Switch media_player only off works

Hi!

i have several switches but in one of them (LG TV on/off) only half of the switch works: turn_off.

turn_on doesnt work.

switch:
  - platform: template
    switches:
        television:
          value_template: "{{ is_state('media_player.tv', 'on') }}"
          turn_on:
            service: media_player.turn_on
            data:
              entity_id: media_player.tv
          turn_off:
            service: media_player.turn_off
            data:
              entity_id: media_player.tv

Any idea? thanks!

It could be the TV that is the “limit”.
My TV also has an API (no integration in HA) that I can use to select input and turn off. But I can’t turn on since the API is off when the TV is off.
Same thing with the app that is built for the TV. I can switch off but not on.

I can power it on via command by running:

echo 'on 0' | cec-client -s -d 1

the problem is i cannot mix a switch based ‘template’ and another based ‘command_line’

You could have turn on action be running a script, or won’t that work?

yes. I have a command_on to power it on:

     encender_television:
        command_on: >
         ssh -i id_rsa -o StrictHostKeyChecking=no [email protected] "sudo echo 'on 0' | cec-client -s"

yes… Add this to a script, then add the script to the template media player

Sorry i dont know how. :thinking: Can you give me a hand on this?

I only have my phone so it’s hard to see everything.

Configuration -> Scipts -> add script.
As action you call service to run this command, whatever command it is.

Then in your template media player

turn_on:
  service: script.the_script_you_created

Something like that. It’s hard to test it from the phone.

OK now i understand what you meaning. Sorry was a traslation issue. Thanks!