Wait for trigger issue for door lock

Hi, I have a magnetic release gate latch and a basic script that is supposed to turn on (unlock) the latch when the automation is triggered. It should then stay on until the gate is opened and then 1 second later turn off so when the gate is closed the gate latch secures the gate. I have a magnetic door/window sensor configured for the gate which correctly reports when it is opened. Despite my best effort using the script below does not work. Does anyone have any suggestions?

alias: Open Gate
sequence:
  - type: turn_on
    device_id: 8112475354f04f287ddf7328460797c1
    entity_id: switch.gate
    domain: switch
  - wait_for_trigger:
      - platform: state
        entity_id: binary_sensor.front_gate
        to: Open
        for: '1'
    continue_on_timeout: false
  - type: turn_off
    device_id: 8112475354f04f287ddf7328460797c1
    entity_id: switch.gate
    domain: switch
mode: single
icon: mdi:gate

First thing first. What doesn’t work?

The script runs forever and never completes. The gate gets unlocked but then remains unlocked. I can manually cancel the running Script but this does not relock (turn off) the gate. Therefore I believe the issue is with the “wait_for_trigger” component.

Ok. Why are you only waiting for 1 second for the trigger?
I’m not sure what happens in a wait_for_trigger after the for if there was no trigger, but I assume the automation exits.

Freeing the latch doesn’t mean the portal will be opened from the sensor perspective, does it? Somebody still have to push the portal open.

The continue_on_timeout is only valid if a timeout is specified, I think (and anyway, if set to false, the automation will exit).

Why are you only waiting for 1 second for the trigger?

Because once the gate is moved (opened) I want the latch to lock as soon as possible so when it’s swung closed it secures the gate. I do not want the latch to lock (turn off) until after the door/window sensor reports the gate is “Open” however.

I have tested this by triggering the Script and opening the gate and leaving it open for many seconds, the “binary_sensor.front_gate” reports “Open” but the latch never locks (turn off)

Freeing the latch doesn’t mean the portal will be opened from the sensor perspective, does it?

Correct, the latch can be unlocked (turn on) for many seconds before the sensor reports “Open” (which will not occur until the gate is physically pushed open). Once the sensor reports “Open” for more than 1 second it should then move to the step to “turn off” the gate latch.

It appears it never reports “Open” to the script as the script seems to run forever until manually cancelled and never runs the “turn off” step.

Is there anyway to trace Scripts in HA? I can show the trace for automations but cannot find the trace for scripts?

The state value of a Binary Sensor is on or off (not Open/Closed or Connected/Disconnected or Locked/Unlocked or anything else reported in the Lovelace UI based on the binary sensor’s device_class).

Change it to:

        to: 'on'
1 Like

Thanks 1 Million. This was doing my head in, I never understood that even though Lovelace and the UI reported “was opened” and “Open” the actual entity state was “on”. I’d actually tried “Opened”, “opened”, “open” and “Open” as states but it never occurred to me it could be simply “On”

Just while I’ve asked this: is there anywhere in the UI to trace scripts? or is this only for automations?

Currently, only automations support the trace feature.

1 Like

How would you go about making an automation to tell you if the sensor has gone offline? If the only possible states are ‘on’ and ‘off’ obviously there’s no 3rd state to show this despite home assistant UI reporting “unavailable”
Is there an internal state that registers it as “unavailable” that I could tap into?

What I overlooked to say is that the normal state values for a binary_sensor are on and off. When there’s something wrong with an entity, the issue is typically reported via the entity’s state value as unavailable. In fact, some situations may be reported as unknown. However, when discussing normal state values, it’s on/off for a binary sensor.

1 Like