Alarm automation based on MQTT trigger - avoid triggering at start-up

Hi all,

so I have an automation triggering on MQTT event for a smoke detector

  trigger:
    - platform: mqtt
      topic: 'sensors/rtl_433/Smoke-GS558/6743/time'

issue is this triggers every time I reboot HA or reload automations.
Now I think issue is the topic is published with retained flag which in anycase I need (to retain the message) for other reasons.
Topic is:

2020-07-19 09:31:57

so basically a date.
how can I make such that, retaining it, automation does not trigger? any suggestion?

Ignore the trigger for the first 5 seconds after a restart by adding this condition:

    condition:
      condition: numeric_state
      entity_id: sensor.uptime
      above: 5

You will of course need the uptime sensor:

1 Like

thanks for your answer: I will implement this, it should cover HA restart use-case

It won’t, by my understanding, “reload automation” use-case: am I correct?

Uptime is not affected by a reload

Though by the documentation you can set the units to days (default), hours or minutes
So I don’t think 5 seconds is doable.
You may have to create a boolean (default) on and reset it x seconds after a restart or something like that.

Hi,

So usage of uptime is clear to me.
The fact is when I reload automations the automation triggered by the MQTT topic subscribe again to it and this triggers the automation itself.

Uptime (I set 5 minutes as condition) works fine to prevent it triggering upon HA restarts, but not in case of automation reload.

Does it make sense or am I missing something?

It makes sense. Turn off retain flag.

The fact is I would like to maintain the retain flag for other reasons hence looking for an alternative way

It seem to me that retain makes little sense for a transitory state. Perhaps tell us why you need it and there may be another solution.