Youtube live stream as alarm clock

  • Hey guys,

    I just started using Kodi with LibreELCE, so sorry for stupid questions in advance.

    I would like to set up Kodi in that way, that it autostarts with a youtube stream. I was able to install youtube addon. However, I'm not able to set the autostart procedure, which is described in the wiki (Autoexec Service - Official Kodi Wiki). First problem: I don't know how to create the files on kodi or transfer them to the right place. When I put the SD card in my Windows notebook, I don't have access to the folders I need.

    Would be very happy if you can give me some advice. :)

    Cheers,

    OnkelHo

    PS: Any other ideas to realize the project easier are very welcome!

  • You need to ssh t your libreelec box..use something like Winscp for windows..

    For your youtube video to start as alarm make a small script and run with cron..

    something like this works fine..

    Code
    kodi-send --action="SetVolume(100)" # set desired volume 100 = 100%
    kodi-send --action="PlayMedia(plugin://plugin.video.youtube/?action=play_video&videoid=your_youtube_video_id)"
  • My Question here is ....

    is your Laptop always on and on your side?

    Then is better you used a PI with CEC. With a script the PI Start your Receiver or TV on your wakeup time and with a delay then start your Youtube Video.

    I think is better as the Laptop always on!

  • You need to ssh t your libreelec box..use something like Winscp for windows..

    For your youtube video to start as alarm make a small script and run with cron..

    something like this works fine..

    Code
    kodi-send --action="SetVolume(100)" # set desired volume 100 = 100%
    kodi-send --action="PlayMedia(plugin://plugin.video.youtube/?action=play_video&videoid=your_youtube_video_id)"

    Thanks, that was very helpful!

    I managed to set up SSH.

    Autoexec is out of date as I tried and read.

    Thus, I created a python script containing your code (with set video ID) and uploaded it as "autoexec.py" in the userdata folder. This doesn't seem to work. So what is the mistake? :S

    Furthermore, as I want to adjust volume after some time as well as brightness, is there a reference manual or tutorial where commands are collected and explained?

    Thanks a lot!!!

    Edited once, last by OnkelHo27 (July 8, 2021 at 12:25 PM).

  • Not sure why you need autoexec?do you want the video to start when kodi starts or as an alarm while kodi is already running?

    What hardware are you using?is it a rpi?

    here are some commands.

    Bash
    #!/bin/sh
    kodi-send --action="SetVolume(100)" # set desired volume to 100 = 100%
    kodi-send --action="PlayMedia(plugin://plugin.video.youtube/?action=play_video&videoid=your_youtube_video_id)"
    sleep 30  # keep volume at 100% for 30 seconds
    kodi-send --action="SetVolume(0)" # set volume to 0 = 100%
    sleep 30  # keep volume at 0% for 30 seconds
    kodi-send --action="SetVolume(100)" # set volume to 100 again = 100%

    You save that as alarm.sh and test from ssh then set cron to run that script at your convenience ..

    brightness I have no idea if it can be set..

  • That helped a lot!

    • Yes, its a RPI
    • I changed my plan of an alarm clock, but use a wifi socket to enable the power for my RPI. So finally I need to start the process after boot.
    • I created the shell file and tried it --> works perfectly
    • However, CRON works only after I restart it manually via SSH. Otherwise I get an error message regarding a time disparity:

    • ● cron.service - Cron daemon
      Loaded: loaded (/usr/lib/systemd/system/cron.service; disabled; vendor preset Active: active (running) since Thu 2019-04-11 18:28:53 CEST; 2 years 2 months Process: 226 ExecStartPre=/bin/mkdir -p /storage/.cache/cron/crontabs (code=ex Main PID: 230 (crond) Memory: 204.0K CGroup: /system.slice/cron.service └─230 /sbin/crond -f -S
      Apr 11 18:28:52 XXX systemd[1]: Starting Cron daemon...
      Apr 11 18:28:53 XXX systemd[1]: Started Cron daemon.
      Jul 10 23:01:51 XXX crond[230]: time disparity of 1182512 minutes det

      So at the moment the command @reboot bash /storage/Test.sh doesn't work, whereas when I restart CRON e.g. the code 0 0 * * * bash /storage/Test.sh works properly. I found a post SOLVED cron won't work which describes the same problem, but I wasn't able to figure out how to solve the problem... May you help one more time? :)
  • Just ssh

    Code
    systemctl restart cron

    after playing around or adding cron timers to /storage/.cache/cron/crontabs/root

    Also you don't need that bash in your commands

    just

    Code
    0 0 * * * /storage/Test.sh

    Are you trying to make the script start at boot instead of alarm/cron?

  • Quote

    Are you trying to make the script start at boot instead of alarm/cron?

    Yes, after boot instead alarm. But why/how instead of cron? I thount using @reboot at the beginn of an cron command is doing exactly this or is there another way?

    Quote

    systemctl restart cron

    That works, but the crucial point is that I don't want to SSH on reboot as I want to wake up on reboot by livestream.

    Quote

    adding cron timers to /storage/.cache/cron/crontabs/root

    In this file there is the command @reboot /storage/Test.sh. But this command isn't executing (probably because of the time disparity)...

  • But how can I enable (install) it?

    You have to build your own image.

    But to prevent any races you should avoid timers and use autoexec.py for LE 9.2/Kodi 18 or the autoexec service you linked in the first post for LE 9.8/Kodi 19.

  • You have to build your own image.

    But to prevent any races you should avoid timers and use autoexec.py for LE 9.2/Kodi 18 or the autoexec service you linked in the first post for LE 9.8/Kodi 19.

    autoexec.py is not working. I tried:

    import xbmc

    xbmc.executebuiltin('RunScript("/storage/Fernsehwecker.sh")')

    and safed the file in the userdata folder.

    Also trying to execute the script via SSH gives an Error:

    ImportError: No module named xbmc

    I really just need a simple solution :D

  • That work's! Woho!

    1. After using autoexec.py (or a kodi service) you can get rid of the script.

    Using Mario77 's template try:

    Code
    import xbmc
    xbmc.executebuiltin('PlayMedia(plugin://plugin.video.youtube/?action=play_video&videoid=your_youtube_video_id)')

    You can test with kodi-send -a 'RunScript(/storage/.kodi/userdata/autoexec.py)' or restart kodi with systemctl restart kodi

    The only strange thing is that it only works if Debug-logging is turned on?!

    2. Likely you have to enable "Wait for Network" in the "Network" tab of the LibreELEC-Settings addon.

    If the issue persist create logs with pastekodi for the logging/not logging cases and post the URLs.

  • Sooooo the addon is (after following the instructions, zip, edit install) not working. I don't see any reaction on startup. However, writing commands directly in the python autoexec.py works fine.

    Only the connectivity problem persists. I changed "Wait for Network" to 120, but it sometimes still doesn't connect. If I reboot, everything works fine. So I thougt it is a good idea to check via python if network connection is established and if not --> reboot. Any idea how to check that via python?