I’m probably doing something stupid, but I THOUGHT I had this right.
I want the automation to trigger if any of these sensors detect motion at any time of the day:
binary_sensor.downstairs_motion_ecobee
binary_sensor.downstairs_occupancy_ecobee
binary_sensor.family_room_occupancy_ecobee
binary_sensor.dining_room_occupancy_ecobee
binary_sensor.hallway_motion_sensor_motion
OR it should trigger with these sensors, but only after 8 am:
binary_sensor.master_bedroom_occupancy_ecobee
binary_sensor.aarlo_motion_family_room
The automation did not fire this morning or yesterday morning before 7 am, but multiple sensors in the first group did detect motion. And yes, I am aware that ecobee sensors are occupancy sensors, but I verified in logbook that their state did change from off to on at these times. Do I have my ORs or indentation wrong?
trigger:
- platform: state
to: 'on'
entity_id:
- binary_sensor.downstairs_motion_ecobee
- binary_sensor.downstairs_occupancy_ecobee
- binary_sensor.family_room_occupancy_ecobee
- binary_sensor.dining_room_occupancy_ecobee
- binary_sensor.hallway_motion_sensor_motion
- binary_sensor.master_bedroom_occupancy_ecobee
- binary_sensor.aarlo_motion_family_room
condition:
condition: or
conditions:
- condition: or # Any one of these sensors can trigger the automation at any time of day
conditions:
- condition: state
state: 'on'
entity_id:
- binary_sensor.downstairs_motion_ecobee
- binary_sensor.downstairs_occupancy_ecobee
- binary_sensor.family_room_occupancy_ecobee
- binary_sensor.dining_room_occupancy_ecobee
- binary_sensor.hallway_motion_sensor_motion
- condition: and # Only triggers at certain times
conditions:
- condition: state
state: 'on'
entity_id: binary_sensor.master_bedroom_occupancy_ecobee
- condition: time
after: '08:00:00' # Fires between 8:00 am and 11 pm
before: '23:00:00'
- condition: and # Only triggers at certain times
conditions:
- condition: state
state: 'on'
entity_id: binary_sensor.aarlo_motion_family_room
- condition: time
after: '08:00:00' # Fires between 8:00 am and 11 pm
before: '23:00:00'
Thanks @123! That’s an interesting way to do it. I hadn’t thought of splitting into separate trigger platforms. I’ll give that a try tonight. But out of curiosity, do you see anything wrong with my original code?
I don’t believe this works the way your code-comment explains it:
- condition: or # Any one of these sensors can trigger the automation at any time of day
conditions:
- condition: state
state: 'on'
entity_id:
- binary_sensor.downstairs_motion_ecobee
- binary_sensor.downstairs_occupancy_ecobee
- binary_sensor.family_room_occupancy_ecobee
- binary_sensor.dining_room_occupancy_ecobee
- binary_sensor.hallway_motion_sensor_motion
It begins by indicating that the next set conditions should be logically ORed. Fine, however, there’s only one condition and it’s the state condition containing several entities. You believe that the OR applies to the entities within that single state condition. It doesn’t; it applies to that state condition ORed with … nothing, because there is no second condition.
It is also possible to test the condition against multiple entities at once. The condition will pass if all entities match the state.
condition:
condition: state
entity_id:
- light.kitchen
- light.living_room
state: 'on'
So for the condition to evaluate to true in your example, all the binary_sensors in the list must be on. Not exactly a common occurrence so that’s what prevented your automation’s action from being executed.
In a condition. Your own automation demonstrates it’s OR in a trigger.
If you believe any of my posts have helped you to resolve your original question, please consider marking one of my posts with the Solution tag. This will automatically place a check-mark next to the topic’s title which signals to other users that this topic has an accepted solution. It will also automatically place a link below your first post that leads to the solution post. All this helps other users, who may have similar questions, find answers.