Template for comparing three binary sensors

I made a template for three binary sensors. I need that pattern to be true if the first binary sensor - true or the other two together - true.
Pattern works only if all three or “or” and "

          {{ is_state('binary_sensor.manual_filtration', 'on') 
            or is_state('binary_sensor.night_rate', 'on')
            and is_state('binary_sensor.blackout', 'on')
          }}


Your description is unclear.

The supplied template could be summarized as:

If both night_rate and blackout are “on” OR manual_filtration is “on”

If that is not what you want, please clarify.

Logical operators are evaluated based on an order of precedence. AND takes precedence over OR.

To be sure things are handled the way you want, you can use () to explicitly group clauses… Parentheses take precedence over logical operators.

{{ is_state('binary_sensor.manual_filtration', 'on') or
(is_state('binary_sensor.night_rate', 'on') and 
is_state('binary_sensor.blackout', 'on')) }}

or you can set variables…

{% set filter = is_state('binary_sensor.manual_filtration', 'on') %}
{% set night_blackout = is_state('binary_sensor.night_rate', 'on') and 
is_state('binary_sensor.blackout', 'on') %}
{{ filter or night_blackout }}
1 Like