Philips Button State

Hi everyone!!!

I have a Philips Hue with a couple of bulbs installed and Huemagic in NodeRed.

I want to control the bulbs with a button that knows what "state" the bulb is in and then activate (true / false) depending on the state of the bulb.

I explain;

The light works as true (on) or false (off). This needs to be verified. The "hue light" node sends the state of the bulb.
Then I have a light button that will always send true.
Depending on the current state of the light, I want the button to activate otherwise.

Check the light status -> Light: OFF -> Press_button: True -> Light: On
Check the light status -> LightOn -> Press_button: True -> Light Off

Has anyone worked with this?

Thank you.

Greetings

Hi!!!

I have been doing several tests.

I took the @davidcgu example and set it to enable / disable the bulb or group of bulbs. This is done correctly, but I still have problems with the state of the bulb.

Any idea why the button does not change color and icon depending on the state returned by the bulb?

Grateful in advance and sorry for being such a rookie.

[{"id":"497d3328.acf7dc","type":"tab","label":"Hue","disabled":false,"info":""},{"id":"b0c184da.7839f8","type":"function","z":"497d3328.acf7dc","name":"if is on","func":"msg.color = \"black\";\nmsg.background = \"#EF2F4F\";\nmsg.text = \"TURN OFF\";\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":240,"wires":[["14cf5db5.4b0d92"]]},{"id":"7e21507c.e6f65","type":"function","z":"497d3328.acf7dc","name":"if its off","func":"msg.color = \"black\";\nmsg.background = \"#B4EEB4\";\nmsg.text = \"TURN ON\";\nreturn msg;","outputs":1,"noerr":0,"x":480,"y":300,"wires":[["14cf5db5.4b0d92"]]},{"id":"14cf5db5.4b0d92","type":"ui_button","z":"497d3328.acf7dc","name":"on/off","group":"d46ce13f.57145","order":5,"width":"7","height":"1","passthru":false,"label":"{{msg.text}}","tooltip":"","color":"{{msg.color}}","bgcolor":"{{msg.background}}","icon":"ac_unit","payload":"none","payloadType":"str","topic":"button","x":630,"y":260,"wires":[["795fd827.ea6158"]]},{"id":"795fd827.ea6158","type":"switch","z":"497d3328.acf7dc","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"button","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":750,"y":260,"wires":[["9b6c17ee.5ddd38"]]},{"id":"9b6c17ee.5ddd38","type":"function","z":"497d3328.acf7dc","name":"","func":"var obtaindata = global.get (\"switch\")\nif (obtaindata == \"1\"){msg.payload = 0}\nif (obtaindata == \"0\"){msg.payload = 1}\nreturn msg;\n\n","outputs":1,"noerr":0,"x":870,"y":260,"wires":[["544bf558.edbbfc","3214efcd.8599a"]]},{"id":"4f23455a.d2d40c","type":"debug","z":"497d3328.acf7dc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1250,"y":480,"wires":[]},{"id":"3214efcd.8599a","type":"change","z":"497d3328.acf7dc","name":"re-wirte switch variable","rules":[{"t":"move","p":"payload","pt":"msg","to":"switch","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":1060,"y":200,"wires":[[]]},{"id":"ca7e656e.c96468","type":"function","z":"497d3328.acf7dc","name":"","func":"var obtaindata = global.get (\"switch\");\nmsg.payload = obtaindata;\n\nreturn msg;\n","outputs":1,"noerr":0,"x":130,"y":280,"wires":[["b68a09b2.6f22b8"]]},{"id":"544bf558.edbbfc","type":"change","z":"497d3328.acf7dc","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"num","to":"true","tot":"bool"},{"t":"change","p":"payload","pt":"msg","from":"0","fromt":"num","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1040,"y":340,"wires":[["3bd31d4c.91b1c2"]]},{"id":"3bd31d4c.91b1c2","type":"hue-group","z":"497d3328.acf7dc","name":"Salon","bridge":"c9eab922.43e148","groupid":"1","colornamer":true,"skipevents":false,"x":1210,"y":340,"wires":[["3e901968.540616"]]},{"id":"b68a09b2.6f22b8","type":"switch","z":"497d3328.acf7dc","name":"ON/OFF state","property":"switch","propertyType":"global","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":300,"y":280,"wires":[["b0c184da.7839f8"],["7e21507c.e6f65"]]},{"id":"3e901968.540616","type":"change","z":"497d3328.acf7dc","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"1","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":480,"wires":[["4f23455a.d2d40c","ca7e656e.c96468"]]},{"id":"d46ce13f.57145","type":"ui_group","z":"","name":"test","tab":"27c50e50.5b08a2","order":3,"disp":true,"width":"7","collapse":true},{"id":"c9eab922.43e148","type":"hue-bridge","z":"","name":"Philips hue Bridge","bridge":"192.168.11.151","key":"fkRRh1XTEda2MyYvGFOxuHa6x5x6Og0sYgzGkqH1","interval":"3000","disableupdates":false},{"id":"27c50e50.5b08a2","type":"ui_tab","z":"","name":"test","icon":"fa-television","order":2}]

Hi!!!

I have already managed to solve the problem.

There is nothing like self help, :slight_smile:

can you tell us how you managed to show the state of the bulb please

Hello all,
I have installed a hue button via zigbee2mqtt and would now like to be able to display and use this via node red.

The button sends with short press these three commands. with a second short press, the same commands just OFF

If you press the button long it sends these commands

the device sends 7x this step down command and then step UP

Can anyone help me with the creation of the flow or has this possibly already used?

You have not said what you want the flow to do.

Hello,
thank you for your answer.
I want to dim lamps and LED strips.
This is connected via a Demos D2 mini and the dimming takes a Mosfet.

Have you built a flow to control the lamps using just inject nodes? If not then do that first. When that is working then you work out how to control it from the button.

Hello,
how do i get it to extract only the payload on / off / up / down from debug?

If you were to use a Switch Node, you can trap each message individually and route to appropriate actions.

Also I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

1 Like

HUE button flow

[{"id":"3ab755f71ea0d25f","type":"mqtt in","z":"11d377bc371aaddb","name":"","topic":"zigbee2mqtt/Button 1/#","qos":"0","datatype":"json","broker":"67e7ccc7233608f6","nl":false,"rap":true,"rh":0,"inputs":0,"x":300,"y":680,"wires":[["c32ce8a22f836e07","6910df201fa292de","bf6e314f722380d3","2ced540e52c69aa4","ee77c16cc6506468","7e96503aa43f2eba","dd095e003c50c7a5","6abe5c4f917c5a65","62b92bfd5151225d","c612f5aa2d3b7450","542ec2d08c99f18b"]]},{"id":"07b6dbf899e1fd90","type":"change","z":"11d377bc371aaddb","name":"ON","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":500,"wires":[["50629ba69451edaa"]]},{"id":"98f34e8c2a458933","type":"change","z":"11d377bc371aaddb","name":"OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":540,"wires":[["50629ba69451edaa"]]},{"id":"8fa52321bf3042b0","type":"debug","z":"11d377bc371aaddb","name":"battery","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":970,"y":780,"wires":[]},{"id":"8ec26df5fea95523","type":"debug","z":"11d377bc371aaddb","name":"linkquality","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":960,"y":840,"wires":[]},{"id":"804770d7a555def8","type":"debug","z":"11d377bc371aaddb","name":"update.state","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":950,"y":900,"wires":[]},{"id":"542ec2d08c99f18b","type":"debug","z":"11d377bc371aaddb","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":270,"y":760,"wires":[]},{"id":"89585b823ac13a97","type":"debug","z":"11d377bc371aaddb","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1210,"y":660,"wires":[]},{"id":"1caa333f2f2fb30c","type":"debug","z":"11d377bc371aaddb","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1210,"y":700,"wires":[]},{"id":"0c7037beb38e11ee","type":"debug","z":"11d377bc371aaddb","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.action","targetType":"msg","statusVal":"","statusType":"auto","x":1230,"y":740,"wires":[]},{"id":"c32ce8a22f836e07","type":"switch","z":"11d377bc371aaddb","name":"on","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":630,"y":500,"wires":[["07b6dbf899e1fd90"]]},{"id":"6910df201fa292de","type":"switch","z":"11d377bc371aaddb","name":"off","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":630,"y":540,"wires":[["98f34e8c2a458933"]]},{"id":"2ced540e52c69aa4","type":"switch","z":"11d377bc371aaddb","name":"brightness_step_up","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"brightness_step_up","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":670,"y":620,"wires":[["08219c778c25c473"]]},{"id":"bf6e314f722380d3","type":"switch","z":"11d377bc371aaddb","name":"brightness_step_down","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"brightness_step_down","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":680,"y":580,"wires":[["934d531d92277877"]]},{"id":"7e96503aa43f2eba","type":"switch","z":"11d377bc371aaddb","name":"release","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"release","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":640,"y":700,"wires":[["0c01c7988cdde1e8"]]},{"id":"ee77c16cc6506468","type":"switch","z":"11d377bc371aaddb","name":"press","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"press","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":630,"y":660,"wires":[["84abf125f4721ca5"]]},{"id":"dd095e003c50c7a5","type":"switch","z":"11d377bc371aaddb","name":"hold","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"hold","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":630,"y":740,"wires":[["7831ade8a28c34fd"]]},{"id":"84abf125f4721ca5","type":"change","z":"11d377bc371aaddb","name":"press","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.action","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":970,"y":660,"wires":[["89585b823ac13a97"]]},{"id":"0c01c7988cdde1e8","type":"change","z":"11d377bc371aaddb","name":"release","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.action","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":960,"y":700,"wires":[["1caa333f2f2fb30c"]]},{"id":"7831ade8a28c34fd","type":"change","z":"11d377bc371aaddb","name":"hold","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.action","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":970,"y":740,"wires":[["0c7037beb38e11ee"]]},{"id":"62b92bfd5151225d","type":"change","z":"11d377bc371aaddb","name":"linkquality","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.linkquality","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":840,"wires":[["8ec26df5fea95523"]]},{"id":"c612f5aa2d3b7450","type":"change","z":"11d377bc371aaddb","name":"update.state","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.update.state","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":900,"wires":[["804770d7a555def8"]]},{"id":"6abe5c4f917c5a65","type":"change","z":"11d377bc371aaddb","name":"battery","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.battery","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":780,"wires":[["8fa52321bf3042b0"]]},{"id":"934d531d92277877","type":"function","z":"11d377bc371aaddb","name":"","func":"\n//msg.payload = \"step down \" + msg.payload*-1;\nlet step = msg.payload.action_step_size*-1;\nlet t =msg.payload.action_transition_time;\nmsg.payload = {\"brightness_step_onoff\":-36};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":960,"y":580,"wires":[["71f2e6a6d5b8aeeb"]]},{"id":"08219c778c25c473","type":"function","z":"11d377bc371aaddb","name":"","func":"//msg.payload = \"step down \" + msg.payload*-1;\nlet step = msg.payload.action_step_size;\nlet t = msg.payload.action_transition_time;\nmsg.payload = {\"brightness_step_onoff\":36};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":960,"y":620,"wires":[["71f2e6a6d5b8aeeb"]]},{"id":"67e7ccc7233608f6","type":"mqtt-broker","name":"mqtt-broker","broker":"10.0.0.43:1883","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]
1 Like

Thank you,
that has already helped me a lot.
currently the dimming does not work yet.
but I do not know why :frowning:

debug1 is from the hue button
debug2 ist after the function node

I added a few nodes to the flow. Hopefully it helps. My dimmer works.

[{"id":"3ab755f71ea0d25f","type":"mqtt in","z":"11d377bc371aaddb","name":"","topic":"zigbee2mqtt/Button 1/#","qos":"0","datatype":"json","broker":"67e7ccc7233608f6","nl":false,"rap":true,"rh":0,"inputs":0,"x":300,"y":680,"wires":[["c32ce8a22f836e07","6910df201fa292de","bf6e314f722380d3","2ced540e52c69aa4","ee77c16cc6506468","7e96503aa43f2eba","dd095e003c50c7a5","6abe5c4f917c5a65","62b92bfd5151225d","c612f5aa2d3b7450","542ec2d08c99f18b"]]},{"id":"07b6dbf899e1fd90","type":"change","z":"11d377bc371aaddb","name":"ON","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":500,"wires":[["50629ba69451edaa"]]},{"id":"98f34e8c2a458933","type":"change","z":"11d377bc371aaddb","name":"OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":540,"wires":[["50629ba69451edaa"]]},{"id":"8fa52321bf3042b0","type":"debug","z":"11d377bc371aaddb","name":"battery","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":970,"y":780,"wires":[]},{"id":"8ec26df5fea95523","type":"debug","z":"11d377bc371aaddb","name":"linkquality","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":960,"y":840,"wires":[]},{"id":"804770d7a555def8","type":"debug","z":"11d377bc371aaddb","name":"update.state","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":950,"y":900,"wires":[]},{"id":"542ec2d08c99f18b","type":"debug","z":"11d377bc371aaddb","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":270,"y":760,"wires":[]},{"id":"89585b823ac13a97","type":"debug","z":"11d377bc371aaddb","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1210,"y":660,"wires":[]},{"id":"1caa333f2f2fb30c","type":"debug","z":"11d377bc371aaddb","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1210,"y":700,"wires":[]},{"id":"0c7037beb38e11ee","type":"debug","z":"11d377bc371aaddb","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.action","targetType":"msg","statusVal":"","statusType":"auto","x":1230,"y":740,"wires":[]},{"id":"c32ce8a22f836e07","type":"switch","z":"11d377bc371aaddb","name":"on","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":630,"y":500,"wires":[["07b6dbf899e1fd90"]]},{"id":"6910df201fa292de","type":"switch","z":"11d377bc371aaddb","name":"off","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":630,"y":540,"wires":[["98f34e8c2a458933"]]},{"id":"2ced540e52c69aa4","type":"switch","z":"11d377bc371aaddb","name":"brightness_step_up","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"brightness_step_up","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":670,"y":620,"wires":[["08219c778c25c473"]]},{"id":"bf6e314f722380d3","type":"switch","z":"11d377bc371aaddb","name":"brightness_step_down","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"brightness_step_down","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":680,"y":580,"wires":[["934d531d92277877"]]},{"id":"7e96503aa43f2eba","type":"switch","z":"11d377bc371aaddb","name":"release","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"release","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":640,"y":700,"wires":[["0c01c7988cdde1e8"]]},{"id":"ee77c16cc6506468","type":"switch","z":"11d377bc371aaddb","name":"press","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"press","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":630,"y":660,"wires":[["84abf125f4721ca5"]]},{"id":"dd095e003c50c7a5","type":"switch","z":"11d377bc371aaddb","name":"hold","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"hold","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":630,"y":740,"wires":[["7831ade8a28c34fd"]]},{"id":"84abf125f4721ca5","type":"change","z":"11d377bc371aaddb","name":"press","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.action","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":970,"y":660,"wires":[["89585b823ac13a97"]]},{"id":"0c01c7988cdde1e8","type":"change","z":"11d377bc371aaddb","name":"release","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.action","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":960,"y":700,"wires":[["1caa333f2f2fb30c"]]},{"id":"7831ade8a28c34fd","type":"change","z":"11d377bc371aaddb","name":"hold","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.action","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":970,"y":740,"wires":[["0c7037beb38e11ee"]]},{"id":"62b92bfd5151225d","type":"change","z":"11d377bc371aaddb","name":"linkquality","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.linkquality","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":840,"wires":[["8ec26df5fea95523"]]},{"id":"c612f5aa2d3b7450","type":"change","z":"11d377bc371aaddb","name":"update.state","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.update.state","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":900,"wires":[["804770d7a555def8"]]},{"id":"6abe5c4f917c5a65","type":"change","z":"11d377bc371aaddb","name":"battery","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.battery","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":780,"wires":[["8fa52321bf3042b0"]]},{"id":"934d531d92277877","type":"function","z":"11d377bc371aaddb","name":"","func":"\n//msg.payload = \"step down \" + msg.payload*-1;\nlet step = msg.payload.action_step_size*-1;\nlet t =msg.payload.action_transition_time;\nmsg.payload = {\"brightness_step_onoff\":-36};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":960,"y":580,"wires":[["71f2e6a6d5b8aeeb"]]},{"id":"08219c778c25c473","type":"function","z":"11d377bc371aaddb","name":"","func":"//msg.payload = \"step down \" + msg.payload*-1;\nlet step = msg.payload.action_step_size;\nlet t = msg.payload.action_transition_time;\nmsg.payload = {\"brightness_step_onoff\":36};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":960,"y":620,"wires":[["71f2e6a6d5b8aeeb"]]},{"id":"71f2e6a6d5b8aeeb","type":"function","z":"11d377bc371aaddb","name":"Step","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1290,"y":340,"wires":[["9cdf6596d0607129"]]},{"id":"9cdf6596d0607129","type":"mqtt out","z":"11d377bc371aaddb","name":"","topic":"zigbee2mqtt/Terasse/set ","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"67e7ccc7233608f6","x":1550,"y":300,"wires":[]},{"id":"50629ba69451edaa","type":"ui_switch","z":"11d377bc371aaddb","name":"","label":"Terassenlampen ein aus","tooltip":"","group":"8af0f4c0aa346a6b","order":1,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"ON","onvalueType":"str","onicon":"fa-2x fa-toggle-on","oncolor":"red","offvalue":"OFF","offvalueType":"str","officon":"fa-2x fa-toggle-off","offcolor":"grey","animate":true,"className":"","x":1090,"y":300,"wires":[["47de07cb93b53ed0"]]},{"id":"47de07cb93b53ed0","type":"function","z":"11d377bc371aaddb","name":"ON/OFF","func":"return{payload:{\"state\": msg.payload}};","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1280,"y":300,"wires":[["9cdf6596d0607129"]]},{"id":"57afce045830f81c","type":"inject","z":"11d377bc371aaddb","name":"ON","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"ON","payloadType":"str","x":830,"y":340,"wires":[["50629ba69451edaa"]]},{"id":"cb7b9815c7965142","type":"inject","z":"11d377bc371aaddb","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"OFF","payloadType":"str","x":830,"y":380,"wires":[["50629ba69451edaa"]]},{"id":"67e7ccc7233608f6","type":"mqtt-broker","name":"mqtt-broker","broker":"10.0.0.43:1883","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""},{"id":"8af0f4c0aa346a6b","type":"ui_group","name":"Terrassenlampen","tab":"87554c7c0c0ec713","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"87554c7c0c0ec713","type":"ui_tab","name":"Terrasse","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

Now it works. I've put the brightness on 100% und try it again. :slight_smile: crazy shit :smiley:
thanks you

Other question: did you implement dimming with a slider as well?

Not yet but it should be easy to do

1 Like

here a dimmer with slider

[{"id":"1c9bb126f3da0c70","type":"mqtt in","z":"11d377bc371aaddb","name":"","topic":"zigbee2mqtt/Lampe links/#","qos":"0","datatype":"json","broker":"67e7ccc7233608f6","nl":false,"rap":true,"rh":0,"inputs":0,"x":150,"y":260,"wires":[["954e78e6974e58d7","30c412e78752c0f0"]]},{"id":"30c412e78752c0f0","type":"debug","z":"11d377bc371aaddb","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload.update.state","targetType":"msg","statusVal":"payload.update.state","statusType":"auto","x":430,"y":220,"wires":[]},{"id":"a6377e7f5a2ff31c","type":"function","z":"11d377bc371aaddb","name":"Dimmer","func":"let b = msg.payload;\nreturn{payload:{\"brightness\": b}};","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1280,"y":260,"wires":[["9cdf6596d0607129"]]},{"id":"d77e0ca85c9d6cee","type":"ui_slider","z":"11d377bc371aaddb","name":"","label":"Dimmer Terrasse","tooltip":"","group":"8af0f4c0aa346a6b","order":15,"width":0,"height":0,"passthru":false,"outs":"end","topic":"topic","topicType":"msg","min":0,"max":"100","step":1,"className":"","x":930,"y":260,"wires":[["82864b644f9ed40a"]]},{"id":"82864b644f9ed40a","type":"range","z":"11d377bc371aaddb","minin":"0","maxin":"100","minout":"0","maxout":"254","action":"scale","round":false,"property":"payload","name":"","x":1100,"y":260,"wires":[["a6377e7f5a2ff31c"]]},{"id":"954e78e6974e58d7","type":"function","z":"11d377bc371aaddb","name":"","func":"return{payload:msg.payload.brightness};","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":260,"wires":[["03bc37c3f9edc5c0"]]},{"id":"03bc37c3f9edc5c0","type":"range","z":"11d377bc371aaddb","minin":"0","maxin":"254","minout":"0","maxout":"100","action":"scale","round":false,"property":"payload","name":"","x":760,"y":260,"wires":[["d77e0ca85c9d6cee"]]},{"id":"9cdf6596d0607129","type":"mqtt out","z":"11d377bc371aaddb","name":"","topic":"zigbee2mqtt/Terasse/set ","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"67e7ccc7233608f6","x":1550,"y":300,"wires":[]},{"id":"67e7ccc7233608f6","type":"mqtt-broker","name":"mqtt-broker","broker":"10.0.0.43:1883","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""},{"id":"8af0f4c0aa346a6b","type":"ui_group","name":"Terrassenlampen","tab":"87554c7c0c0ec713","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"87554c7c0c0ec713","type":"ui_tab","name":"Terrasse","icon":"dashboard","order":2,"disabled":false,"hidden":false}]
1 Like

Hello, very good.
Thanks :slight_smile:
However, have another problem.
I want to use a Hue button. This sends on / off when pressed short and 7x when pressed long:
{"action": "brightness_step_down", "action_step_size":56, "action_transition_time":0.09, "battery":100, "linkquality":184, "update":{"state": "idle"}}

and then 7x:
{"action": "brightness_step_up", "action_step_size":56, "action_transition_time":0.09, "battery":100, "linkquality":176, "update":{"state": "idle"}}

I would now have to convert that to a number to use it in the range note.

can you help me?

this is my current flow:

[{"id":"a2bf2f3b856e78ce","type":"zigbee2mqtt-in","z":"9f99ca32053f4cbc","name":"","server":"d6cb6dc92f386f45","friendly_name":"Hue Button Eingang (8718699693985)","device_id":"0x001788010b9e79cd","state":"0","outputAtStartup":true,"filterChanges":false,"enableMultiple":false,"x":210,"y":580,"wires":[["7964a7baf35fe47d","0ad97dc951627dc9","8e16961b96f59bab","29758a7b242b91da","e6db9b14d30d0182","c5b68bbd5c0393d2","a34afd0535fa2e5e","5d74de45213046b7","a49969938d6fa737","82148a40083d5e14","cee28066583e072c"]]},{"id":"c1969e6d8543fc89","type":"debug","z":"9f99ca32053f4cbc","name":"debug1 Eingang","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1240,"y":560,"wires":[]},{"id":"ce5ff6b23ddbd4c2","type":"change","z":"9f99ca32053f4cbc","name":"ON","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":400,"wires":[["357897046eec06bf"]]},{"id":"a72784568d2591d9","type":"change","z":"9f99ca32053f4cbc","name":"OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":460,"wires":[["357897046eec06bf"]]},{"id":"0645040ae3e82553","type":"debug","z":"9f99ca32053f4cbc","name":"battery","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":760,"y":840,"wires":[]},{"id":"310b55c74de48dc3","type":"debug","z":"9f99ca32053f4cbc","name":"linkquality","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":760,"y":940,"wires":[]},{"id":"e3feae99b0ccaf18","type":"debug","z":"9f99ca32053f4cbc","name":"update.state","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":770,"y":1040,"wires":[]},{"id":"cee28066583e072c","type":"debug","z":"9f99ca32053f4cbc","name":"debug1 Eingang","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":200,"y":660,"wires":[]},{"id":"ca1f337c61f78d56","type":"debug","z":"9f99ca32053f4cbc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":970,"y":660,"wires":[]},{"id":"85caf099dbc67c55","type":"debug","z":"9f99ca32053f4cbc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":970,"y":720,"wires":[]},{"id":"6225976d81eeaa78","type":"debug","z":"9f99ca32053f4cbc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.action","targetType":"msg","statusVal":"","statusType":"auto","x":990,"y":780,"wires":[]},{"id":"7964a7baf35fe47d","type":"switch","z":"9f99ca32053f4cbc","name":"on","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":510,"y":400,"wires":[["ce5ff6b23ddbd4c2"]]},{"id":"0ad97dc951627dc9","type":"switch","z":"9f99ca32053f4cbc","name":"off","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":510,"y":460,"wires":[["a72784568d2591d9"]]},{"id":"29758a7b242b91da","type":"switch","z":"9f99ca32053f4cbc","name":"brightness_step_up","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"brightness_step_up","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":550,"y":600,"wires":[["c083d85267f2aab5"]]},{"id":"8e16961b96f59bab","type":"switch","z":"9f99ca32053f4cbc","name":"brightness_step_down","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"brightness_step_down","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":560,"y":520,"wires":[["87df7aea839d9b49"]]},{"id":"c5b68bbd5c0393d2","type":"switch","z":"9f99ca32053f4cbc","name":"release","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"release","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":520,"y":720,"wires":[["f130d463eef53457"]]},{"id":"e6db9b14d30d0182","type":"switch","z":"9f99ca32053f4cbc","name":"press","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"press","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":510,"y":660,"wires":[["9fdd61a7cf140602"]]},{"id":"a34afd0535fa2e5e","type":"switch","z":"9f99ca32053f4cbc","name":"hold","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"hold","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":510,"y":780,"wires":[["cf5cdd4d8fef0b42"]]},{"id":"9fdd61a7cf140602","type":"change","z":"9f99ca32053f4cbc","name":"press","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.action","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":660,"wires":[["ca1f337c61f78d56"]]},{"id":"f130d463eef53457","type":"change","z":"9f99ca32053f4cbc","name":"release","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.action","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":720,"wires":[["85caf099dbc67c55"]]},{"id":"cf5cdd4d8fef0b42","type":"change","z":"9f99ca32053f4cbc","name":"hold","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.action","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":780,"wires":[["6225976d81eeaa78"]]},{"id":"a49969938d6fa737","type":"change","z":"9f99ca32053f4cbc","name":"linkquality","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.linkquality","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":940,"wires":[["310b55c74de48dc3","f118a41a7e4942d8"]]},{"id":"82148a40083d5e14","type":"change","z":"9f99ca32053f4cbc","name":"update.state","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.update.state","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":1040,"wires":[["e3feae99b0ccaf18"]]},{"id":"5d74de45213046b7","type":"change","z":"9f99ca32053f4cbc","name":"battery","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.battery","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":840,"wires":[["0645040ae3e82553","5d008cc57fae3e99"]]},{"id":"87df7aea839d9b49","type":"function","z":"9f99ca32053f4cbc","name":"","func":"\n//msg.payload = \"step down \" + msg.payload*-1;\nlet step = msg.payload.action_step_size*-1;\nlet t =msg.payload.action_transition_time;\nmsg.payload = {\"brightness_step_onoff\":-36};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":520,"wires":[["e21ebe14b9f39926"]]},{"id":"c083d85267f2aab5","type":"function","z":"9f99ca32053f4cbc","name":"","func":"//msg.payload = \"step down \" + msg.payload*-1;\nlet step = msg.payload.action_step_size;\nlet t = msg.payload.action_transition_time;\nmsg.payload = {\"brightness_step_onoff\":36};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":600,"wires":[["e21ebe14b9f39926"]]},{"id":"e21ebe14b9f39926","type":"function","z":"9f99ca32053f4cbc","name":"Step","func":"return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":950,"y":560,"wires":[["c1969e6d8543fc89"]]},{"id":"357897046eec06bf","type":"ui_switch","z":"9f99ca32053f4cbc","name":"Eingang On / Off","label":"Eingang ","tooltip":"","group":"b39a769e1a5ab2d0","order":1,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"ON","onvalueType":"str","onicon":"fa-2x fa-toggle-on","oncolor":"red","offvalue":"OFF","offvalueType":"str","officon":"fa-2x fa-toggle-off","offcolor":"green","animate":true,"className":"","x":990,"y":280,"wires":[["77a55f8e37d0061a"]]},{"id":"77a55f8e37d0061a","type":"function","z":"9f99ca32053f4cbc","name":"ON/OFF","func":"return{payload:{\"state\": msg.payload}};","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1220,"y":280,"wires":[[]]},{"id":"46512a4130ee641d","type":"inject","z":"9f99ca32053f4cbc","name":"ON","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"ON","payloadType":"str","x":710,"y":260,"wires":[["357897046eec06bf"]]},{"id":"e03ea086dc262180","type":"inject","z":"9f99ca32053f4cbc","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"OFF","payloadType":"str","x":710,"y":300,"wires":[["357897046eec06bf"]]},{"id":"f118a41a7e4942d8","type":"ui_text","z":"9f99ca32053f4cbc","group":"3463b2b4d95822f5","order":5,"width":0,"height":0,"name":"linkquality","label":"linkquality","format":"{{msg.payload}} unit","layout":"row-spread","className":"","x":760,"y":1000,"wires":[]},{"id":"5d008cc57fae3e99","type":"ui_text","z":"9f99ca32053f4cbc","group":"3463b2b4d95822f5","order":3,"width":0,"height":0,"name":"battery","label":"Battery","format":"{{msg.payload}} %","layout":"row-spread","className":"","x":760,"y":900,"wires":[]},{"id":"d6cb6dc92f386f45","type":"zigbee2mqtt-server","name":"","host":"localhost","mqtt_port":"1883","mqtt_username":"","mqtt_password":"","mqtt_qos":"0","tls":"","usetls":false,"base_topic":"zigbee2mqtt"},{"id":"b39a769e1a5ab2d0","type":"ui_group","name":"Dimmer","tab":"c7e50f4d.33f09","order":4,"disp":true,"width":"6","collapse":false,"className":""},{"id":"3463b2b4d95822f5","type":"ui_group","name":"hue button entrance","tab":"b881d91c.f73d98","order":2,"disp":true,"width":"6","collapse":false,"className":""},{"id":"c7e50f4d.33f09","type":"ui_tab","name":"Switches","icon":"mi-toggle_on","order":2,"disabled":false,"hidden":false},{"id":"b881d91c.f73d98","type":"ui_tab","name":"Status","icon":"dashboard","order":4,"disabled":false,"hidden":false}]

Hello again,
I have tried it myself and now always get a 0 or 100 as output.
step down I get 7x and then 7x step up.
I need a function that sets the value at step down from 100 to 0 and then at step up from 0 to 100.

let stepSize = 100 / 7;
let step = msg.payload.action;
let brightness = Number(msg.payload.brightness);

if (!isNaN(brightness)) {
    if (step === "brightness_step_down") {
        brightness -= stepSize;
        if (brightness < 0) {
            brightness = 0;
        }
    } else if (step === "brightness_step_up") {
        brightness += stepSize;
        if (brightness > 100) {
            brightness = 100;
        }
    } else {
        brightness = 0;
    }
    msg.payload = brightness;
} else {
    msg.payload = 0;
}

return msg;