Tv switch and automation

Hi guys! really rookie here. Im trying to create a switch to turn on/off the TV. As Ive an old TV (2012) Ive done it using CEC_HDMI. Ive created a scrip to turn on and another to turn it off and both works correctly. Now I want instead of the script to use the switch in the UI. I`ve created the folowing automation

   - alias: Turn TV off
     trigger:
       platform: state
       entity_id: switch.hdmi_0
       to: 'off'
     action:
       service: hdmi_cec.standby

and the configuration file is as follows

hdmi_cec:
  devices:
    TV: 0.0.0.0

The result is that the switch is only showing the TV state but it does not respond to the changes, every time I change the switch.

Any suggestion on what I`m doing wrong?

Thank you in advance!

if you somehow have a way to find out if the TV is on or off, you can use a template switch
Otherwise I’d just create a “dummy” input_boolean to control your TV and add an automation based on the input_boolean as a trigger:

- alias: TV Control
  trigger:
    - platform: state
      entity_id: input_boolean.tv_switch
  action:
    - service_template: >
      hdmi_cec.{% if states.input_boolean.tv_switch.state =='on' %}power_on{% else %}standby{% endif %}