Automation triggered for no apparent reason

Hello,

I created a new automation to notify me in case of water flooding (Xiaomi Aqara Zigbee sensor, connected via deCONZ). The notification service I use is Join from JoaoApps.
The automation works well when I intentionally immerse the sensor in water or remove it. However, yesterday, I received 4-5 notifications with the ‘else condition’ message for no apparent reason. At first, I thought the sensor state changed from ‘on’ to ‘unknown’ or from ‘unknown’ to ‘off’, but the history shows it’s not the case.
here is my automation, is there anything wrong with it ?

- alias: Notification Presence Eau
  initial_state: true
  trigger:
    platform: state
    entity_id: binary_sensor.capteur_de_fuite
  action:
    - service: notify.join_notify
      data:
        title: "Alerte Home Assistant"
        message: >
          {% if is_state('binary_sensor.capteur_de_fuite', 'on') %}
            Présence d'eau détectée à {{ as_timestamp (now()) | timestamp_custom('%Hh%M') }} !
          {% else %}
            Problème de fuite réglé à {{ as_timestamp (now()) | timestamp_custom('%Hh%M') }}
          {% endif %}
        data:
          icon: "https://www.iconsdb.com/icons/preview/caribbean-blue/water-xxl.png"
          smallicon: "https://i.ibb.co/BLgk8jY/home-assistant.png"
          vibration: "0,65,706,86,657,95,100"
          url: "https://wwwwwwwww:8123"

could you explain why you have done it this way

[quote="mat44150, post:1, topic:172413"]
{% if is_state('binary_sensor.capteur_de_fuite', 'on') %} Présence d'eau détectée à {{ as_timestamp (now()) | timestamp_custom('%Hh%M') }} ! {% else %} Problème de fuite réglé à {{ as_timestamp (now()) | timestamp_custom('%Hh%M') }} {% endif %}
[/quote]

as not everyone speaks French.
Also why don’t you want to restrict your trigger to something like from:off to: on and/or have a condition to avoid reacting to any change (and btw, I’m not sure you’ll see all changes in History (did you mean logbook?))

Explanation:If my sensor reports an “on” state, I send a message with “flooding detected at time x”, otherwise it reports a message with “problem solved at time x”.

I was not aware of the from: off to: on conditions. I will use it and it will probably solve my issue with spurious events.
Yes, I meant logbook… The logbook does not show all events, but the history shows a few ‘unknwown’ spurious states that I overlooked the first time. I guess my weird notifications came from a change from ‘unknown’ to ‘off’ state.
Thanks for your help

I was talking about trigger section actually. However, you can do similar things at conditions level as well.

That’s only a part of what you need to keep in mind when using state trigger without any restrictions.
It triggers every time state or any attribute’s value changes. So unless you know what you’re after add at least one of from/to.

1 Like