Open\Close sensor notifications issue

Hello!

I have SNZB-04P sensor installed via Zigbee2mqtt. Everything works fine and home assistant sees it’s OPEN\CLOSED states without problems.

Decided to make an automation to get Push Notification’s and everything got messed up :joy:

When door is opened I get two notifications in a row - Door Closed + Door Opened
When door is closed I get two notifications in a row - Door Closed + Door Closed

What am I doing wrong? :grinning:

Yaml for Door Opened:

alias: Гараж (Відкриття)
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.datchik_vidkrittia_garazh_contact
    to:
      - "on"
    for:
      hours: 0
      minutes: 0
      seconds: 1
conditions: []
actions:
  - action: notify.mobile_app_iphone_rostyslav
    metadata: {}
    data:
      message: Відкрито!
      data:
        push:
          sound:
            name: default
            critical: 1
            volume: 1
      title: ГАРАЖ
mode: single

YAML for door closed

alias: Гараж (Закриття)
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.datchik_vidkrittia_garazh_contact
    to:
      - "off"
conditions: []
actions:
  - action: notify.mobile_app_iphone_rostyslav
    metadata: {}
    data:
      message: Закрито!
      data:
        push:
          sound:
            name: default
            critical: 1
            volume: 1
      title: ГАРАЖ
mode: single

I would guess this has to do with having 2 separate automations and the way the sensor is handling it’s state. I would try using a single automation to handle both the ‘open’ and ‘closed’ positions:

alias: Гараж (Статус)
description: "Сповіщення про відкриття та закриття гаража"
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.datchik_vidkrittia_garazh_contact
    # Ми прибираємо "to", щоб тригер спрацьовував на будь-яку зміну стану
conditions: []
actions:
  - action: notify.mobile_app_iphone_rostyslav
    metadata: {}
    data:
      title: ГАРАЖ
      message: >
        {% if is_state('binary_sensor.datchik_vidkrittia_garazh_contact', 'on') %}
          Відкрито!
        {% else %}
          Закрито!
        {% endif %}
      data:
        push:
          sound:
            name: default
            critical: 1
            volume: 1
mode: single

Note: I used AI to give me that code, hence not sure if the non-english bits are correct.

1 Like

Tried Your code and even vibe coded with Claude one more alternative automation - still get two messages on open (Open+Open) and two on close (Close+Open) :slight_smile:

One more sensor reports correct. Could it be sensor malfunction? Is it possible to reset device or to reupload firware?

Where to dig more?