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:

    Bash
    #!/bin/sh
    (
    sleep 10;
    touch /storage/.config/autostarted
    sh /storage/.config/startPlay.sh
    ) &

    This starts before kodi launches and has this format so it doesn't hang.

    Then I created my startPlay.sh (/storage/.config/startPlay.sh):

    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:

    Bash
    #!/bin/bash
    kodi-send --host=localhost --port=9777 --action="SetVolume(0)"

    unmute.sh:

    Bash
    #!/bin/bash
    kodi-send --host=localhost --port=9777 --action="SetVolume(100)"

    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.