Dim/Brighten light on button Long Press

Hello everyone,

here i am again looking for some help with an automation i am trying to build and although i have seen many similar posts, i was not able to make it work for my set up. I have an Aqara Mini Switch that supports long press hold and long press release and i am trying to use the feature to dim or brighten the light in the WC. So the intention is:

When i hold the button, the brightness increases smoothly. Here is a screenshot of the aqara button functions:

The light i have in the WC supports increase / decrease brightness but some how i need to make it work as if it is increasing or decreasing the brightness for as long as i hold the button. I thought to use the Repeat Until function in automations but some how it is not working for me.

Here is a screenshot of the light functions:

And here is the automation i tried to build:

alias: WC Light Brightness
description: ''
trigger:
  - device_id: d49305d0c0a8eeb4e553f4a415fe03b2
    domain: zha
    platform: device
    type: remote_button_long_press
    subtype: remote_button_long_press
condition: []
action:
  - repeat:
      until:
        - condition: state
          entity_id: light.wc_light
          state: '255'
          attribute: brightness
      sequence:
        - device_id: 67a622f167413951530a00b4c623b8c1
          domain: light
          entity_id: light.wc_light
          type: brightness_increase
mode: single

Could i please ask for your help to make it work? Also, in case the brightness is at 100% the next long press should start decreasing the brightness.

Thank you very much
Kind Regards
M

2 Likes

Status update. I figured out how to make it understand if to increase or decrease the brightness using an input_boolean. So, i created an input_boolean and an automation that toggles the state of the boolean on the button long press. Now when i long press the button first time, the boolean changes state to on, and when i press again it changes to off.

So based on that, i created another automation that either increases or decreases the brightness based on the state of the boolean. Here it is:

alias: WC_Brightness
description: ''
trigger:
  - device_id: d49305d0c0a8eeb4e553f4a415fe03b2
    domain: zha
    platform: device
    type: remote_button_long_press
    subtype: remote_button_long_press
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: input_boolean.wc_toggle
            state: 'on'
        sequence:
          - device_id: 67a622f167413951530a00b4c623b8c1
            domain: light
            entity_id: light.wc_light
            type: brightness_increase
      - conditions:
          - condition: state
            entity_id: input_boolean.wc_toggle
            state: 'off'
        sequence:
          - device_id: 67a622f167413951530a00b4c623b8c1
            domain: light
            entity_id: light.wc_light
            type: brightness_decrease
    default: []
mode: restart

With the above, it decreases or increases the brighness once. I haven’t figure out how to repeat it until something happens. Perhaps you can help me here.

Thank you very much
M

2 Likes

Repeat while action will probably work.

So repeat while until your remote sends the release command.

When I looked in the GUI I could not do that on my devices from IKEA. I’m limited to the battery in repeat while. Perhaps yours is different.
If not then you will need to read the zha_event for the release command

I tried last night for a couple of hours and this is exactly the problem. I am also limited in the battery state of the button. I have never used so far the zha_event option. Could you please redirect me to an example?

Thank you very much
Kind Regards
M

Do this:

Then press the button and you should see the communication from the remote.
Most likely there will be a “command”: “long_press”, then when you release a “command”: “release”.

Copy paste the data here and we can probably get it to work

1 Like

Thank you again for the quick reply. Here is the data from the developer tools:

{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "00:15:8d:00:06:d4:c8:64",
        "unique_id": "00:15:8d:00:06:d4:c8:64:1:0x0012",
        "device_id": "d49305d0c0a8eeb4e553f4a415fe03b2",
        "endpoint_id": 1,
        "cluster_id": 18,
        "command": "release",
        "args": {
            "value": 255
        }
    },
    "origin": "LOCAL",
    "time_fired": "2022-01-03T09:37:46.624210+00:00",
    "context": {
        "id": "f6e931a3186eb41e2a48b6e95914c43a",
        "parent_id": null,
        "user_id": null
    }
}

huh… In the repeat you can’t make it repeat while events.
I guess I can’t help more now.

I’m sure this can be done with a variable or with a helper that is set with the events.
This is why I never bother with HA automations when doing something more than flipping a switch or similar.

Thank you for giving it a try!

Here is the yaml for triggering on the release:

trigger:
  - platform: event
    event_type: zha_event
    event_data:
      data:
        device_ieee: 00:15:8d:00:06:d4:c8:64
        unique_id: 00:15:8d:00:06:d4:c8:64:1:0x0012
        device_id: d49305d0c0a8eeb4e553f4a415fe03b2
        endpoint_id: 1
        cluster_id: 18
        command: release

if all these values are constant. if not then just delete the parts that change. I believe as long as you keep device_id and command release it should work.

1 Like

Thanks for the code.
Since the button supports release state i don’t need to use the zha_event. I can select it from the GUI but only as a trigger. The intention was to select it as a repeat - until section to stop a loop.

I think i am going to quit as i don’t see this possible… Pity, it should be something that could be there by default. I believe that the button manufacturers include the hold/release features for such reasons (increase / decrease brightness).

I have found a post that does it with node-red but i don’t want to go this way. Thank you very much for the help though, really appreciate it!

I understand that. I just figured if you some how found a way then this code could be useful for you.

If you change your mind then I have sequences how to do it since I use similar things in Node red.

I just realized something.

Sorry for this but I’m not at the computer anymore so this is a quick GUI automation on my phone.
You can probably use the trigger id.

trigger:
  - device_id: 770b0eca92df31064acad1ab9a76ec51
    domain: zha
    platform: device
    type: remote_button_long_release
    subtype: dim_up
    id: release
  - device_id: 770b0eca92df31064acad1ab9a76ec51
    domain: zha
    platform: device
    type: remote_button_long_press
    subtype: dim_up
    id: hold 
condition: []
action:
  - repeat:
      while:
        - condition: trigger
          id: hold
      sequence:
        - service: light.turn_on
          target:
            entity_id: light.davids_lampa

So I created a trigger id for both hold and release (not sure release is needed).
But in repeat I use condition trigger id “hold”

Thank you very much.

.

I have tried this last night however the result is that the automation never stops. It keeps increasing the brightness to 100% and if you turn the light off, it turns it on again and raises the brightness to 100%.

What mode are you running that in?
If that is in mode: repeat (given that is what you posted before) then I could see that happen as all automations are queued.

If you run it in single mode then all automations that occur when the first is running should be blocked from running.

I was running it on single but i have tried restart and queued and parallel with no results.

A shot in the dark… but perhaps when not release?

action:
  - repeat:
      while:
        - condition: not
          conditions:
            - condition: trigger
              id: release

I think what we need to do here is to implement another helper. An Input_Slider. The idea is, that the long press, increases the number of the slider and then with another automation (if possible, the brightness is equal to the slider number).

This can be then further extended with another condition that if the slider is number is >50 then the brightness should increase but if <50 the brightness should decrease.

I am going to give this a try

1 Like

Status Update… I was able to create an input_slider and link it the light brightness. I was even able to add conditions so if slider is above 50 it should increase while if below 50 it should decrease.

The problem again is the event of stopping the slider from increasing/decreasing. So, the button registers the long press, but there is no way to stop changing the brightness on release because in the repeat - until condition there is no “event” option.

And now i am officially quitting… I am going to do it the old way. Create some scenes with different brightness and shuffle them with the button one after the other.

Thanks for the help
M

Sure you’re not going to give it a try with Node red?
As I said, I have 95% of what you need ready made, you just need to add your entities/devices