Seat occupancy sensor is too sensitive. How to output the average of a binary sensor?

Hi everyone

I’m a Home Assistant newb, so any help, guide, or key words to search would be greatly appreciated.

I’ve attached an Aqara window sensor to a car seat sensor to use as a seat occupancy sensor. I’m trying to create an automation so the standing desk will rise if I sit down for more than 1 hour. I’m using Zigbee2MQTT and the sensor works really well. Pleasantly surprised how instant the sensor is.

The problem is when I fidget or move while still sitting down, the sensor will go to a “clear” state for a second and reset the 1 hour timer. This sensor doesn’t have a separate sensitivity expose in zigbee2MQTT.

I’m thinking if I use the last 5 minute average of the occupancy state, then it should provide enough buffer to lessen the sensitivity.
I’ve tried creating a template binary sensor with the following code.

  - platform: statistics
    name: "Seat occupancy 5 min average"
    entity_id: binary_sensor.seat_occupancy_sensor_contact
    state_characteristic: average_step
       minutes: 5

I’m not sure if its doing anything, but it doesn’t update at all. I’m assuming the state is never changing. Do I need to force the sensor to start every 5 mins? Is there a way to continuously output the last 5 minute average state?

I’m currently trying to use the last 5 minute average of the state to lessen the sensitivity. I’m sure there are smarter ways to approach this.
Any ideas, help would be great.


All devices have a Debounce setting in Z2MQTT (it’s in Device > Settings tab) which should do exactly what you want.

From the Z2MQTT docs:
"Debounces messages of this device. When setting e.g. debounce: 1 and a message from a device is received, Zigbee2MQTT will not immediately publish this message. But it will combine it with other messages that are received max 1 seconds apart from each other. So there needs to be “N second of silence” from the device before the combined message is sent out.

For example debounce: 5 means that there needs to be “5 seconds of silence” from the device, before combined messages is sent out."

That is not a Template Binary sensor… it’s a Statistics sensor. Assuming it is configured in the proper place, it should output a number that reflects the percentage of the last 5 minutes during which the binary source sensor was “on”.

If that’s not what you are trying to do, you might want to consider using an actual Template Binary sensor with delay_on and/or delay_off assigned.