Can't figure out endless loop

Trying to copy the “Dim lights THE RIGHT WAY” tutorial, and I have a problem with the loop never ending. Can anyone spot what’s wrong here?

alias: seqrepeattest
description: seqrepeattest
trigger:
  - platform: device
    domain: mqtt
    device_id: d7be3cdd4627110879ece4b209dcabf0
    type: action
    subtype: dial_rotate_left_step
    discovery_id: 0x001788010d12e163 action_dial_rotate_left_step
    id: leftstep
condition:
  - condition: trigger
    id: leftstep
action:
  - repeat:
      while:
          - condition: trigger
            id: leftstep
      sequence:
        - service: light.turn_on
          data:
            brightness_step_pct: -5
          target:
            entity_id: light.ljosakrona
        - delay:
            milliseconds: 200
mode: restart

You need to change the while's condition to monitor the device’s current value, not the value it had when it triggered the automation.

The way you have it now, the automation triggers when it detects dial_rotate_left_step and proceeds to repeatedly decrement the light’s brightness while the trigger.id is leftstep which it does endlessly because the automation is designed to trigger for no other value than dial_rotate_left_step.

1 Like

Thanks for the pointer, still not getting it though. I’ve added another trigger, but still looping endlessly, pretty much copying directly from another user in this thread who reported his code working

alias: Borðstofa Dimmer
description: Borðstofa Dimmer
trigger:
  - platform: device
    domain: mqtt
    device_id: 9a48f8c1fa36ad56bdbf4b5810a3e5b0
    type: action
    subtype: button_1_hold
    discovery_id: 0x001788010d12c71a action_button_1_hold
    id: hold1
  - platform: device
    domain: mqtt
    device_id: 9a48f8c1fa36ad56bdbf4b5810a3e5b0
    type: action
    subtype: button_3_hold
    discovery_id: 0x001788010d12c71a action_button_3_hold
    id: hold3
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: hold1
        sequence:
          - repeat:
              while:
                - condition: trigger
                  id: hold1
              sequence:
                - service: light.turn_on
                  data:
                    brightness_step: 10
                  target:
                    entity_id: light.ljosakrona
                - delay:
                    milliseconds: 200
      - conditions:
          - condition: trigger
            id: hold3
        sequence:
          - repeat:
              while:
                - condition: trigger
                  id: hold3
              sequence:
                - service: light.turn_on
                  data:
                    brightness_step: -10
                  target:
                    entity_id: light.ljoskrona
                - delay:
                    milliseconds: 200
mode: restart

The first example you posted isn’t like the one in the other topic because it employs a condition that effectively prevents any other kind of button press from interrupting the repeat (and so it loops endlessly).

I also know why the second example loops endlessly. However I see that you have already posted in the topic where you got the example so, to avoid the duplication of topics (cross-posting is discouraged), I’ll let the author of the example help you sort it out.

I would appreciate if you share your information since the other thread seems to be dead.

I don’t have the means to test the following automation so it may require further adjustments.

It listens for two types of button events: hold and release.

  • When hold is detected, it increases or decreases the light’s brightness, depending on which button was pressed.

  • When release is detected, it stops increasing/decreasing the light’s brightness.

alias: Borðstofa Dimmer
description: Borðstofa Dimmer
trigger:
  - platform: device
    domain: mqtt
    device_id: 9a48f8c1fa36ad56bdbf4b5810a3e5b0
    type: action
    subtype: button_1_hold
    discovery_id: 0x001788010d12c71a action_button_1_hold
  - platform: device
    domain: mqtt
    device_id: 9a48f8c1fa36ad56bdbf4b5810a3e5b0
    type: action
    subtype: button_1_release
    discovery_id: 0x001788010d12c71a action_button_1_release
  - platform: device
    domain: mqtt
    device_id: 9a48f8c1fa36ad56bdbf4b5810a3e5b0
    type: action
    subtype: button_3_hold
    discovery_id: 0x001788010d12c71a action_button_3_hold
  - platform: device
    domain: mqtt
    device_id: 9a48f8c1fa36ad56bdbf4b5810a3e5b0
    type: action
    subtype: button_3_release
    discovery_id: 0x001788010d12c71a action_button_3_release
condition: []
action:
  - repeat:
      until: "{{ 'release' in trigger.payload }}"
      sequence:
        - service: light.turn_on
          data:
            brightness_step: "{{ 10 if trigger.payload == 'button_1_hold' else -10 }}"
          target:
            entity_id: light.ljosakrona
        - delay:
            milliseconds: 200
mode: restart

Thank you kindly for the pointers, this makes sense and I think I can take it from here!

Yup this absolutely did the trick, thank you very much, also much cleaner syntax.

Is this possible if there is no explicit message accompanied with stopping the action? For example for a rotating knob that only sends a rotate_right/left_step?

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.


I suggest looking at how blueprints implement it, for example this one:

Thanks again, not quite sure what in that automation is relevant. Should I repeat until the action in the device’s state is empty or null?