Sensor notification automation when HA/Z2M is restarted

i have an automation that sends a notification when a door sensor is either opened or closed - these work correctly.

however, whenever HA restarts (due to update etc) or Z2M is updated/restarted i get a notification saying the door has closed (presumable because it’s reporting the current state of the sensor due to restart).

is there a way to stop that particular notification from sending?
this is the yaml for the “door closed” notification

alias: Rear door closed notification
description: ""
triggers:
  - type: not_opened
    device_id: a3f0a8d3339f29c2a73bc73ed57dd28c
    entity_id: 5444386840f4fcfc01788a085b9731c7
    domain: binary_sensor
    trigger: device
conditions: []
actions:
  - action: notify.mobile_app_simons_iphone
    metadata: {}
    data:
      message: Office Back Door  was closed.
      title: My Home
    alias: Send notification to Simons phone
mode: single

It is because on a restart, the device is shortly unknown. If you use a state trigger instead of a device trigger, you can add a condition

1 Like

something like this?

1 Like

Yes, Indeed.

There are also things like this you can do. adapt as needed…