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
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).
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?
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 normalstate 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.