I have been wanting to use the HDMI CEC component to build a switch for my devices which can be controlled via HDMI CEC. However, I wasn’t able to find a way to get on/off status with the existing component. I ended up finding a project on github to create a REST api for CEC devices and decided to create a container to make it easier to run.
https://hub.docker.com/r/blakeblackshear/rpi-hdmi-cec-rest/
Just run this docker container and setup a REST api switch as follows:
switch:
- platform: rest
name: TV
resource: http://localhost:5000/device/0/power
body_on: '{"state":"on"}'
body_off: '{"state":"off"}'
is_on_template: '{{ value_json.state == "starting" or value_json.state == "on" }}'
Your config may vary depending on the CEC implementation of your TV. Mine is a Samsung.