Some Neat Kodi Automation

Some Neat Kodi Automation

I use Kodi for my home theater management. There are a couple of neat plugins I want show off. The first one is the PseudoCinema Poster plugin. This neat plugin lets me show a "Now Playing" movie poster on a dedicated screen for my home theater. When a movie is not playing, it shows random posters. When a movie starts, it takes that artwork in the Kodi DB and puts it up on the dedicated screen with a "Now Playing" label. Neat stuff. Here's a vid:

You can get the plugin info here: I'm typing this, it seems like the guy who developed it has taken it off of github. Ugh - I'll post a link to plugin later.

I threw together a quick script to auto turn on the display (it's a TV with a raspberry pi running Kodi too) when it detects that the Kodi web service is running. The raspberry pi is where you run the actual movie poster plugin and it reads from the web services exposed from the Kodi machine. Here it is:

#check statuses first
TVSTATUS=$(echo pow 0 | cec-client -s -d 1 | grep -q standby; echo $?) # 0 means tv is off
KODISTATUS=$(nc -z -w3 8080; echo $?) # 1 means that KODI is off


if [ $TVSTATUS -eq 0 ] && [ $KODISTATUS -eq 1 ]
    exit 0 #everything is off.  do nothing.

elif [ $TVSTATUS -eq 0 ] && [ $KODISTATUS -eq 0 ]
    ""echo on 0 | cec-client -s -d 1""; sleep 15; killall -9 kodi kodi_v7.bin; exit 0 # turn on the TV and restart kodi local binary

elif [ $TVSTATUS -eq 1 ] && [ $KODISTATUS -eq 1 ]
    ""echo standby 0 | cec-client -s -d 1"" & exit 0 # turn off the TV

elif [ $TVSTATUS -eq 1 ] && [ $KODISTATUS -eq 0 ]
    exit 0 #everything is on.  do nothing


A few notes:

  • The Raspberry Pi version of Kodi installs the hdmi cec-client that allows you to control the tv over HDMI.
  • netcat (nc) is used to see if the web server on the main kodi machine is listening. Change that line to reflect your IP and port.
  • I use a cron job to run the script every minute to check the status of things.

The sconce lights are controlled by an official Kodi plugin called "Kodi Callbacks".

I'll have to post more about it another time, but basically, you can do things based on Kodi events like run scripts, send json RPC notifications, do HTTP requests. Oh, and another neat project I have to blog about: I turned some cheap plastic battery powered sconces into wired, Alexa enabled sconces.