Want to control a TV over HDMI-CEC via a remote RasPi? Include the following as a switch:
platform: command_line
switches:
tv_power:
command_on: "ssh pi@<ip_address> -i /home/homeassistant/.homeassistant/id_homeassistant 'echo on 0 | cec-client -s -d 1'"
command_off: "ssh pi@<ip_address> -i /home/homeassistant/.homeassistant/id_homeassistant 'echo standby 0 | cec-client -s -d 1'"
command_state: "tvstatus() { local RESULTS; RESULTS=$(ssh pi@<ip_address> -i <path_to_ssh_key> \"echo pow 0 | cec-client -s -d 1 | grep -q 'power status: on'\"); echo $?; }; tvstatus"
value_template: '{{ value == "0" }}'
friendly_name: TV
Be sure to replace '<ip_address>' and '<path_to_ssh_key>'
'command_state' looks overly complicated but a shell function is required to return the proper exit code, passed to HASS
Inspiration from: /u/rockNme2349 on Reddit
For what it's worth, I had to add a switch in my ssh command to get this to work on hassio:
-o StrictHostKeyChecking=no
. It tells the SSH client to not prompt you with warning messages or yes/no questions when host has changed. e.g.From: https://megamorphf.github.io/homeassistant/hyperion/ssh/hassio/2018/01/22/controlling-anything-via-ssh.html