Help requested trend sensor identifying increase and decrease of presence with Aqara FP2

Hi all,

I am trying to get a simple “increase” or “decrease” of presence with my Aqara FP2 presence sensor, so I could automate playing and pausing my Apple TV.

The Aqara FP2 is connected via HomeKit, but doesn’t tell the amount of people present. With the workaround here, I created different zones for my couch where I want to count presence. Big thanks to @John_Kotrolos, see (Room Multi People Detection in HA, with Aqara FP2 sensor)

So I got 5 different ‘zones’ for my couch, which are working properly and as expected. I have setup a template sensor that count the total number of zones that report ‘present’.

{{ states.binary_sensor
  | selectattr('entity_id', 'search', 'woonkamer_presence_sensor_aqara_presence_sensor_bank*')
  | selectattr('state', 'eq', 'on')
  | list | count }}

I want to use the increase and decrease of this value to drive automation to pauze / play my Apple TV:

In pseudo.

If "Increase" is "true" AND "Apple TV" is "Paused" than play
If "Decrease" is "true" and "Apple TV" is "Playing" then pause

As part of this discussion (click!) I have setup two trend indicators. One would indicate a increase and decrease, by measuring the same but report inverted

binary_sensor:
  - platform: trend
    sensors:
      increase:
        entity_id: sensor.presence_couch_count
        max_samples: 2
        min_samples: 2

binary_sensor:
  - platform: trend
    sensors:
      decrease:
        entity_id: sensor.presence_couch_count
        max_samples: 2
        min_samples: 2
        invert: true

This does seem to work, but the Aqara sometimes report being present in two zones which is corrected in a split second. So when I get to the couch, it recognized me in two zones, reporting 2 and within a split seconds records 1. Which causes the automation to start playing again (cause increase) but directly paused (cause decrease)

I tried to change the sample_duration and min/max value but no success to filter out the false positive. Basically, if I can ignore a new value to the trend sensor for one second it would solve my issue, but I find it hard to understand the configuration of the trend sensor and if this is even possible.

Anyone got a good idea to help me out?