Binary template assessing the value of multiple valves - how to?

Hi! I have multiple cooling valves (0-100%) and I want to create a binary sensor that will be on if any of the valves is above 0% (and otherwise be off). If the binary sensor is "on’ then an automation will turn-on the cool water circulator and the cooling function of the heat pump. My question is how I can make such a template (I am not familiar with the syntax).

Also, I would like to create a similar template being “on” if any wled light is “on” as well.

Many thanks! :slight_smile:

template:
  - binary_sensor:
      - name: Valves
        state: >
          {{ expand('sensor.valve1', 'sensor.valve2', 'sensor.valve3')
            | map(attribute='state') | map('int', 0) | sum > 0 }}
  • If the state of all three sensors is 0 then their sum is 0 which isn’t greater than 0 so the template reports false (‘off’).
  • If any of the three sensors is greater than 0 then their sum is greater than 0 so the template reports true (‘on’).

For lights you can use this:

        state: >
          {{ expand('light.wled1', 'light.wled2', 'light.wled3')
            | selectattr('state', 'eq', 'on') | list | count > 0 }}
1 Like

Thank you so much!! :slight_smile: :slight_smile: :slight_smile: really touching how good the community is here!

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic is resolved. This helps other users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.

1 Like