How do I make my autoplay OSMC sleep at 5pm and wake up at 8am? (with RTC!)

My OSMC running on Pi2 is for showing ads and it uses autoexec.py to load a video dir and repeat forever.
I would like to make it sleep at nights and maybe also on weekends. How would I do that?
Do you advise doing a reboot in the mornings? Or simply use an electrical timer to cut power? Is the latter dangerous?

EDIT:
I am thinking using Cron to kill kodi and tvservice in the evenings and starting them in the mornings. Anything else worthwhile to kill? Perhaps a reboot in the morning instead of starting services again?

I think crontab is the way to go here, I’ve ran countless game servers and with cron i was doing all the stop/update/restart things. If your autoexec.py is working properly then i would suggest a reboot as well. Just dont forget to disable automatic updates in osmc, at least the manual selection that ‘waits’ for user interaction…you dont want a popup showing on your screen :stuck_out_tongue:
If i’m not mistaken its, apt-get install cron, not crontab.

1 Like

I just realized that Raspberry Pi doesn’t have a RTC and it will running without network access. So now I wait for my RTC shipment :smile:

1 Like

Ok RTC is here!

I needed to add these lines to /boot/config.txt:

dtparam=i2c_arm=on 
dtoverlay=i2c-rtc,ds3231

In cron I added these lines for testing:

34 9 * * * /opt/vc/bin/tvservice -o
35 9 * * * systemctl stop mediacenter
36 9 * * * /sbin/shutdown -r now

Now I have a problem that when the HDMI is turned off - Raspberry wont restart - it crashes. Could it be logged somewhere? journalctl only knows that happened after boot. I added something after shutdown in cron but it’s not run anymore and I had to powercycle to have it resume operation.
Also since the shutdown -r now failed it will try again after power-cycling and it works then with HDMI on.

I could probably run tvservice -p before and it should work but thats hardly elegant, is it?

EDIT: I added “systemctl stop mediacenter” in between and while kodi.bin is still alive after the cron - restart now works!

EDIT2: Sadly the Pi RTC doesn’t tick. It shows up as a hwclock but once its powered off for more than 10 minutes the time stops. It starts with the previous time. Any ideas?

EDIT3: I think I got it…will leave it without power over night and then post my findings.

Success! The DS3231 real-time clock ticks!

Here is the cron I am using:

5 17 * * 1,2,3,4,5 /opt/vc/bin/tvservice -o
6 17 * * 1,2,3,4,5 systemctl stop mediacenter
0 8 * * 1,2,3,4,5 /sbin/shutdown -r now

On workday evenings it stops first HDMI output (putting the monitor to standby) and then kills Kodi. In the morning it simply restarts and loads my autoexec.py to automatically start playing a folder of videos on repeat.

Then for the RTC I also needed the following:

And lastly to make it sync hwclock with system time at boot add to /etc/rc.local:

hwclock -s

before “exit 0”

Thats it, all done!

The restart is still not consistent. It sometimes works and sometimes it hangs requiring manual power cycling. Can anyone please help me get relevant logs?
I can make the restart work by running “tvservice -p” (turning HDMI back on) at the same time as “shutdown -r now” but I’d rather not use that.

EDIT: nope - nothing really helps - “shutdown -r now” hangs every now and then and I have to power cycle manually.

EDIT2: I am now running systemctl start mediacenter instead of the reset. Lets see how it holds up running by itself OVER THE YEARS :smile:

Nice that you figured it out :slight_smile: btw…wouldnt this be so much easier
http://www.midlandstoolsupplies.co.uk/asset/image/imagep/large/plug-in-mechanical-timer-1928.jpg

Well, unless the timer has a battery backup - you will drift back in time every time there is an outage. Also you’d still want to at least unmount the file systems to avoid data corruption. But still yes, it could work years this way :slight_smile:

1 Like