Switch that activates script independent of state from before

Hi,

I am trying to make a switch that activates scripts independent of state on the switch from before, but with no luck so far.
The script sends a remote command to my samsung tv.
The problem is that my samsung TV does not seem to update properly in homeassistant (slow, or not at all), so I can`t use that as a value template in a template switch.
I want to use it with Alexa and emulated hue, so I can turn on and off the TV from Alexa.
What I have now is two scripts, “TV on”, and “TV off”. But that is kind of stupid, cause then I have to say: “Alexa, turn off TV off” or “Alexa, turn on TV on”.

I can not use input_boolean either, cause if I turn off or on the TV from my remote, the input_boolean will be in the wrong state, and nothing will happen.

Have anyone a solution for this problem? Thank you.

If you’re using the samsungtv component, add timeout: 30 to the settings. I did that it and it now actually updates.

1 Like

Thank you. I can see it now works good if I control it from homeassistant, and register “on” from the remote, but does not seem to register “off” from the remote. I have the 2017 model, and have host and mac in my configuration, and port 8001, and timeout: 30

Mine is older, but it does register as off within a couple of minutes.

Ok, mine does not update at all it seems. I see that there is a problem with at least one of the MU-series on the homeassistant page with the samsung component. Don`t know how to install the websocket client on hassio if that is the problem.

Assuming you’re not using HassIO:

  1. SSH to the Pi
  2. sudo su -s /bin/bash homeassistant
  3. Activate your virtual environment (exactly how you do this varies according to how you installed HA)
  4. Type pip3 install websocket-client

thank you, but as I wrote, I am using HassIO :frowning:

Then I’m afraid you’re out of luck until somebody produces a component that includes it.

I use this switch to execute scripts on alexa. Note that the switch doesn’t need to be off for the service turn off to execute the turn off command.

  - platform: template
    switches:
      lock:
        value_template: "{% if is_state('switch.teststatus', 'on') %}on{% else %}off{% endif %}"
        turn_on:
          service: homeassistant.turn_on
          entity_id: script.test1
        turn_off:
          service: homeassistant.turn_on
          entity_id: script.test2
1 Like

One cludgy solution if it’s safe for the TV is to use a smart plug. You could monitor the power draw on the plug, and use that in your script to determine which command to use.

1 Like

Thank you, that worked perfectly, don’t know why I didn’t think of that.