How to trigger automation on unavailable entity in MQTT?

I have this automation to notify me if Zigbee goes down:

alias: Notify if zigbee is diconnected
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.zigbee2mqtt_bridge_connection_state
    to:
      - unavailable
    for:
      hours: 0
      minutes: 2
      seconds: 0
conditions: []
actions:
 xxx
mode: single

But it does not seem to trigger if the bridge becomes unavailable. I think it is because the entire entity becomes unavailable somehow?

How can I make it trigger when the entity becomes unavailable?

    to:
      - unavailable
      - unknown

Tried it but no, it did not trigger when its unavailable.

Check that the entity id you have used in the trigger is correct.

Have you looked in Trace ?, or how do you determined that it does not “Trigger”
( Yes i noticed your “masked” action, just test with a simple light_turn-on ) " not a zigbee light :wink:

" No traces found " and no email was sent. Triggering the action manually works.

Sadly, I am positive its the correct ids:

alias: Notify if zigbee is disconnected
description: ""
triggers:
  - type: not_connected
    device_id: 65910e5201f4d12c1372e71c97aa1359
    entity_id: 41f558d88723e0ac9967da5867a2b3c6
    domain: binary_sensor
    trigger: device
    for:
      hours: 0
      minutes: 2
      seconds: 0
  - trigger: state
    entity_id:
      - binary_sensor.zigbee2mqtt_bridge_connection_state
    to:
      - unavailable
      - unknown
    for:
      hours: 0
      minutes: 2
      seconds: 0
conditions: []

Try to change the type , What does the Entity

Have for “States” ?

Yes , You can run/trigger it manually, but it will never show “unavailable” i think, check the sensors state in Dev-Tools

Yeah, those attributes are “valid” when the device is connected and “working”. I am talking about when my mqtt instance goes down and the entire devices is basically gone. Maybe some sort of custom sensor in configuration.yaml is needed?

If i understand you correct, this “connection_state_disconnected” sensor, What does it show in /Developer-tools#states
And while your there, also check the other sensors various States
Dunno why you suddenly added this above sensor to the equation thou, because you didn’t had this involved, in your first example

in Yaml or Helper, what ever, Yes maybe, … But you have to know Your Sensors First, otherwice there’s no point in trying with a template

Its the same sensor?

This entity likely goes to “off” when not connected. You could try adding it to the list of states:

    to:
      - unavailable
      - unknown
      - "off"

As Chris above say, try to “cut off” the device and see whether
trigger
This will change to “off” Or Disconnected etc.
I.e as it might eventually end up in an “unavailable” does, does not mean that this is the “first state change” which occur , So that Device/Entity can not be used as a trigger, because it’s “Gone” . The “unavailable” You see in history is a system state, not an entity state-change

Actually the Trigger in the pic, might even show “On”, i.e “State-Disconnected”= True
However this can happen ?, as it’s already “gone”
( Must in that case be the Integration has taken into account every scenario/ it can end up in, beside that the Device is actually still “On/available/etc”
Pretty weird backwards thinking approach " If “Gone” == On :joy:

Note, I would use the Trigger “Connected”, i.e if trigger “connected” change to X,Y or Z

You might only be able to use that trigger you’r “playing with”, to I.e
If trigger " Disconnected" change to “On” / Action “Lighten Up”

Are you looking for a trigger event for something that didn’t happen?

Some times i honestly have no idea what you are talking about

I think I will give up on this, didn’t think it would be that hard to detect when the entity is not available in the integration. :smiley:

You won’t be able to directly trigger for it. You will have to poll in a loop (oh how I hate that), and raise a trigger event for when it changes status.

Hmm ok, yeah polling sucks but maybe once a minute wouldn’t be that bad.

Actually, I am mostly interested in to check the status at a specific time.

My use case is that I have watchtower that updates my docker containers every week to latest. Sometimes, this breaks mqtt and I would like to be notified when that happends. So perhaps a check of the state could just be performed 5 minutes after the update, that would give me 99% of what I need this for :smiley: