Automation Triggers when HA restarts

Very recently, with the last two updates to HA Core, I have three (out of many, many) automations that trigger when HA comes back online. I have looked at the yaml code for the three problem automations and compared to the other automations, I see no difference. One is within the MQTT area, the other is an announcement from Alexa, and the other is ratgdo garage door controller.

All automations are developed via the UI.

Any insight into why this is happening and how to correct these three automations would be helpfull.

share the code?

Are you using “device triggers”? They work in a nonsense way that triggers even when going from “unavailable”. That means trigger “when door opens” does not only trigger when door contact goes from off to on, but also on HA restart - it goes from unavailable to on - while the door obviously didn’t magically move and just remained open the whole time. If that’s the case, I’d suggest to switch to “state trigger” and specify the change from off to on…

@armedad Code as requested:

alias: File Cabinet Drawer Closed
description: ""
trigger:
  - type: not_opened
    platform: device
    device_id: abfac92c880530fa756c0162de4af7a9
    entity_id: 09486f231c563ff09c5afa0c6e7afd42
    domain: binary_sensor
condition: []
action:
  - service: notify.mobile_app_dave_sm_n986u1
    data:
      message: File Cabinet Drawer Closed.
mode: single

another

alias: Clothes Dryer Stopped Notification Everywhere In The House.
description: ""
trigger:
  - type: not_moving
    platform: device
    device_id: d4a3571746e787dc6c5644f9652e0cf4
    entity_id: a368788eca707e8d1c5a801d433ebf17
    domain: binary_sensor
    for:
      hours: 0
      minutes: 1
      seconds: 0
condition: []
action:
  - service: notify.alexa_media_living_room_echo_spot
    data:
      message: OK, the clothes dryer stopped.  Time to fold the clothes.
      data:
        type: tts
mode: single

Thoughts?

@tomas1 Think I can do that (new to HA). :slight_smile:

So is there something in the code I just posted that helps?

I ask, as before I start jumping and making changes…if there is something obvious that I am doing or need to change how I am doing.

But I guess, why now, why these three (I posted two of them)? Why not the other sensors?

Could be the “nonsense way” you mention?

Standing by.

@armedad and @tomas1 I should mention both of the codes posted use a Smartthing multi-function sensor. the ragdo obviously does not - yet it behaves the same.

yet I have many of these Smartthing multi-function sensors around the house and only these two act this way.

Thoughts?

  1. follow what @Stiltjack said… this will help you, and also help us help you.
  2. if you’re looking to understand what is triggering these on restart, go restart it, then after it’s triggered, look at the trace or logbook and see the states of the entities as they get triggered.

@Stiltjack Thanks - I think. No - really thanks. This will take some reading and digesting. The more I get into HA, the more I learn - a good thing.

Well, I did get the call service right in parts of the automations. Now need to work the device aspect. And continue to learn.

While on this note, any good sources (books, courses, etc.) you could refer me to in learning yaml?

to give you the cliff notes version of the document:
don’t use device_id and entity_id with the big long hairy numbers/letters.

instead of that, use entity_id with human readable names. like sensor.drawer_closed.

you can try to read a book on yaml, but my advice is not to do that, but instead to use the UI to build out your logic, then switch it to yaml mode and read the yaml… make sure you understand what home assistant just generated for you.

then as you’re doing point things that you can’t figure out how to do in the ui, use a search engine and ask… most of the time, someone else has asked that same question and it’s already been answered here somehere with sample code…

1 Like

It states, for the clothes dryer automation, it showed the sensor not moving, then unknown, then not moving.

I also checked some other sensors (smartthings multi-function and others) that are to send me notifications and they showed the same behaviors, but did not alter me.
The behavior being in a known state (HA running) to unknow (HA Rebooting), then back to a known state HA running).

Cliff note version - thanks !

Yup - getting the real feeling on learning yaml…appreciate the patience.

ah… if the sensor goes from “unknown” to “not_moving” and stays at “not_moving” for 1 minute, then it will trigger again.

you can do this to exclude coming from “unknown”:

alias: Clothes Dryer Stopped Notification Everywhere In The House.
description: ""
trigger:
  - type: not_moving
    platform: device
    device_id: d4a3571746e787dc6c5644f9652e0cf4
    entity_id: a368788eca707e8d1c5a801d433ebf17
    domain: binary_sensor
    not_from:
      - "unknown"
    for:
      hours: 0
      minutes: 1
      seconds: 0
condition: []
action:
  - service: notify.alexa_media_living_room_echo_spot
    data:
      message: OK, the clothes dryer stopped.  Time to fold the clothes.
      data:
        type: tts
mode: single

you can add other possible bad states in the list.
just add them under - “unknown” if there are additional ones like “unavailable” and such.

Use a State Trigger in both automations that explicitly indicates the desired state-change (using its from and to options).

alias: File Cabinet Drawer Closed
description: ""
trigger:
  - platform: state
    entity_id: binary_sensor.your_file_cabinet
    from: 'on'
    to: 'off' 
condition: []
action:
  - service: notify.mobile_app_dave_sm_n986u1
    data:
      message: File Cabinet Drawer Closed.
mode: single
alias: Clothes Dryer Stopped Notification Everywhere In The House.
description: ""
trigger:
  - platform: state
    entity_id: binary_sensor.your_clothes_dryer
    from: 'on'
    to: 'off' 
    for:
      minutes: 1
condition: []
action:
  - service: notify.alexa_media_living_room_echo_spot
    data:
      message: OK, the clothes dryer stopped.  Time to fold the clothes.
      data:
        type: tts
mode: single

Why do it like that? Because if on startup the binary_sensor’s initial state is momentarily unavailable (or unknown) and then becomes off, that state-change is sufficient for a Device Trigger to detect as a change to off.

Don’t forget to change the entity_ids of the binary_sensors in my examples to match the ones in your system.

@armedad and @123 I will give both a try…learning. Appreciate your patience and give me a couple of days to do some testing.

@123 , @armedad , @Stiltjack, @WallyR, and @tomas1 I have studied, read, reread, listened, and relistened…am a bit smarter now. Thank you. :slightly_smiling_face:

Short version: At a novice but growing level - Understand entity vice device. Understand entity numeric and state features.

Appreciate both @armedad and @123 as you helped me walk through setting up the automations, but also enlightened me to factoring in error handling along with the state of the system/components on a restart/reboot.

Corrected the ratgdo door sensor, Dryer, and File cabinet automations as @123 suggested. And while using the UI, also stopped and examined the yaml code as @armedad suggested - very helpful.

In yaml code I am definitely in the crawl, walk, run stages…that would be very much crawling right now.

Also bottom line - those strange and seemingly random (odd that only three sensors acted this way - I suppose a feature somehow - but - I learned!) notifications have been corrected - thank you.

Again, many thanks to all - for me, you each gave a part of the solution that helped me better understand, and make better code in the future.

3 Likes