Logical OR operation between switches?

Hello Community!

I’m trying to develop an automated heating control in my house. I use a Sonoff TH and a valve actuator for each radiator. I created a climate/thermostat in Home Assistant for each and it works as expected. Switches are automatically controlled by Home Assistant based on the temperature read from the sensor.
But I need an extra switch to control the boiler, I use a modified Sonoff Basic which when turned on, starts the boiler, and when turned off, stops the boiler. So far so good on the hardware part.

What I can’t seem to understand how to program in Home Assistant, is a kind of logic “OR” function to combine the switch states of each radiator. So basically all I need:

  • whenever any radiator’s switch is ON, turn the boiler ON
  • whenever all radiator switches are OFF, turn the boiler OFF
    Actually this is an OR logical operation of all the radiator switches, and the result should actuate the switch of the boiler. More easily: at any time if there’s at least one radiator switch in ON state, keep the boiler in ON state. Only turn off the boiler when all the radiator switches are OFF.

Any ideas how to implement this?

I looked at triggers and templates but couldn’t figure out how to do it. I don’t see how to prevent turning off the boiler when a radiator goes off, but there are other radiators still on.

Thanks in advance for your help.

The trigger is always at an OR state. So you can have multiple triggers (in your case multiple switches) and if any of them change to the desired state, it will trigger the automation.

Now… for the OFF part, you can do this if you group all your switches and use the group as a state trigger. This will do the job.

Something that is irrelevant to what you asked, but might be helpful in the future, is that the conditions can be changed to be an OR logic or an AND logic.
Check this out if you want to know more:

It should be as easy as:

automation:
  - alias: Control boiler
    trigger:
      platform: state
      entity_id:
        - switch.radiator1
        - switch.radiator2
    action:
      service_template: >
        {% if is_state('switch.radiator1', 'on') or
              is_state('switch.radiator2', 'on') %}
          switch.turn_on
        {% else %}
          switch.turn_off
        {% endif %}
      entity_id: switch.boiler