My setup involves pressing “Watch a Movie” on my Logitech Harmony which then plays a Pearl & Dean 20 second video clip streamed from Youtube on Kodi, whilst dimming my Philips Hue lights to a soft glow. Turning off the activity turns the Hue lights back on.
I found an excellent Kodi CLI project on github which makes playing videos remotely on Kodi very easy: GitHub - nawar/kodi-cli: Kodi/XBMC bash script to send Kodi commands from the command line
-
On your HASS server, download kodi-cli
cd ~
git clone GitHub - nawar/kodi-cli: Kodi/XBMC bash script to send Kodi commands from the command line -
Create a new script for HASS to execute the kodi-cli command. Your HASS homedir may be different to mine and you can name the script something other than playpearl.sh
sudo vim /home/homeassistant/playpearl.sh -
Within playpearl.sh, add the following line (alter the path to suit your environment). The Youtube ID “3WQrLuaMBMw” points to https://www.youtube.com/watch?v=3WQrLuaMBMw which is a HD version of the 90s Pear & Dean intro. Change this ID to which ever video you prefer.
/home/pi/kodi-cli/kodi-cli -y 3WQrLuaMBMw -
Change permissions so that the file is owned by home assistant and can be executed.
sudo chown homeassistant:homeassistant /home/homeassistant/playpearl.sh
sudo chmod 755 /home/homeassistant/playpearl.sh -
Edit the kodi-cli file and enter your kodi details in the required fields:
vim /home/pi/kodi-cli/kodi-cliKODI_HOST=192.168.0.2
KODI_PORT=8080
KODI_USER=
KODI_PASS= -
Test it plays the video on Kodi. You may need to install the Youtube plugin and grant remote access from the Kodi screen.
sudo /home/homeassistant/playpearl.sh -
The following entries in my configuration.yaml tied it all together:
remote: - platform: harmony name: Lounge host: 192.168.0.3 #Hue integration polls for activity state changes at a default 30 seconds. I changed this to 10 because activity status only changes once Harmony has finished executing all commands. scan_interval: 10
automation: - alias: "Watch Movie started from harmony hub" trigger: platform: state entity_id: remote.lounge condition: condition: template value_template: '{{ trigger.to_state.attributes.current_activity == "Watch a Movie" }}' action: - service: shell_command.playpearl #Within the official Hue app, you can create a new scene within a room and then reference it by name - service: light.hue_activate_scene data: group_name: "Lounge" scene_name: "Moviemode" - alias: "Power Off" trigger: platform: state entity_id: remote.lounge condition: condition: template value_template: '{{ trigger.to_state.attributes.current_activity == "PowerOff" }}' action: - service: light.hue_activate_scene data: group_name: "Lounge" scene_name: "Evening"
shell_command:
playpearl: /home/homeassistant/playpearl.sh#The following entry allows you to test running the script from HASS States page.
script:
play_pearanddean:
alias: Play Pear and Dean Video on Kodi
sequence:
- service: shell_command.playpearl
One thing I would like to add is the ability to slowly transition my hue lights to the new scene. Does anyone know if this is possible?