Posts by substancev
-
-
I was working on a project that required me to have a display show video content based on the time of day and day of the month. It also had to have some volume control depending on what time of the morning it was. The platform was a RPi3. The schedule is as follows:
- Sun-Friday AM - Play AM playlist between 6AM and 8PM
- Mute AM playlist between hours of 6AM and 10AM
- Sat AM - Play AM playlist between 6AM and 9PM
- Sun-Friday PM - Play PM playlist between 8PM and 6AM
- Sat PM - Play PM playlist between 9PM and 6AM
First I created my scripts. I needed to automatically initiate the playback when the system reboots (should it ever need to be rebooted). So in "/storage/.config/" i created "autostart.sh" with the following:This starts before kodi launches and has this format so it doesn't hang.
Then I created my startPlay.sh (/storage/.config/startPlay.sh):
Bash
Display More#!/bin/bash #script by substancev currday=$(date +%u) currtime=$(date +%H%M%S) satamstart=060000 satamfinish=210000 otherdaystart=060000 otherdayfinish=200000 muteStart=060000 muteFinish=100000 if [[ $currday -eq 6 ]]; then if [[ $currtime -ge $satamstart && $currtime -le $satamfinish ]]; then /storage/.config/playAM.sh else /storage/.config/playPM.sh fi elif [[ $currday -eq 7 ]]; then if [[ $currtime -ge $otherdaystart && $currtime -le $otherdayfinish ]]; then /storage/.config/playAM.sh else /storage/.config/playPM.sh fi elif [[ $currday -lt 6 ]]; then if [[ $currtime -ge $otherdaystart && $currtime -le $otherdayfinish ]]; then /storage/.config/playAM.sh if [[ $currtime -ge $muteStart && $currtime -le $muteFinish ]]; then /storage/.config/mute.sh else /storage/.config/unmute.sh fi else /storage/.config/playPM.sh fi fi
This will handle the schedule on reboot.
Next I created my playAM.sh:
Bash#!/bin/bash kodi-send --host=localhost --port=9777 --action="PlayMedia(/storage/.kodi/userdata/playlists/video/AM.m3u)" sleep 2 kodi-send --host=localhost --port=9777 --action="PlayerControl(RepeatAll)"
and playPM.sh:Bash#!/bin/bash kodi-send --host=localhost --port=9777 --action="PlayMedia(/storage/.kodi/userdata/playlists/video/PM.m3u)" sleep 2 kodi-send --host=localhost --port=9777 --action="PlayerControl(RepeatAll)"
mute.sh:
unmute.sh:
Then i configured my crontabs using crontab -e at the console.
crontab:
Code#Play AM Weekday 0 6 * * * /storage/.config/playAM.sh #Play PM Sun-Fri 0 20 * * 0,1,2,3,4,5 /storage/.config/playPM.sh #Play PM Sat 0 21 * * 6 /storage/.config/playPM.sh #Mute AM 0 6 * * 1,2,3,4,5 /storage/.config/mute.sh #Unmute AM 0 10 * * 1,2,3,4,5 /storage/.config/unmute.sh
I'm not sure if it was necessary or not to chmod +x these scripts... so I did it anyway.
And there we have it... Kodi auto plays on the schedule I want it to be on.
Please let me know if you would have done this differently.
**Updated 9/6/16 - Fixed muting issue.
- Sun-Friday AM - Play AM playlist between 6AM and 8PM