Setting cover position in template cover actions

I’m trying to improve a template cover I have for my garage door with only one contact sensor attached. I am able to publish the door position from the contact sensor input successfully, and both the open and close actions successfully set the current_operation to opening/closing, but when opening the door, I also have a 15 second delay then it is supposed to change to open, but it is not doing that. Ultimately I want to have the actual position of the door updated based on the contact sensor after a 15 sec delay, but I can’t get the position to update outside the contact sensor publishing.

Here’s my current config:

binary_sensor:
  - platform: gpio
    name: "Contact"
    disabled_by_default: true
    device_class: garage_door
    id: contact
    pin:
      number: GPIO18
      inverted: true
    filters:
      - delayed_on: 50ms
      - settle: 1s
    on_release: #closed
      then:
        - lambda: "id(garagedoor).current_operation = CoverOperation::COVER_OPERATION_IDLE;"
        - cover.template.publish:
            id: garagedoor
            state: CLOSED
        - logger.log: "Contact released"
    on_press: #open
      then:
        # if:
        #   condition:
        #     - lambda: "return !id(garagedoor).current_operation == CoverOperation::COVER_OPERATION_OPENING;"
        #   then:
            - cover.template.publish:
                id: garagedoor
                state: OPEN
            - logger.log: "Contact pressed"

cover:
  - platform: template
    device_class: garage
    name: "Garage Door"
    id: garagedoor
    # lambda: "return id(contact).state ? COVER_OPEN : COVER_CLOSED;"
    open_action:
      - if:
          condition:
            lambda: "return !id(contact).state;"
          then:
            - logger.log: "Open action"
            - switch.turn_on: relay
            - lambda: "id(garagedoor).current_operation = CoverOperation::COVER_OPERATION_OPENING;"
            - delay: 15s
            - lambda: "id(garagedoor).current_operation = CoverOperation::COVER_OPERATION_IDLE;"
            - lambda: "id(garagedoor).position = COVER_OPEN;"
    stop_action:
      - if:
          condition:
            - lambda: "return id(garagedoor).current_operation != CoverOperation::COVER_OPERATION_IDLE;"
          then:
            - logger.log: "Stop action"
            - switch.turn_on: relay
    close_action:
      - if:
          condition:
            lambda: "return id(contact).state;"
          then:
            - logger.log: "Close action"
            - switch.turn_on: relay
            - lambda: "id(garagedoor).current_operation = CoverOperation::COVER_OPERATION_CLOSING;"
            # - delay: 15s
            # - lambda: "id(garagedoor).current_operation = CoverOperation::COVER_OPERATION_IDLE;"

So you have NO switch for open position?
And some pulsed relay?

I think you would have cleaner setup with endstop cover. You could do time based template binary sensor for the closed position.

Correct. It’s an Athom garage door opener, and I am modifying the code is shipped with, which was a simple open/close template based on the sensor.

I have tried an endstop cover, but the behavior wasn’t quite correct with only one endstop. What would it look like with a timed sensor?

Did you take a look at feedback covers? They may be a better fit (but not 100% as haven’t looked closely at your set-up). I migrated my template covers onto them a while back. Mine have a closed endstop but no open endstop. I use a time based opening.

The % open updates as it goes based on the time and if it hits the endstop it updates based on that.

If they aren’t a good fit or you really want to stick with a template cover you could look at creating a another copy binary sensor off of your endstop cover and adding a delayed_off filter of 15sec and driving states from that (or adding that filter to your existing binary sensor).

cover:
  - platform: feedback
    name: Cover
    id: cranky_cover
    device_class: window
    assumed_state: false
    open_action:
      - switch.turn_on: winopen
    open_duration:  ${open_duration}
    close_action:
      - switch.turn_on: winclose
    close_duration: ${close_duration}
    close_endstop: window_closed_endstop
    stop_action:
      - switch.turn_off: winclose
      - switch.turn_off: winopen

1 Like

I mean endstop cover setup is very simple, just two switches and relay. You could make template binary sensor for virtual closed endstop simply turning it on with 15s delay and turning it off when opening.

Its best if you have 2 endstop sensors but, you can easily set up a feedback cover and it already incorporates a “Time” configuration that you set for the amount it takes to fully open and close plus, it incorporates your single binary sensor too.