State triggers on automation reload

i have a “garage door lock” switch that prevents me from accidentally opening my garage door…if i have it turned off for more than 10 minutes, it turns back on. it works exactly as i want it to work…except if i have the switch turned off and then do some other automation work, and reload automations. the switch never gets turned back on.

is there a way to get this to trigger in a situation like that? i tried using homeassistant start, but that didn’t trigger it either…

# re-lock garage door after 10 minutes of being unlocked
- alias: "Garage Door Re-lock"
  trigger:
    - platform: state
      entity_id: switch.garage_door_lock
      state: 'off'
      for:
        minutes: 10
  action:
    - service: switch.turn_on
      entity_id: switch.garage_door_lock

What if you use the initial: attribute for the switch. Do switches use that like input_booleans do?

  initial: on

unfortunately that didn’t work…the config wouldn’t even load with the initial attribute set for the switch.

Couple thoughts:

  1. Would it work to have the state of garage door itself be the trigger? Or is your garage_door_lock a stand-in for a door that you can’t get the state of. For instance, with my Myq-suppported door, it has a state of open/closed.
  2. Could you use a binary (that does support initial) instead of a switch?

Maybe a script works for this?

- alias: "Garage Door Re-lock"
  trigger:
    - platform: state
      entity_id: switch.garage_door_lock
      state: 'off'
  action:
    - service: homeassistant.turn_on
      entity_id: script.re_lock

script:

re_lock:
  sequence:
    - delay: 600
    - service: switch.turn_on
      entity_id: switch.garage_door_lock

i’m not sure how using the state of the garage door would work - wouldn’t that just be the same issue i’m having now? the system knows the switch is off, but isn’t triggering the automation to re-lock it…

interestingly enough, i am using a input_boolean as the main variable. the switch just toggles that input on/off (on = locked, off = unlocked). now that i think about it that’s probably overkill, but i didn’t see a way to toggle the boolean via the UI (which i obviously need to be able to do). i suppose i could just use the value of the switch itself, but then we’re still in the same situation where i can’t get it to auto-lock itself if i reload the server or automations while the switch is off (i’d have to remember to do it myself or set a time trigger to do it once a day). i suppose the time trigger would work, but then it’s unlocked until it hits that time (whatever it may be), so that’s not optimal either…

that’s basically what i’m doing now (minus the script), but the problem is that the automation is never triggered if i reload the automation (or the entire server) while the switch is turned off. it works absolutely perfectly and does exactly what i want as long as the server is running…but if i turn the switch off and then do some work on automations and reload them before i turn the switch back on, it never triggers the automation and the re-lock never happens. i could try it with a script, but i don’t know how that would be any different from just turning the switch back on like i am right now. it seems the automation just isn’t being triggered after a reload, unless you turn the switch on and back off again…

i thought leaving out the ‘from:’ part would work, because it would just sense when the switch has been in ‘off’ mode for 10 minutes rather than triggering when it changes from ‘on’ to ‘off’…but that doesn’t seem to be the case.

as a follow up on this, i switched it to an input_boolean and used initial: ‘on’…this still doesn’t work. if i turn the switch off and then reload automations, the switch stays off and the automation to turn it back on never triggers.

Thought when only reloading automation, the script would work. But on restart?
I think you have to use a time trigger which runs every minute.
conditions:

  • switch off and switch.last_changed > 10minutes
    action:
  • switch on

isn’t that effectively the same thing as saying

  trigger:
    - platform: state
      entity_id: switch.garage_door_lock
      state: 'off'
      for:
        minutes: 10

No, the state trigger only triggers on state change.
The time trigger every minute, or how you adjust it.

oh, that explains it then. i thought the state trigger was on state change only if ‘from’ was specified (which i’m not)…otherwise i thought it was triggered once it was in a certain state for whatever specified time.

did you manage to resolve this then?

I have the same issue when I restart my HA the automation does not get triggered for some reason and does not read the state i.e. on or off of my binary switch.