Combining two binary sensors into one?

I’ve read the Template Sensor documentation, but it seems like my attempt at an “OR” combination of sensors does not work:

  sensors:
    combined_motion_porch:
      friendly_name: "Combined Motion Porch"
      device_class: motion
      entity_id:
        - binary_sensor.porch_motion_sensor
        - sensor.blueiris_motion_porch
      value_template: >-
        {% if is_state('binary_sensor.porch_motion_sensor', 'on')
           or is_state('sensor.blueiris_motion_porch', 'on') %}
           on
        {% else %}
           off
        {% endif %}

All three sensors show up in dev-state, but binary_sensor.combined_motion_porch never changes from the off state. Can anyone point out what I’m doing wrong?

1 Like

Else if might work as in the kettle example. If sensor 1 is on, then on , else if sensor 2 is on, then on, otherwise off

try changing on/off to true/false:

      value_template: >-
        {% if is_state('binary_sensor.porch_motion_sensor', 'on')
           or is_state('sensor.blueiris_motion_porch', 'on') %}
           true
        {% else %}
           false
        {% endif %}

i think if you write it the way you have it, on/off are interpreted as strings.

Your template looks right to me, and I tested it with two binary sensors in my system, and it does work as expected. (on if either binary sensor is on)
To troubleshoot this, I would use the template editor, and separate out the two sensors to see what is working and what is not working. like this:

 {{is_state('binary_sensor.porch_motion_sensor', 'on')}}
 {{is_state('sensor.blueiris_motion_porch', 'on') }}

Each line should return True of False
If they don’t then you have a sensor that is not working as expected.

1 Like

Thanks, i didn’t know about the template editor!

Looks like the issue was the one thing i didn’t include in my post - i put it under the root key “binary_sensor:” instead of sensor:"

Now it works like a charm.