Is it possible to set the value_template of a template switch to read from 2 entities?

I’m trying to create a template switch that turns on and off 2 automations, and set that state of the switch to: ON if one or both of the automations is on, and OFF if both of the automations are off. Is this possible? How should I proceed with writing the value_template? I figure it must have something to do with the “and” condition. I’m a novice when it comes to templates, so I’m having a difficult time figuring this out or if this is even possible.

Thanks in advance for the replies folks!

Why turn ON/off a automation

why not just set a condition and

    condition: and
    conditions:
      - condition: state
        entity_id: sensor.dishwasher_status
        state: Dirty
      - condition: state
        entity_id: automation.dishwasher_consume_tablet_running
        state: 'off'

both these have to be true before going to the next step

1 Like

Myle’s question is a good one, but to answer your question you would to it like this:

value_template: "{{ is_state('automation.one', 'on')  and  is_state('automation.two', 'on')  }}"
3 Likes

That’s actually not a bad idea, but I with a template switch I could monitor the state of the automations just by looking at the state of the switch. I also wanted to be able to run a service when I turn on or turn off the switch. So being able to bundle all of those functionalities into a single entity like a template switch would be perfect for me.

Wow thank you, your code worked! But instead of using "and’, I ended up using “or”. Using “and” requires both of the automations to be on for the template switch to change to on, while I wanted the template switch to change to on when only one of the automations turns on.

Yeah that’s my bad, I misread this:

Sorry.

No problem! Luckily this time I was able to figure it out myself :smiley:

1 Like