These are great! I started off really trying as much to consolidate my automations, but like may here mentioned often times when i need to troubleshoot something it’s harder to do that. For example, my setup I have each room with an “_occupied” helper. (i.e. input_boolean.living_room_occupied).
I have an automation that detects presence, such as motion, or the TV turns on (apple TV) or a bed sensor has detection, and it will mark the room as occupied. A second automation will turn on the light if and when a room becomes “occupied.” This way if a motion detector thinks there is no one there, it won’t turn off the light unless it considers the room unoccupied. Same thing for a manual light switch press. a “input_boolean.living_room_manual” makes it so if a light switch gets pressed manually, it turns that on and nothing will turn it off unless the switch is hit again.
For the occupancy automation, the triggers are all of my motion sensors for every room (in one automation). If detected, it uses the following template to turn on an input_boolean:
entity_id: input_boolean.{{area_name(trigger.entity_id)}}_occupied
Turning off based on the sensors in my house, it has a condition:
{{
states('input_boolean.' ~ area_name(trigger.entity_id) ~ '_manual') in ['off']
and
states('media_player.' ~ area_name(trigger.entity_id) ~ '_apple_tv') in ['standby', 'off', 'unknown']
and
states('binary_sensor.' ~ area_name(trigger.entity_id) ~ '_motion_sensor') in ['off', 'unknown']
and
states('input_boolean.' ~ area_name(trigger.entity_id) ~ '_sleep') in ['off', 'unknown']
and
(
(expand(state_attr("input_select." ~ area_name(trigger.entity_id) ~ "_connected", "options")) | map(attribute='last_changed') | reject("<", now() - timedelta(minutes=2)) | list | length > 0)
)
}}
That way it only considers the room unoccupied if everything is off that could be off, even if that room doesn’t have that sensor. The last part of that is what I’ve been messing aroudn with to reduce false positives if I really haven’t left the room. It only turns it off if a connected room (a input_select with a list of adjacent rooms) has detected motion or been occupied within the last 2 minutes, or an adjacent room is currently occupied.
This does make for a pretty satisfying setup, since every device has a configured area, but as you can see it really does complicate things if one room really isn’t acting the way it should be. I really only have 4 or so automations with it set up this way and I can just add a new sensor to the one automation and the rest of the manual and occupancy automations function as normal.
I was just curious to see how others had it set up.