Automation keeps running when restart Homeassistant

Hi
I have a strange issue just started recently
I have an Automation that keeps Run Action when I restart Homeassistant
This only started few weeks ago, I deleted the automation and re-wrote it but still will run on restart or reboot
Here is the yaml file
alias: Gate Opened
description: “”
triggers:

  • type: opened
    device_id: 250c67d19721f7d5398c5caf4c68f739
    entity_id: edb57cd861e3c90e72fa795f12c39b4f
    domain: binary_sensor
    trigger: device
    for:
    hours: 0
    minutes: 0
    seconds: 4
    conditions:
    actions:
  • device_id: ab4dfd9eb9885beeb2b7f95402ce3beb
    domain: select
    entity_id: 7a6fe4ac2dc340fd443ced776c8831f1
    type: select_option
    option: Doorbell Ring 8
  • action: siren.turn_on
    metadata: {}
    target:
    device_id: ab4dfd9eb9885beeb2b7f95402ce3beb
    data:
    volume_level: 0.65
  • delay:
    hours: 0
    minutes: 0
    seconds: 5
    milliseconds: 0
  • action: siren.turn_off
    metadata: {}
    target:
    device_id: ab4dfd9eb9885beeb2b7f95402ce3beb
    data: {}
    mode: single

This sets a device “SmartHubby” [wife named this] which is a TPlink hub with sound output. to ring whenever the gate is opened

Would you be so kind as to adjusting the format of your code so that we can read it properly & check the YAML spacing, etc. Editing your original is the preferred way. It is very hard for us to tell what is what when the text formatter jumbles everything like that.
You can use the </> button like this… How to format your code in forum posts
OR… Here is an example of how to fix formatting from the site FAQ Page.
How to help us help you - or How to ask a good question.

Sorry
When I copy and paste the format seems to get lost. when I paste here it is ok till I post it

alias: Gate Opened
description: ""
triggers:
  - type: opened
    device_id: 250c67d19721f7d5398c5caf4c68f739
    entity_id: edb57cd861e3c90e72fa795f12c39b4f
    domain: binary_sensor
    trigger: device
    for:
      hours: 0
      minutes: 0
      seconds: 4
conditions: []
actions:
  - device_id: ab4dfd9eb9885beeb2b7f95402ce3beb
    domain: select
    entity_id: 7a6fe4ac2dc340fd443ced776c8831f1
    type: select_option
    option: Doorbell Ring 8
  - action: siren.turn_on
    metadata: {}
    target:
      device_id: ab4dfd9eb9885beeb2b7f95402ce3beb
    data:
      volume_level: 0.65
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - action: siren.turn_off
    metadata: {}
    target:
      device_id: ab4dfd9eb9885beeb2b7f95402ce3beb
    data: {}
mode: single

When I click edit it shows correctly same as the YAML script, same as shown in Notepad ++
Ahh Got It

Does the automation run always on startup, or only on startup when the state of the binary sensor is open?

1 Like

The automation is executed when the gate is opened.
But for some strange reason is also triggered when homeassistant is restarted, this also includes times shen updated
This only started happenjng a few week back. Was nevef the cass before
This led me to replace the gate sensor thinking it may bd problem
I also deleted and re-created the automation
I have similar automations on the windows but they dont get affected
The automations were created using thd UI not YAML

I meant to ask if the automation also triggers unwanted in case your HA restarts, and the gate is closed.
My guess is that the automation is triggered by a state change from unavailable to on (opened). If that is indeed the case, it will only trigger when the gate is open at the time of the restart, and not when the gate is closed.

Replace the automation’s Device Trigger with a State Trigger that is configured to trigger only for off to on state-changes.

Replace this section:

  - type: opened
    device_id: 250c67d19721f7d5398c5caf4c68f739
    entity_id: edb57cd861e3c90e72fa795f12c39b4f
    domain: binary_sensor
    trigger: device
    for:
      hours: 0
      minutes: 0
      seconds: 4

With this:

  - trigger: state
    entity_id: binary_sensor.your_gate
    from: 'off'
    to: 'on'
    for:
      hours: 0
      minutes: 0
      seconds: 4

Ensure you replace binary_sensor.your_gate with the actual entity_id of your gate’s Binary Sensor.

After you make the modification and save it (using the Automation Editor), restart Home Assistant and check if the automation is still triggered shortly after startup.

2 Likes

when I changed to the suggested from: ‘off’ to:‘on’
Try to save and get the error Message malformed: required key not provided @ data[‘triggers’][0][‘trigger’]
The gate trigger is a simple door sense Sonoff (SNZB-04P)
Should I use other option in place of OFF & ON
Tried Opene & close but obviously these are not correct either

The State Trigger I posted is correct. The error message indicates you may have copied it incorrectly because it is missing a “required key”.

The State Trigger I posted is completely different from the existing Device Trigger in your automation.
The recommendation is to replace the entire Device Trigger with a State Trigger.

1 Like

Yess
My Bad, I mistyped.
I typed only one g in trigger
now corrected it and it works. Thanks for this…

1 Like

Hi. I have this working however it always shows the gate is open after add this edit
Is there something else I need to do so it shows that5 the gate has closed again
Also it rings again when the gate is closed

Can you post the full automation you have right now, and also explain more clearly what goes wrong, and what you would have expected to happen.

I found the original problem
Is a broken magnet, somehow broke into 2 pieces and was sitting just on the edge of the sensor position.
So I replaced the magnet I reverted my original automation and all works correctly
I had thought it was the sensor so replaced it, but all my other window and doors were ok. so looked a bit deeper by putting the sensor on my work desk then saw it worked on the desk…
The problem was home assistant was seeing the gate open,