Continuously increase brightness on long press

Hello,

I’m new to Home assistant and am struggling with my Ikea switches and Zigbee Lights. I’m sorry if this seems pretty basic, but I’ve looked for a few solutions online, and so far I’ve been unable to achieve this behaviour.

What I want to achieve:
On a long press, I want my light to continuously increase brightness until I release the button (let’s say 10% every 500ms).

What happens at a Zigbee level when I press the button:

# Start long-pressing the button
brightness_move_up
# Stop long-pressing the button
brightness_stop

Here’s what I currently have:
Increase brightness once on a long press (no repeat):

alias: test_ikea_bureau
description: ""
trigger:
  - platform: device
    domain: mqtt
    device_id: 10c9b509fa5983eef495510c6e3eaf02
    type: action
    subtype: brightness_move_up
    discovery_id: 0x04cd15fffe31b5f5 action_brightness_move_up
condition: []
action:
  - device_id: 297000be31fa34f82b4a3526cd04f32d
    domain: light
    entity_id: light.plafonnier_bureau
    type: brightness_increase
mode: single

And this is what I’d like to achieve:

alias: test_ikea_bureau
description: ""
trigger:
  - platform: device
    domain: mqtt
    device_id: 10c9b509fa5983eef495510c6e3eaf02
    type: action
    subtype: brightness_move_up
    discovery_id: 0x04cd15fffe31b5f5 action_brightness_move_up
condition: []
action:
  - repeat:
      until:
        - platform: device
          domain: mqtt
          device_id: 10c9b509fa5983eef495510c6e3eaf02
          type: action
          subtype: brightness_stop
          discovery_id: 0x04cd15fffe31b5f5 action_brightness_stop
      sequence:
        - device_id: 297000be31fa34f82b4a3526cd04f32d
          domain: light
          entity_id: light.plafonnier_bureau
          type: brightness_increase
mode: single

Upon trying to save this last block, I get the following error:

Message malformed: Unexpected value for condition: ‘None’. Expected and, device, not, numeric_state, or, state, sun, template, time, trigger, zone @ data[‘action’][0][‘repeat’][‘until’][0]

Is there a way to provide a Device Action as a stop condition on an Until loop ? If not, is there another way to implement this automation?

Thanks!

I will reply to my own thread, but I have found a solution! It’s probably not the best implementation, but it works and uses no pluggin or extension.

What we will use:

  • A “toggle” helper (Boolean variable)
  • An automation that start the brightness_up loop
  • An automation that start the brightness_down loop
  • An automation that stop any running brightness loop

The logic:

# Initial situation
Our Boolean Variable is set to False.
# Long press brightness_up
Our brightness_up loop starts. Every 1 second, the brightness is increased, until our Boolean Variable is set to false.
# Stop pressing brightness_up
A brightness_stop signal is sent. This brightness_stop automation starts, sets our Boolean Variable to false.
The brightness_up loop stops.

The exact same logic applies to the brightness_down loop.

How-to implement:
Start by creating a Helper (Settings > Devices and Services > Helpers). Chose type “Toggle” and name it (I named mine “test_ikea_bureau_helper”).

Create the 3 following automations (Replace my devices IDs and helper with yours):

Brightness_up automation:

alias: test_ikea_bureau_up
description: This automation starts the "Brightness Up" loop
trigger:
  - platform: device
    domain: mqtt
    device_id: 10c9b509fa5983eef495510c6e3eaf02
    type: action
    subtype: brightness_move_up
    discovery_id: 0x04cd15fffe31b5f5 action_brightness_move_up
    id: brightness_up
condition:
  - condition: state
    entity_id: input_boolean.test_ikea_bureau
    state: "off"
action:
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.test_ikea_bureau
  - repeat:
      while:
        - condition: state
          entity_id: input_boolean.test_ikea_bureau
          state: "on"
      sequence:
        - device_id: 297000be31fa34f82b4a3526cd04f32d
          domain: light
          entity_id: light.plafonnier_bureau
          type: brightness_increase
        - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 0
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.test_ikea_bureau
mode: single

Brightness_down automation:

alias: test_ikea_bureau_down
description: This automation starts the "Brightness Down" loop
trigger:
  - platform: device
    domain: mqtt
    device_id: 10c9b509fa5983eef495510c6e3eaf02
    type: action
    subtype: brightness_move_down
    discovery_id: 0x04cd15fffe31b5f5 action_brightness_move_down
    id: brightness_down
condition:
  - condition: state
    entity_id: input_boolean.test_ikea_bureau
    state: "off"
action:
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.test_ikea_bureau
  - repeat:
      while:
        - condition: state
          entity_id: input_boolean.test_ikea_bureau
          state: "on"
      sequence:
        - device_id: 297000be31fa34f82b4a3526cd04f32d
          domain: light
          entity_id: light.plafonnier_bureau
          type: brightness_decrease
        - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 0
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.test_ikea_bureau
mode: single

Brightness_stop automation:

alias: test_ikea_bureau_stop
description: This automation stops any "Brightness" loop
trigger:
  - platform: device
    domain: mqtt
    device_id: 10c9b509fa5983eef495510c6e3eaf02
    type: action
    subtype: brightness_stop
    discovery_id: 0x04cd15fffe31b5f5 action_brightness_stop
condition: []
action:
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.test_ikea_bureau
mode: single

I’m still open to better implementations of this, but it does the job for now.

2 Likes

Tried this one?

1 Like

Just wanted to say thanks for that solution! Tried it and it worked great!

Thanks for the solution - one question, what should I change the discovery ID to?
The automation is not working for me and i suspect I need to change that

Hi Mark, thanks for your post but it doesn’t work yet for me. What is the “discovery_id” and what does the parameters refer to ?
Thanks

1 Like