Template switch - boolean not driving change

What don’t I understand here?

I am trying to set up a switch template for turning a night light on and off with various automations.

I want to be able to change the input boolean to on or off and have it switch the light.
Problem i’m getting, if I switch the switch the boolean updates and the light goes on or off. If I update the input boolean, the template switch also changes but the light does not go on or off.

I made a card for it while testing, you will see what I mean…

This is the code:

input_boolean:
    night_lite:                  # For night light etc
        name: 'Night Lite'
        initial: on
        icon: mdi:ab-testing


# for night light
switch:
  - platform: template
    switches:
      night_lite:
        value_template: "{{ is_state('input_boolean.night_lite', 'on') }}"
        turn_on:
          - service: input_boolean.turn_on
            entity_id: input_boolean.night_lite
          - service: light.turn_on
            entity_id: light.steps
        turn_off:
          - service: input_boolean.turn_off
            entity_id: input_boolean.night_lite
          - service: light.turn_off
            entity_id: light.steps

You’re describing expected behaviour. Common misconception is that the switch will react to the template change, but in fact the template is only there to establish the state of the switch with the turn_off and turn_on being executed when the switch is changed only.

What you want there is an automation that synchronises the states, or there’s an appdaemon app on hacs (name escapes me) that links entities together for this purpose.

Thanks for replying so quickly. Ok, that explains a lot.
would that appdaemon be “Follow Me” ?
I’ll give it a try

What I’m not understanding is why you need an input boolean (and hence the need for a template switch/appdaemon app) at all if the only thing it ever does is just always follows the state of the light switch?

Why don’t you just use the light switch itself wherever you would use the input boolean?

That is how I had it set up a few days ago, (I think so… i’ve changed it so many times now I can’t remember what is up and what is down anymore!)

The light wasn’t always turning on through the automation. Then I read somewhere that it would be more reliable if you use a template switch. Something about when it gets multiple On commands and it thinks it’s already on (but its not) it discards them or something…

I would be very surprised if adding two extra layers of operations could make things more reliable.

I’ve never needed to use any template switches to turn on any lights/switches from an automation.

I would probably try to troubleshoot the issue with the automation before making it even more complex and harder to maintain.

2 Likes

Did you solve the issue?