Using GPIO binary sensor as readonly cover

I deployed ESPHome board to connect to my front gate opener and read the open/closed state in Home Assistant. The gate opener has a AUX output that reports the gate state, I guess using a relay in the opener. The output from the opener looks like this:

  1. Gate closed - circuit open
  2. Gate opening - circuit opening and closing every 1 second
  3. Gate open - circuit closed
  4. Gate closing - circuit opening and closing every 0.5 second

So far it is integrated into HA using a GPIO binary sensor and it looks like this:

There is one thing that I’d like to improve here - possibly make HA see this as a cover. I have a separate integration that allows me to trigger gate opening and it is displayed in HA as a lock. I can only trigger one action, so I’d like a cover that has open/closed/opening/closing state and only one action: open. Is this possible?

Quite surely it’s possible.
Maybe some combination of binary sensor, pulse counter and template cover…

2 Likes

Take a look at the feedback cover for this too.

I’m thinking some copy binary sensors which leverage some of the delayed_* family of filters could be used here for opening/closing state detection too.

I don’t quite get this bit though. I guess for the closed action you could put in a dummy action like a delay if that’s what you want.

Also, do you have a ā€œstopā€ control available?

1 Like

or multiclick…

2 Likes

Thank you for the ideas!

So to explain my setup more clearly:

  1. My only available input (for the gate state) is ESPHome binary sensor described in the original post.
  2. My only available output (action?) is the possibility to open the gate via Hikvision Door Station. It is also already integrated into HA and shows two locks (I have two gates actually, but let’s consider only one here).


It shows like this in HA.

So if it’s possible, I’d like for this newly created cover to have only one action - open. It should actually ā€˜call’ unlock on this Hikvision Lock under the hood. I believe I can also stop the gate opening by clicking the lock button while gate is opening, but I’m not interested in that.

So to answer the rest:

  1. Feedback cover seems like not a good match, since it requires the actions but the sensors are optional? I think I want something opposite? I have the possibility to detect all states (open/closed/opening/closing), given sophisticated enough config. But I can only trigger ā€˜open’ action. Or do I misunderstood something?
  2. Copy sensor seems like a good idea, thank you. Do I understand correctly that I’d create e.g. 4 copy sensors with different filters to have 4 on/off binary states for open/closed/closing/opening respectively?

Right now the biggest question for me is how to combine binary sensor (or sensors?) and lock into one cover? Should I use the template cover? Template - Home Assistant

esphome binary sensor on multi click

EDIT
Closed = OFF for at least 2s
opening = on at least 900ms, off at least 900ms, on at least 900ms, off at least 900ms
open = ON for at least 2 s
Closing = on at most 550ms, off at most 550ms, on at least 550ms, off at least 550ms

2 Likes

Let’s say you make plain template cover without lambda and binary sensor with multiclick approach. You update the template cover from binary sensor.

binary_sensor:
  - platform: gpio
    id: gate_signal
    name: "Gate Signal"
    pin:
      number: GPIO4 # whatever your pin is
      mode: INPUT_PULLUP
       
    filters:
      - delayed_on: 80ms # for bounce
      - delayed_off: 80ms

    on_multi_click:
      # GATE OPEN
      - timing:
          - ON for at least 2s
        then:
          - cover.template.publish:
              id: gate_cover
              position: 1.0
              current_operation: IDLE

      # GATE OPENING (1s pulses)
      - timing:
          - ON  for 0.8s to 1.2s
          - OFF for 0.8s to 1.2s
          - ON  for 0.8s to 1.2s
        then:
          - cover.template.publish:
              id: gate_cover
              current_operation: OPENING

and so on…

2 Likes

I think Karosms approach above is good and probably a nice way forward.

The multiclick is probably a better fit here than the delay_*

Sometimes I like to create the copy binary sensors for each state you are tracking as they can sometimes be useful of themselves and can be handy for debugging. You can make them internal to reduce clutter. But probably not really necessary in the first instance here.

Maybe, maybe not. One has to experiment with different setups to find the most reliable one.

Also, OP didn’t mention the board. Binary sensor now uses interrupts as default, but the approach is still not 100% clear to me.
Interrupt_type might also have effect…
Pulse counter looks like ā€œwrong toolā€ here, but would use pcnt on esp32 and might offer some advantage (or not work at all).

1 Like

Oh, I didn’t expect such a detailed example, thank you for all of the suggestions! The on_multi_click feature looks like a perfect fit there.

The board is Olimex ESP32-PoE. Does that change anything?

I’ll try to experiment with this in the following days and let you know the results!