Open/closed state of gate based on electric lock signal from motors

My front gates have SCS Sentinel Opengate motor on them. I fed a signal that normally opens an electric lock to a Shelly input (configured as a detached switch). That signal on the Shelly goes “on” for 2 seconds only when the gate is opening so it can serve as a way to monitor open/closed state.

I had everything working (cover template with open/close states based on a derivative sensor) on a Raspberry Pi docker until the docker just disappeared for the sd card. Probably some corruption. I have been struggling to get is back up and running for days on my new proxmox mini-pc now. Anyway: I need a binary sensor that stays on even after the 2 second input pulse has vanished.
This works:

template:
  - trigger:
      - platform: state
        entity_id: binary_sensor.shegategarage_input
        to: "on"
    binary_sensor:
        name: gategaragestate
        state: "on"

But I need this to refresh at every motor movement, however this does not work:

template:
  - trigger:
      - platform: state
        entity_id: switch.shegategarage
        to: "off"
    binary_sensor:
        name: gategaragestate
        state: >
            {% if is_state("binary_sensor.shegategarage_input", "on") %}
                "on"
            {% else %}
                "off"
            {% endif %}

Screenshot 2023-12-13 173516

BTW: The shegategarage switch is on for 1 second only, as the gate is triggered by pulses. The trigger is set on the off slope of the pulse, as after that second delay the lock open signal (read as shegategarageinput) is still high.
The image shows that when shegategarage goes off, shegategarage_input is still on for 1 sec, so it should evaluate to “on”.

My faith in Home Assiantant is waivering a bit because of this issue. It seems like the new template syntax is somewhat buggy. It is so strange that I could have it working nicely on my old Pi installations.

You have issues with your binary sensor template, you’re outputting "on" when it needs to just be on.

Secondly, there’s a chance this get’s out of sync, and you’ll have no quick/easy way to fix it.

If I were in your shoes, I’d make an input boolean that can store the state of the garage and I’d write an automation that just toggles it based on the shegategarage.

Then use that input_boolean as the state on your template cover.

if you need help with this, post all entity_id’s involved and how they behave and I can help you cobble something together that works.

1 Like