TLDR: if occupancy detected → cleared → detected inside a time window defined by delayed_off the sensor will publish two state changes - OFF immediately followed by ON at the end of the delayed_off window.
In the case below, I am sitting in front of the sensor holding very still so the sensor state clears. As you can see from the logs, 10s after the sensor initially detects 0 targets, the OFF state is sent.
[13:05:10][D][sensor:093]: 'Target Count': Sending state 0.00000 with 0 decimals of accuracy
[13:05:19][D][binary_sensor:036]: 'Occupancy': Sending state OFF
11s later, I move into the detection area triggering an ON state - so far so good
[13:05:10][D][sensor:093]: 'Target Count': Sending state 0.00000 with 0 decimals of accuracy
[13:05:19][D][binary_sensor:036]: 'Occupancy': Sending state OFF
[13:05:30][D][binary_sensor:036]: 'Occupancy': Sending state ON
[13:05:30][D][sensor:093]: 'Target Count': Sending state 1.00000 with 0 decimals of accuracy
Next, I hold very still to clear the presence detection 13:05:37, after which I move again 13:05:38.
[13:05:10][D][sensor:093]: 'Target Count': Sending state 0.00000 with 0 decimals of accuracy
[13:05:19][D][binary_sensor:036]: 'Occupancy': Sending state OFF
[13:05:30][D][binary_sensor:036]: 'Occupancy': Sending state ON
[13:05:30][D][sensor:093]: 'Target Count': Sending state 1.00000 with 0 decimals of accuracy
[13:05:37][D][sensor:093]: 'Target Count': Sending state 0.00000 with 0 decimals of accuracy
[13:05:38][D][sensor:093]: 'Target Count': Sending state 1.00000 with 0 decimals of accuracy
[13:05:47][D][binary_sensor:036]: 'Occupancy': Sending state OFF
[13:05:47][D][binary_sensor:036]: 'Occupancy': Sending state ON
The problem: notice how at 13:05:47 the Occupancy state rapidly flips from OFF to ON. The net result of the occupancy state is ON, but I have the occupancy tied to an automation watching for both states. Since this happens so fast, the first automation is not complete by the time the second state change again triggers the automation - this means the second execution is ignored and the end result is that the OFF automation is fired even though the current state is ON. My current bandaid to the rapid state change is to put a 3 minute duration check on the OFF state change.
It is totally possible that I don't understand how filters are supposed to work; to me, it seems that with delayed_off: 10s in the above configuration the ON state change would only fire if the sensor detected presence after 10s of no presence detection. Or put in context of my example above: I am surprised to see the last two log messages where any state change is published.
TLDR: if occupancy detected → cleared → detected inside a time window defined by
delayed_off
the sensor will publish two state changes -OFF
immediately followed byON
at the end of thedelayed_off
window.Using the following configuration
In the case below, I am sitting in front of the sensor holding very still so the sensor state clears. As you can see from the logs, 10s after the sensor initially detects 0 targets, the
OFF
state is sent.11s later, I move into the detection area triggering an
ON
state - so far so goodNext, I hold very still to clear the presence detection 13:05:37, after which I move again 13:05:38.
The problem: notice how at 13:05:47 the
Occupancy
state rapidly flips fromOFF
toON
. The net result of the occupancy state isON
, but I have the occupancy tied to an automation watching for both states. Since this happens so fast, the first automation is not complete by the time the second state change again triggers the automation - this means the second execution is ignored and the end result is that theOFF
automation is fired even though the current state isON
. My current bandaid to the rapid state change is to put a 3 minute duration check on theOFF
state change.It is totally possible that I don't understand how filters are supposed to work; to me, it seems that with
delayed_off: 10s
in the above configuration theON
state change would only fire if the sensor detected presence after 10s of no presence detection. Or put in context of my example above: I am surprised to see the last two log messages where any state change is published.