I think a template sensor is the way to go, but I’m open to other solutions.
I want to know if a room is occupied. I have 4 sensors to work with. 3 are motion sensors, and one is an open close sensor. So, all binary sensors
Two of the motion sensors are in the room.
One motion sensor is triggered if you enter the room, but otherwise not able to be triggered from the room.
The open close sensor is for door entry into the Room.
The only way to get into the room is through the door or by passing the motion sensor outside the room (it’s in a stairwell to the room)
I’m thinking that basically if the last changed of either of the two motion sensors in the room is newer that the other two sensors, then someone is in the room and has not left.
Only thing is in the past you end up running into possible false positives if one sensor takes a few seconds longer to “turn off”, so I think I need some sort of buffer or timer. Also It’s not uncommon for there to be no motion detected in the room even though someone is in the room. I think that will still be ok as long as the sensors in the room were the last active.
Anyone have any thoughts, or suggestions.
Thanks
EDIT:
Adding some extra details. I’ve got the general idea, but need help getting them all together
This works for two sensors
{{((as_timestamp(states.binary_sensor.bedroom_motion_sensor.last_changed)) > as_timestamp(states.binary_sensor.bedroom_stairs_motion_sensor.last_changed)) }}
These are the names of all the sensors
binary_sensor.bedroom_motion_sensor
binary_sensor.closet_motion_sensor
binary_sensor.bedroom_door_open_close_sensor
binary_sensor.bedroom_stairs_motion_sensor
Edit 2:
I’m close, but this does not work
sensors:
bedroom_prob_occupied:
device_class: presence
value_template: >-
{{
((as_timestamp(states.binary_sensor.bedroom_motion_sensor.last_changed)) > as_timestamp(states.binary_sensor.bedroom_stairs_motion_sensor.last_changed))
or
((as_timestamp(states.binary_sensor.bedroom_motion_sensor.last_changed)) > as_timestamp(states.binary_sensor.bedroom_door_open_close_sensor.last_changed))
or
((as_timestamp(states.binary_sensor.closet_motion_sensor.last_changed)) > as_timestamp(states.binary_sensor.bedroom_door_open_close_sensor.last_changed))
or
((as_timestamp(states.binary_sensor.closet_motion_sensor.last_changed)) > as_timestamp(states.binary_sensor.bedroom_door_open_close_sensor.last_changed))
}}