Zigbee2Mqtt Binary trend sensor false trigger?

I have an Aqara Temperature/Humidity/Pressure sensor in my bathroom.
I use it to detect if someone is taking a shower and if so I start a ventilation script that enables the ventilation for a period of time.
I detect a shower by a steep increase in humidity using a binary trend sensor.

This worked fine but I recently switched from the official Aqara gateway to Zigbee2Mqtt
I updated the sensor config and the humidity values it reads are fine. (also in the log)

But the binary trend sensor detects steep increases out of nowhere.
I have seen gradients of 50 or higher. (which to me must be impossible)

With the Aqara gateway setup I never experienced any false triggers.
Because of the recent switch I suspect the combination between the two components.
At user-level I can’t find anything that is going wrong

Binary trend sensor config

    binary_sensor:
      - platform: trend
        sensors:
          shower_detector:
            entity_id: sensor.0x00158d00022cb776_humidity
            min_gradient: 0.20
            sample_duration: 300
            device_class: moisture
            friendly_name: "Shower detector"

Sensor entity info:

    sensor.0x00158d00022cb776_humidity 	63.72 	
    unit_of_measurement: %
    linkquality: 34
    device_class: humidity
    voltage: 3005
    battery: 99
    friendly_name: Bathroom Humidity

Does anyone have a clue what is going wrong / Causing this?

No one has a clue how to debug this? :disappointed_relieved:

Here is my automation… replace the cover with script.turn_on

Does it help?

 - action:
   - service: automation.turn_off
     entity_id: automation.bad_switch_feuchtigkeit_luftung
   - delay: 00:15:00
   - service: automation.turn_on
     entity_id: automation.bad_switch_feuchtigkeit_luftung
   - condition: state
     entity_id: switch.badezimmer
     state: 'off'
   - data:
       entity_id: switch.badezimmer
     service: switch.turn_on
   - delay: 00:00:02
   - data:
       entity_id: switch.badezimmer
     service: switch.turn_off
   alias: Bad - Switch - Feuchtigkeit Lüftung
   condition:
   - above: '68'
     condition: numeric_state
     entity_id: sensor.0x00158d00016d0d0d_humidity
   id: '1515580845686'
   trigger:
   - entity_id: switch.badezimmer
     from: 'on'
     platform: state
     to: 'off'

Thanks, this was my approach before the trend-detection.
The issue i found with that is when it is very humid weather the fan also turns on (having no effect on humidity because the outside air is also humid)

In this topic Trigger -> If humidity changed about 5% in time period (5min)
They are using the same approach and it seems to be working for them.

I’ve increased the sample duration on my trend config. Maybe it helps

I think I found the culprit. My theory is that Zigbee2mqtt only updates the value when the sensor sends a new value.
Because the sensor only sends a new value when the value has changed with a certain threshold the time between messages can be more that one hour.
I think the aqara API repeats the last received value every once in a while.

I had a time limit on my samples resulting in no samples at all, and when a sample did arrive it would trigger the trend sensor.

I changed my configuration to this and now it works as before:

binary_sensor:
  - platform: trend
    sensors:
      shower_detector:
        entity_id: sensor.0x00158d00022cb776_humidity
        min_gradient: 0.125
        max_samples: 4
        device_class: moisture
        friendly_name: "Shower detector"

I have the sensor close to my shower and it works every time because the value changes with the “certain treshold” :wink: