Two Switches in one Toggle

Hello, I would like to control two entities manualy with only one toggle in the UI. One entity is the heater and the other is a pump (both are switches). The heating element must not run without a pump. So I want to control both together via oine toggle. It serves to heat up the pool. Unfortunately, I am still a beginner and need help. How can I do that?

Thanks in advance, Fabian

You can use a simple automation.

  - alias: two switches with one toogle
    trigger: 
      platform: state
      entity_id: switch.one
    action: 
      service_template: >
        {% if trigger.to_state.state == 'on' %}
          switch.turn_on
        {% else %}
          switch.turn_off
        {% endif %}
      entity_id: switch.two

Use a template switch

  - platform: template
    switches:
      heater_and_pump:
        value_template: "{{ is_state('switch.switch_one', 'on') }}"
        turn_on:
          - service: switch.turn_on
            entity_id : switch.switch_one
          - service: switch.turn_on
            entity_id : switch.switch_two
        turn_off:
          - service: switch.turn_off
            entity_id : switch.switch_one
          - service: switch.turn_off
            entity_id : switch.switch_two
2 Likes

Or dig into NodeRed. It´s a graphica interface to do all that, and a lot more powerful.

To make this bullet proof I think I’d go with : -
“{{ is_state(‘switch.switch_one’, ‘on’) or is_state(‘switch.switch_two’, ‘on’) }}”
That way either switch will do the business :smiley:

Edit: Maybe not, I’m not sure how you’d switch this off as it seems a bit ambiguous, can you explain its operation Francis ?
On balance, I’m favouring VDRainer’s nice and simple solution.

Maybe you can create a group like this:

group:
  poll:
    name: poll
    entities:
      - switch.heater
      - switch.pump

And then use group.poll to turn on and off both switches at the same time. You can put it in a Lovelace card or use it in an automation.

When i try to use switches in an template, it does not work. I put it at the end of my configuration.yaml, right?

Konfig
configuration

You have to state the domain, so put
switch:
Directly above your ‘new’ switch (where your cursor is shown)
Other new switches would go under the same heading (ie you don’t need multiple headers)

You should not post images to display text (size issues) use the </> button to insert preformatted text.

Thank you for your help. It works like the way i want it.

switch:      
- platform: template
  switches:
    heizstab_und_pumpe:
      friendly_name: "Heizstab und Pumpe"
      value_template: "{{ is_state('switch.oeq1938469_2', 'on') }}"
      turn_on:
        - service: switch.turn_on
          entity_id : switch.oeq1938469_2
        - service: switch.turn_on
          entity_id : switch.oeq1938469_4
      turn_off:
        - service: switch.turn_off
          entity_id : switch.oeq1938469_2
        - service: switch.turn_off
          entity_id : switch.oeq1938469_4
1 Like

Thanks a) for using text and b) for formatting it correctly, well done ! :+1:

Err ! I didn’t give you the solution you used, @francisp did, you should give him the solution.

Actually to be super flexible you could extend @VDRainer 's solution so that switching either switch on, brings on the other and switching either switch off, switches both off : -

  - alias: two switches with either the master
    trigger: 
      - platform: state
        entity_id: switch.one
      - platform: state
        entity_id: switch.two
    action: 
      - service_template: switch.turn_{{trigger.to_state.state}}
        entity_id: switch.one, switch.two
4 Likes

Ok, i did it. Thanks

In my case, that would not be the best way, because sometimes the pump clears the water without heating. Three times a day.

Ah ! undestood. :+1:
I did not comprehend your usage case :crazy_face:

Thank you. Not so much for the simple logic as for the beautiful yaml.

1 Like