I want to dim X% with each buttonpress

Hello

I have a couple of Aqara wireless smart switches (1-4 presses) and my current setup is using 1 push of the button to turn it on on a certain effect.

I want to take the current value of brightness on the ledlight and dim up (lets say 10% with each step) with 2 push and dim down (10%) with 3 push

Im lost when it comes to how I should do the above…

Would greatly appriciate the help.

[{"id":"24b6260c.8473ea","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"f514eea5.9b43c","type":"server-events","z":"24b6260c.8473ea","name":"","server":"ee6480c8.d1c6b","event_type":"deconz_event","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":140,"y":160,"wires":[["7b63e41a.bfa91c"]]},{"id":"7b63e41a.bfa91c","type":"switch","z":"24b6260c.8473ea","name":"Aqara Smart switch","property":"payload.event.id","propertyType":"msg","rules":[{"t":"eq","v":"smart_switch_5","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":410,"y":160,"wires":[["36bcbd72.612512"]]},{"id":"36bcbd72.612512","type":"switch","z":"24b6260c.8473ea","name":"1-4 pusches on Button","property":"payload.event.event","propertyType":"msg","rules":[{"t":"eq","v":"1002","vt":"str"},{"t":"eq","v":"1004","vt":"str"},{"t":"eq","v":"1005","vt":"str"},{"t":"eq","v":"1006","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":680,"y":160,"wires":[["5e78bc27.f10e94"],[],[],[]]},{"id":"5e78bc27.f10e94","type":"api-call-service","z":"24b6260c.8473ea","name":"Led with effect","server":"ee6480c8.d1c6b","version":1,"debugenabled":false,"service_domain":"light","service":"toggle","entityId":"light.ledutekok","data":"{\"effect\":\"2\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":930,"y":60,"wires":[["f25d1935.3ffb08"]]},{"id":"f25d1935.3ffb08","type":"debug","z":"24b6260c.8473ea","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1170,"y":60,"wires":[]},{"id":"ee6480c8.d1c6b","type":"server","z":"","name":"Home Assistant"}]

After some searching (over and over and over again) I found something and made it to work for me.

[{"id":"24b6260c.8473ea","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"f514eea5.9b43c","type":"server-events","z":"24b6260c.8473ea","name":"","server":"ee6480c8.d1c6b","event_type":"deconz_event","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":140,"y":200,"wires":[["7b63e41a.bfa91c"]]},{"id":"7b63e41a.bfa91c","type":"switch","z":"24b6260c.8473ea","name":"Aqara Wireless Smart Switch","property":"payload.event.id","propertyType":"msg","rules":[{"t":"eq","v":"smart_switch_5","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":180,"y":280,"wires":[["36bcbd72.612512"]]},{"id":"36bcbd72.612512","type":"switch","z":"24b6260c.8473ea","name":"1-4 pushes on Button","property":"payload.event.event","propertyType":"msg","rules":[{"t":"eq","v":"1002","vt":"str"},{"t":"eq","v":"1004","vt":"str"},{"t":"eq","v":"1005","vt":"str"},{"t":"eq","v":"1006","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":480,"y":240,"wires":[["5e78bc27.f10e94"],["31f3c620.98e36a"],["b236a22c.c796d"],[]]},{"id":"5e78bc27.f10e94","type":"api-call-service","z":"24b6260c.8473ea","name":"Led ON with effect","server":"ee6480c8.d1c6b","version":1,"debugenabled":false,"service_domain":"light","service":"toggle","entityId":"light.ledutekok","data":"{\"effect\":\"2\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":770,"y":120,"wires":[[]]},{"id":"b4242571.082008","type":"function","z":"24b6260c.8473ea","name":"increase brightness","func":"varBright = msg.data.attributes.brightness;\nvarEntity = msg.data.entity_id;\nif (varBright < 200) {varBrightness = varBright + 50}\nelse {varBrightness = 254}\nmsg.payload = {\"entity_id\":varEntity}\nmsg.payload.data = {\"brightness\":varBrightness}\nreturn msg;","outputs":1,"noerr":0,"x":1010,"y":200,"wires":[["ce0a80ae.446b1"]]},{"id":"ce0a80ae.446b1","type":"api-call-service","z":"24b6260c.8473ea","name":"led","server":"ee6480c8.d1c6b","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"{{payload.entity_id}}","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1230,"y":240,"wires":[[]]},{"id":"31f3c620.98e36a","type":"api-current-state","z":"24b6260c.8473ea","name":"led","server":"ee6480c8.d1c6b","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.ledutekok","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":730,"y":200,"wires":[["b4242571.082008"],[]]},{"id":"b236a22c.c796d","type":"api-current-state","z":"24b6260c.8473ea","name":"led","server":"ee6480c8.d1c6b","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.ledutekok","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":730,"y":280,"wires":[["ce4501ef.3666a"],[]]},{"id":"ce4501ef.3666a","type":"function","z":"24b6260c.8473ea","name":"decrease brightness","func":"varBright = msg.data.attributes.brightness;\nvarEntity = msg.data.entity_id;\nif (varBright > 50) {varBrightness = varBright - 50}\nelse {varBrightness = 1}\nmsg.payload = {\"entity_id\":varEntity}\nmsg.payload.data = {\"brightness\":varBrightness}\nreturn msg;","outputs":1,"noerr":0,"x":1020,"y":280,"wires":[["ce0a80ae.446b1"]]},{"id":"ee6480c8.d1c6b","type":"server","z":"","name":"Home Assistant"}]
1 Like

This is from the cookbook in the docs:

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/cookbook/jsonata.html#increase-lights-brightness-with-remote

and to dim

{
  "brightness_pct": $max([$entities("light.ledutekok").attributes.brightness - 10, 0]),
  "effect": 2
}

I’ve still got this bookmarked, as I’m get to do it.

But this should help I hope.
https://notenoughtech.com/home-automation/nodered-home-automation/xiaomi-aqara-switch-in-nodered/