Dim/Brighten light on button Long Press

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

I am running Home assistant on an old Intel NUC via Virtual Box. Since it is using shared resources with other server applications i run on the NUC, such as PLEX server, FTP server, XAMPP (apache etc) i would like to keep it as light as possible.

This is the reason i wouldn’t go to the node red as i believe that will chew up recourses and ultimately slow down the entire set up.

I can back up my virtual machine to a file (that can be deployed again) and give it a try.

If an automation runs in HA or in Node red should not make much difference. The idle of Node red on my Pi4 is:

I assume, when it’s running an automation it will be as much of a load as HA.
Also, making an automation in HA that needs more variables, helpers and steps seems counter intuitive in my opinion if load/performance is the goal.
But I don’t know for sure.

I am backing up my set up and installing Note Red. There only one way to find out! :slight_smile:

Here is a flow you can try.
It’s untested since I’m not home and I don’t have a one button remote.

[{"id":"d1e80f24c1404c45","type":"api-call-service","z":"a787a77.9c16458","name":"","server":"4bbca37b.1700ec","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.kokslampa","data":"{\t    \"brightness\": msg.data.attributes.brightness+15\t}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2430,"y":1200,"wires":[["262a5c1a0ab5d636"]]},{"id":"670fb406fbd06439","type":"api-current-state","z":"a787a77.9c16458","name":"","server":"4bbca37b.1700ec","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.kokslampa","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":2190,"y":1200,"wires":[["d1e80f24c1404c45"]]},{"id":"262a5c1a0ab5d636","type":"delay","z":"a787a77.9c16458","name":"","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":2630,"y":1200,"wires":[["8bda7d028cc01905"]]},{"id":"31edfd71c5043ac7","type":"change","z":"a787a77.9c16458","name":"","rules":[{"t":"set","p":"hold_btn","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1690,"y":1240,"wires":[["7e486ad0a5600a61"]]},{"id":"8bda7d028cc01905","type":"switch","z":"a787a77.9c16458","name":"","property":"hold_btn","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":2390,"y":1120,"wires":[["670fb406fbd06439"]]},{"id":"a0b29eada06560bd","type":"change","z":"a787a77.9c16458","name":"","rules":[{"t":"set","p":"hold_btn","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1730,"y":1180,"wires":[[]]},{"id":"570b6729d783eb93","type":"ha-device","z":"a787a77.9c16458","name":"Hold down","server":"4bbca37b.1700ec","version":0,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"inputs":0,"deviceType":"trigger","device":"770b0eca92df31064acad1ab9a76ec51","event":{"device_id":"770b0eca92df31064acad1ab9a76ec51","domain":"zha","platform":"device","type":"remote_button_long_press","subtype":"dim_down"},"capabilities":[],"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":1500,"y":1240,"wires":[["31edfd71c5043ac7"]]},{"id":"898b9f228a3779cf","type":"ha-device","z":"a787a77.9c16458","name":"Hold down release","server":"4bbca37b.1700ec","version":0,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"inputs":0,"deviceType":"trigger","device":"770b0eca92df31064acad1ab9a76ec51","event":{"device_id":"770b0eca92df31064acad1ab9a76ec51","domain":"zha","platform":"device","type":"remote_button_long_release","subtype":"dim_down"},"capabilities":[],"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":1530,"y":1180,"wires":[["a0b29eada06560bd"]]},{"id":"7e486ad0a5600a61","type":"switch","z":"a787a77.9c16458","name":"","property":"dim_up_down","propertyType":"flow","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1890,"y":1240,"wires":[["670fb406fbd06439","ea2d0a30f1cc1a6f"],["a5b4c8483fefb419","d2400292384d0f84"]]},{"id":"ea2d0a30f1cc1a6f","type":"change","z":"a787a77.9c16458","name":"","rules":[{"t":"set","p":"dim_up_down","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":2060,"y":1100,"wires":[[]]},{"id":"a5b4c8483fefb419","type":"change","z":"a787a77.9c16458","name":"","rules":[{"t":"set","p":"dim_up_down","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":2060,"y":1400,"wires":[[]]},{"id":"d2400292384d0f84","type":"api-current-state","z":"a787a77.9c16458","name":"","server":"4bbca37b.1700ec","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.kokslampa","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":2190,"y":1280,"wires":[["cb6b78e7e1319641"]]},{"id":"43d638cefe4dd9bc","type":"switch","z":"a787a77.9c16458","name":"","property":"hold_btn","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":2390,"y":1360,"wires":[["d2400292384d0f84"]]},{"id":"cb6b78e7e1319641","type":"api-call-service","z":"a787a77.9c16458","name":"","server":"4bbca37b.1700ec","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.kokslampa","data":"{\t    \"brightness\": msg.data.attributes.brightness-15\t}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":2430,"y":1280,"wires":[["dbb6714f9cf7f5f1"]]},{"id":"dbb6714f9cf7f5f1","type":"delay","z":"a787a77.9c16458","name":"","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":2630,"y":1280,"wires":[["43d638cefe4dd9bc"]]},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

It could probably have been made simpler/smaller but this is what I came up with remotly.

The nodes that is marked with red is the ones you need to put some attention to.
You need to replace the device with your device long press/release command and the light entity

This dims up/down every other time you press it.

3 Likes

Just using a tweak of your logic above to try and get a button dimming and brightening my blind and got a bit of an odd thing happening… it works, but only twice…

[{"id":"e8e6290c0de09c90","type":"server-state-changed","z":"59430083fba16f20","name":"Study Light Switch","server":"3aa13fed.bf745","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.study_light_switch_action","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":150,"y":660,"wires":[["6cc9216855f24d53","1371276ecd430ab4"]]},{"id":"6cc9216855f24d53","type":"switch","z":"59430083fba16f20","name":"Hold Actions","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"left_top_hold","vt":"str"},{"t":"eq","v":"left_bottom_hold","vt":"str"},{"t":"eq","v":"right_top_hold","vt":"str"},{"t":"eq","v":"right_bottom_hold","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":350,"y":660,"wires":[["df44b2fd95736b35"],["1ecb47afdecdaddf"],["d8315b8b3acdde08"],["6a8878273cf61135"]]},{"id":"df44b2fd95736b35","type":"change","z":"59430083fba16f20","name":"","rules":[{"t":"set","p":"hold_btn_lt","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":600,"wires":[[]]},{"id":"1ecb47afdecdaddf","type":"change","z":"59430083fba16f20","name":"","rules":[{"t":"set","p":"hold_btn_lb","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":640,"wires":[[]]},{"id":"d8315b8b3acdde08","type":"change","z":"59430083fba16f20","name":"","rules":[{"t":"set","p":"hold_btn_rt","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":680,"wires":[["d7b539ce91a0c835"]]},{"id":"6a8878273cf61135","type":"change","z":"59430083fba16f20","name":"","rules":[{"t":"set","p":"hold_btn_rb","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":720,"wires":[["8d0654457eadd171"]]},{"id":"5d4cd4124797a743","type":"api-call-service","z":"59430083fba16f20","name":"","server":"3aa13fed.bf745","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.study_bulb"],"data":"{     \"brightness\": msg.data.attributes.brightness+15 }","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":890,"y":720,"wires":[["95595c2a7ac6add5"]]},{"id":"acb0e4c1adef50af","type":"switch","z":"59430083fba16f20","name":"","property":"hold_btn_rt","propertyType":"flow","rules":[{"t":"eq","v":"true","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":910,"y":640,"wires":[["d7b539ce91a0c835"]]},{"id":"95595c2a7ac6add5","type":"delay","z":"59430083fba16f20","name":"","pauseType":"delay","timeout":"50","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1070,"y":720,"wires":[["acb0e4c1adef50af"]]},{"id":"d7b539ce91a0c835","type":"api-current-state","z":"59430083fba16f20","name":"","server":"3aa13fed.bf745","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.study_bulb","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":785,"y":720,"wires":[["5d4cd4124797a743"]],"l":false},{"id":"1371276ecd430ab4","type":"debug","z":"59430083fba16f20","name":"debug 24","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":340,"y":580,"wires":[]},{"id":"8d0654457eadd171","type":"api-current-state","z":"59430083fba16f20","name":"","server":"3aa13fed.bf745","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.study_bulb","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":785,"y":780,"wires":[["4bb53e34ae3dfbf0"]],"l":false},{"id":"4bb53e34ae3dfbf0","type":"api-call-service","z":"59430083fba16f20","name":"","server":"3aa13fed.bf745","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.study_bulb"],"data":"{     \"brightness\": msg.data.attributes.brightness-15 }","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":890,"y":780,"wires":[["d001348625689d84"]]},{"id":"d001348625689d84","type":"delay","z":"59430083fba16f20","name":"","pauseType":"delay","timeout":"50","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1070,"y":780,"wires":[["59b6a2eea7648bd0"]]},{"id":"59b6a2eea7648bd0","type":"switch","z":"59430083fba16f20","name":"","property":"hold_btn_rb","propertyType":"flow","rules":[{"t":"eq","v":"true","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":970,"y":860,"wires":[["8d0654457eadd171"]]},{"id":"3aa13fed.bf745","type":"server","name":"Home Assistant","version":4,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m"}]

I suspect it might be because on my button, for some reason holding it (or any action actually) give a blank state response immediately after the actual state change
image

Is there any way to ignore this?
Is this flow still the best way of doing this?