How to repeat an action until another (specific) device trigger is received

Tags: #<Tag:0x00007fc4088e90f8> #<Tag:0x00007fc4088e8d38> #<Tag:0x00007fc4088e8798>

I am trying to mimic the behaviour of a TRÅDFRI dimmer where you need to hold ON or OFF to increase or decrease the brightness.
When you hold ON zigbe2mqtt will publish one brightness_up action and when released, released (or something like that…
What I want is to gradually increase the brightness until the released action is triggered.

Has anyone done that?

I am quite new to Home Assistant and I am struggling a little bit what’s the best way to do this…

you could set up an automation and use the “repeat-until” function that should do what you want.

Sadly the exit condition does not include the actions of the switch as an option

don’t use a device condition. use a state condition.

Thanks, that shows the action of the button now and I can add the event of brightness_stop but it actually doesn’t stop iterating when that event is receveived…

This is how my automation looks like. Do you something wrong? Thanks!

alias: New Automation
description: ''
trigger:
  - platform: device
    domain: mqtt
    device_id: 5403d6e0191011eb81f6cb70b8727afa
    type: action
    subtype: brightness_move_up
    discovery_id: 0xccccccfffeeeba5b action_brightness_move_up
condition: []
action:
  - repeat:
      until:
        - condition: template
          value_template: >-
            {{ is_state('sensor.0xccccccfffeeeba5b_action', 'brightness_stop')
            }}
      sequence:
        - type: brightness_increase
          device_id: 16f515bd14a811ebab63d3c040acd2ee
          entity_id: light.yeelight_color_0x0000000007f17283
          domain: light
        - delay: '0.75'
mode: single

are you sure that’s the state of the entity and not an attribute?

Sadly I am not really sure as I still don’t fully understand the data model behind devices in Home Assistant.

This is what I see…

and when I select XXXXX_action I have these as Attributes:

Edit: After restarting the server, now I also see “action” as an Attribute, which I guess is what I am looking for… But still doesn’t beahve as I expect.
This “brightness_stop” only lasts some milliseconds, is it possible that the automation is missing it?

look in the deveopers tools-> states list for your sensor (sensor.0xccccccfffeeeba5b_action). then see if the state changes to “brightness_stop” when you release the button.

it’s possible but I kind of doubt it. Is there any way to lengthen that signal?

Hi @sergimola, probably this is what you are looking for. I just used it by myself with some modifications and it works just fine. Hope it helps.

1 Like

That was it @MacJawa! Thanks, it was exactly what I needed…
I had to change the triggers (I don’t have a zwave dimmer and I don’t know if that “Scene” thing is something from zwave, but still I managed to make it work with the triggers I already knew from my dimmer.

Link in not working anymore. Can you post some resulting example please?

1 Like

Agree, I am looking for something similar but the link in the solution doesn’t work. I want to increase brightness of my bulb until brightness_up_release even comes.

Actually, made it working. This is from my example:

trigger:
- platform: device
  domain: mqtt
  device_id: !input 'remote'
  type: action
  subtype: brightness_up_hold
  discovery_id: 0x804b50fffe82fb13 action_brightness_up_hold
  id: "_brightness_up_hold"
- platform: device
  domain: mqtt
  device_id: !input 'remote'
  type: action
  subtype: brightness_up_release
  discovery_id: 0x804b50fffe82fb13 action_brightness_up_release
  id: "_brightness_up_release"
action:
- variables:
    command: '{{ trigger.payload }}'
- choose:
  - conditions:
      - "{{ command == 'brightness_up_hold' }}"
    sequence:
      - repeat:
          until:
            - condition: trigger
              id: "_brightness_up_release"
          sequence:
            - service: light.turn_on
              data:
                brightness_step_pct: 10
                transition: 1
              target: !input light
            - delay: '1'

Hi Kotrfa, I’m trying to do the same thing but decrease off a button. for some reason the traces seems to indicate that my automation appears to run two instances of the thing automation, 1 for the long press and then a second for the release, which means my light just keeps turning down.
Can you see anything in this YAML that jumps out as incorrect?

id: '1628102794007'
alias: test light decrease
description: ''
trigger:
  - device_id: 8621b4f2fce548a49da1d754a2c41bcb
    domain: zha
    platform: device
    type: remote_button_long_press
    subtype: button
    id: '1'
  - device_id: 8621b4f2fce548a49da1d754a2c41bcb
    domain: zha
    platform: device
    type: remote_button_long_release
    subtype: button
    id: '2'
condition: []
action:
  - repeat:
      until:
        - condition: trigger
          id: '2'
      sequence:
        - device_id: 3f7189b028a7f5b5007604f8ce44fa08
          domain: light
          entity_id: light.computer_room
          type: brightness_decrease
        - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 0
mode: single

can you use a codeblock to format the yaml correctly? I can’t make much sense out of it

Cheers, I can see what you were talking about

Well, I have the repeat part :thinking: . Is that missing on purpose?

1 Like

Just found out that is was the mode, I thought triggers could pass a message to a running automation, my bad.
Needed to change the mode to restart. (thanks 123)

Thanks for having a look