A better way to record the state of room occupation


I’ve been using an input_boolean to maintain whether a room is currently occupied or not and want to shift this to an input_select with options: absent, enter, present, leave, so I can make more informed decisions on whether certain targets should be activated or not.

To illustrate with a use case:

  • enter is a temporary state that triggers tasks that need to be immediately activated (e.g. lights), or can be switched on/off quickly and with low energy consumption (e.g. turn on the ceiling fan or turn off dnd on an alexa media player).
  • present is a more permanent state, where the system is over 50% confident that whoever has come into the room will stay there. At this point I can trigger the air conditioner to switch on and adjust the room to a comfortable climate if required. But this is something I only want to do unless I’m confident the occupant will stay in the room for a decent amount of time.

I currently have motion sensors set to report every 60 seconds, which means, if there is motion and state is off then report state as on, if there is no motion in 60 seconds then report state as off. The sensors in the room are then combined with the brilliant Magic Areas, and then I read off the binary_sensor.area_motion_*

I also have a door sensor, which could raise the confidence level to 100% if there was recent motion, but in most cases the door is left open but remains occupied.

enter can be easily set based on the current state being absent and binary_sensor.area_motion triggered when state is on.

Setting present is little tricky. This is what I need help with and would been keen to understand what others have done to solve this problem.

I’m currently going with a trigger on input_select.room_state where state is enter for 2 minutes. Then have a condition which checks if binary_sensor.area_motion is on. This effectively triggers if there has been movement in the last minute after 2 minutes of entering.

A better solution I thought would be to trigger / check after 5 mins, and if in the last 5 mins binary_sensor.area_motion has been on more than 50% of the time, then set to present. The current conditions framework doesn’t report on the % of time a particular entity has been in a state over a time period.

Has anyone looked at this problem before and what solutions did you come up with?