Now it all works as expected, but the TV turns off after around 10 seconds. Is this due to the device tracker taking a while to show the TV as online? I’ve tried adding a - delay: 00:00:20 to the script sequence but that doesn’t work.
That was my guess aswell, and indeed it switches back off (template switch). Thats why i added the delay in the turn on command, but that obviously doesnt really work.
Should i substitute the value template with a inputboolean which on device tracker away turns off and on in the script?
Edit:
value_template: >-
{% if is_state('input_boolean.salora', 'on') %}
on
{% else %}
{% if is_state('device_tracker.salora', 'not_home') %}
off
{% endif %}
{% endif %}
Edit:
When i flip the switch.salora it turns on for about 5 seconds, then switches off, and then on again once the device tracker is online (which then turns it off, i guess)
Never mind. It will never work correctly and here’s why:
The purpose of a Template Switch’s value_template is to report its current state. When you turn it on, the value_template receives feedback acknowledging the actual device was turned on.
If it fails to receive the feedback, it puts the switch back to its original state (if you turned it on, it will turn it back off).
Your value_template is monitoring the state of a device_tracker that has absolutely nothing to do with the TV you are turning on. As a result, any command the Template switch sends (turn on or off) results in no feedback returned to the value_template. So the switch reverts to its previous state.