I’m having trouble making a template binary sensor that’s the OR of two other sensors. The individual sensors are working correctly. I’ve tried changing OR to AND and using the same sensor in both is_state() to force both arguments to be the same. I expected that to force it to be the same state as the main sensor, but basement_occupancy still never changed state.
I’m new to this, so there’s likely some subtle syntax issue that I’m missing.
binary_sensor:
- platform: template
sensors:
basement_occupancy:
entity_id:
- sensor.basement_sensor_burglar_19_10
- binary_sensor.basement_stairs_motion
value_template: >-
{%- if is_state("sensor.basement_sensor_burglar_19_10", "on")
or is_state("binary_sensor.basement_stairs_motion", "on") -%}
on
{%- else -%}
off
{%- endif %}
sensor_class: occupancy
my code:
{%- if is_state(“sensor.basement_sensor_burglar_19_10”, “on”) or is_state(“binary_sensor.basement_stairs_motion”, “on”) -%}on
{%- else -%} off
{%- endif %}
You need an entity_id (optionally, a list of entity_ids) to trigger the change. The changing state of the entity_id is what causes the template to be re-evaluated.
Yes. I’m using the bluetooth based presence, so it is easy to test. Is there another way to define an automation based off of a logical OR? My goal is to turn of the Christmas Tree lights if no one is home.
Yeah. Definitely. You can use the state of group.all_devices as a trigger for an automationq. It’s home when anyone is home. Away when everyone is away.
Or use a list of specific devices as your entity_id for a state trigger.