Ignoring repeating states in an automation

I have a garage door that reports the following “trigger” sequence when opening:
closed opening opening ... opening open
A similar thing happens when closing:
open closing closing ... closing closed

Those “opening” and “closing” triggers repeat many times in the 10-12 seconds that the door is in motion.

I initially tried an automation that triggers on any change and did 4 options, one for each trigger type. This resulted in the last triggered action being the one for “opening” (or “closing”), which happened many times, but missing the end state entirely. I figured that maybe the automation was bogged down with all the transition triggers that it misses the final “steady state” one.

So I changed the “opening” one to detect if the previous trigger was “closed” which should only happen once. Unfortunately, now the “the opening” part always seems to get ignored.

Not sure what’s wrong - maybe the template is not correct?
Or I’m approaching this entirely the wrong way?

Here’s my test automation, with just an “opening” option included for now to test the idea.

alias: Garage Door1 Door Status
description: Sends an MQTT msg when door status changes
trigger:
  - platform: state
    entity_id:
      - cover.ratgdov25i_f39307_door
condition: []
action:
  - service: mqtt.publish
    metadata: {}
    data:
      qos: 0
      topic: stat/Garage-Door1/door
      payload_template: "{{ states('cover.ratgdov25i_f39307_door') }}"
  - choose:
      - conditions:
          - condition: state
            entity_id: cover.ratgdov25i_f39307_door
            state: closed
            for:
              hours: 0
              minutes: 0
              seconds: 0
        sequence:
          - service: mqtt.publish
            data:
              qos: 0
              topic: cmnd/GarageDoor1State/POWER
              payload: "0"
      - conditions:
          - condition: template
            value_template: >-
              {{ trigger.from_state.state == 'closed' and trigger.to_state.state
              == 'opening' }}"
        sequence:
          - service: mqtt.publish
            data:
              topic: cmnd/GarageDoor1State/POWER
              payload: "1"
      - conditions:
          - condition: state
            entity_id: cover.ratgdov25i_f39307_door
            state: open
            for:
              hours: 0
              minutes: 0
              seconds: 0
        sequence:
          - service: mqtt.publish
            data:
              qos: 0
              topic: cmnd/GarageDoor1State/POWER
              payload: "2"
mode: single

Maybe there is extra states you do not see, because it goes too fast.

Try the event tab in the developer tools and then listen for the events related to the garage door.
You might have to listen to * if you do not know what filter to use to get a better capture.
The * will capture a lot, so maybe get the first event and then see if you can filter it better.

Tried that. I see several events where the state was old: closing to new:closing, and then followed by a old:closing, new:closed.
I didn’t capture a old:open, new:closing - think I ran out of space for the events display.
But only the closing->closed seems to have run in the automation.

Capture again until you catch it.
It is the eventsHA react to, so you need to know what they are to make it work.

I’ll try again, but I’m pretty sure I know what they are. It’s a cover, so “open”, “closed”, “opening”, “closing” are the states I’m looking for in the triggers. I’m seen all of these, but haven’t actually seen the “closed”->“opening” transition yet.

I’m definitely getting all the states I’m looking for. But I think that the flood of “opening” and “closing” repeating states is somehow overwhelming the automation. That sounds odd to me, but I decided to take an apporach similar to that suggested in other posts - use input_boolean helpers, one for opening and one for closing, to indicate movement. This seems to work well (as far as I can tell so far).

Here’s the final automation:

alias: Garage Door 2 Status
description: Sends an MQTT msg when door status changes
trigger:
  - platform: state
    entity_id:
      - cover.ratgdov25i_f39311_door
condition: []
action:
  - service: mqtt.publish
    metadata: {}
    data:
      qos: 0
      topic: stat/Garage-Door2/door
      payload_template: "{{ states('cover.ratgdov25i_f39311_door') }}"
  - choose:
      - conditions:
          - condition: state
            entity_id: cover.ratgdov25i_f39311_door
            state: closed
            for:
              hours: 0
              minutes: 0
              seconds: 0
        sequence:
          - service: input_boolean.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.garage_door_2_closing
          - service: mqtt.publish
            data:
              qos: 0
              topic: cmnd/GarageDoor2State/POWER
              payload: "0"
      - conditions:
          - condition: state
            entity_id: cover.ratgdov25i_f39311_door
            state: closing
          - condition: state
            entity_id: input_boolean.garage_door_2_closing
            state: "off"
        sequence:
          - service: input_boolean.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.garage_door_2_closing
          - service: mqtt.publish
            data:
              topic: cmnd/GarageDoor2State/POWER
              payload: "1"
      - conditions:
          - condition: state
            entity_id: cover.ratgdov25i_f39311_door
            state: open
            for:
              hours: 0
              minutes: 0
              seconds: 0
        sequence:
          - service: input_boolean.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.garage_door_2_opening
          - service: mqtt.publish
            data:
              qos: 0
              topic: cmnd/GarageDoor2State/POWER
              payload: "2"
      - conditions:
          - condition: state
            entity_id: cover.ratgdov25i_f39311_door
            state: opening
          - condition: state
            entity_id: input_boolean.garage_door_2_opening
            state: "off"
        sequence:
          - service: input_boolean.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.garage_door_2_opening
          - service: mqtt.publish
            data:
              topic: cmnd/GarageDoor2State/POWER
              payload: "3"
mode: single