A very basic garage opener & help with lambda

I live in rented flat but wanted the automatic garage gate to be available on the dash Apple carplay.
I’ve managed to get it all working with esphome, but it bugs me that when clicking the garage opener it visually switches off immediately.
The actual gate remains open for around 60sec.
Is anyone able to help me put a 60s delay before the “return COVER_CLOSED;”
Despite google and hours of trying, I just can’t work out how to do it.


switch:
  - platform: gpio
    pin: GPIO0
    id: open_relay
    name: Gate Relay
    on_turn_on:
    - delay: 500ms
    - switch.turn_off: open_relay
    inverted: true
    internal: False
  # The following can be omitted
  - platform: restart
    name: ${devicename} restart

cover:
  - platform: template
    device_class: garage
    name: Garage Gate
    id: gate_opener
    lambda: |-
      if (id(open_relay).state) {
        return COVER_OPEN;
      } else {
        return COVER_CLOSED;
      }
    open_action:
      - switch.turn_on: open_relay


sensor:
  - platform: wifi_signal
    name: ${devicename} wifi signal
    update_interval: 600s

You could use time based cover for example.

Or try like this:

    on_turn_on:
    - delay: 500ms
    - switch.turn_off: open_relay

    - delay: 60s
    - cover.template.publish:
        id: gate_opener
        state: CLOSED

and remove the state lambda completely from cover.

You should just add some reed sensors to keep the door position synchronized. Add 1 at the top at the fully open position and another at the bottom dor fully closed. Once you add some feedback sensors the Cover will automatically keep track and update the state.

The problem with the way your doing it is if someone stops the door and leaves it open or if the laser sensor is triggered and it stops then opens, your door states will be completely wrong and will say closed when its actually 100% open.

Something else i noticed with your DIY RF keychain is ya, it will work but is unnecessary. A simple RF transmitter/receiver kit could have easily been used without having to destroy a keychain.

If you intend to keep the RF keychain in there, i would strongly suggest you pop the battery out of it and just hardwire it from the power supply you have easy access to right beside it.

Those coin cells are 3v nominal and you can use the 3.3v off the esp01 to power it instead.

Thanks Karosm that’s exactly what i needed and much simpler too. It works perfectly!
Poo_on_myShoeShoe you’re right about the battery I don’t know why I didn’t think of that. Sensors may be tricky though, it’s a shared gate and power may be an issue. Out of curiosity I’ll look into a RF transmitter/receiver kit, it may be complex, it’s a rolling code system and the remote thingy was less than AU$10 on ali express

There’s about no way you can control rolling code system through any other setup than what you made. Ok, you could control the fob without relays, but not without fob. Don’t waste your time/money with transmitter/receiver kit.
And sign your topic solved if you received solution for your problem.

IDK why people always jump to duplicating a rolling code system and fail to think outside the box.

Thats not what i said and not what i was suggesting. You dont have to use the factory security 2.0 RF rolling codes inorder to use RF. You only need a transmitter and a receiver at the motor and that can be bypassed. If someone is paranoid to the extent that they think they absolutely need to use something more secure than a fixed RF code, i cant imagine it would be to difficult to set up an alternating code sustem and install it on both transmitter and receiver but, its overkill in most cases because the odds someone is being targeted by someone with a Flipper or some other broad RF scanner is very unlikely.

Even if you used fixed codes, you could add additional conditions like BT, wifi presence detection so that a correct RF code alone wont be sufficient for someone to get your code and use it because they would be unaware of the unique conditions created by the owner.

Idk what you mean by “shared gate” but, if its an electric/automatic gate then by definition it uses power and that means you have access to power.

If you have something up and working, it may not be worth making a bunch of modifications that weren’t originally intended but, they are things i would atleast keep filed somewhere in memory for a time your comfortable making modifications and want to improve the original build.

Those things tend to be more common than you might think, lol.

I’m limited here as it is a rented apartment with a communal gate shared by 17 other flats. Making modifications to communal facilities will probably not endear me to the other tenants :grinning:

Oh no! I hear tenants and property managers love that and even encourage it so, go for it and if anyone asks, tell them i said it was OK!

Lol jk obviously! Good for you respecting others property! I see so many asking for instructions on modifying rentals or apartments and im like, “Uumm… bad idea Scooter!”