Subflow to be used with node-red-contrib-deconz
Here's what's inside the subflow:
How to use the subflow - Example 1:
How to use the subflow - Example 2:
The deCONZ light input node should be configured as follows (this is the default):
The deCONZ light output node should be configured as follows (same light entity as input):
Copy the subflow below to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option
Hello, I have been looking for a solution for days, but have not found one. Hopefully you can help me.
My problem: I have no idea how to integrate your flow with mine. My aqara switch not only provides 1 and 0 via deconz, but also button events (1002: single tab, 1004: double tap, 1001: hold start, 1004: hold end). And at the output I have a Hue Node hanging, which can't handle "bri". Can you give me tips on how to adjust your flow?
Here is my flow:
[{"id":"87cd25ce.6a67a8","type":"subflow","name":"Single button deCONZ dimmer","info":"","category":"","in":[{"x":60,"y":40,"wires":[{"id":"d570d72d.c3da98"}]}],"out":[{"x":840,"y":300,"wires":[{"id":"98ce5177.b0bb4","port":0},{"id":"66af08b1.cdafd8","port":0},{"id":"38a7138d.87851c","port":0},{"id":"1f9d1b97.ac7124","port":0},{"id":"326d4593.beea1a","port":0}]}],"env":[{"name":"ButtonPressed","type":"str","value":"0"},{"name":"ButtonReleased","type":"str","value":"1"},{"name":"Step","type":"num","value":"20","ui":{"label":{"en-US":"Step (1-255)"},"type":"input","opts":{"types":["num"]}}},{"name":"On state","type":"str","value":"Resume","ui":{"type":"select","opts":{"opts":[{"l":{"en-US":"Resume"},"v":"Resume"},{"l":{"en-US":"Full brightness"},"v":"Full brightness"}]},"label":{}}}],"color":"#E6E0F8","inputLabels":["from trigger and deCONZ in (complete state payload))"],"outputLabels":["to deCONZ out (command>object>json)"],"icon":"node-red/light.svg","status":{"x":840,"y":240,"wires":[{"id":"98ce5177.b0bb4","port":0},{"id":"66af08b1.cdafd8","port":0},{"id":"38a7138d.87851c","port":0},{"id":"1f9d1b97.ac7124","port":0},{"id":"326d4593.beea1a","port":0}]}},{"id":"4edef881.56f858","type":"comment","z":"87cd25ce.6a67a8","name":"instructions + link to latest version of this subflow","info":"Latest version of this flow can be found at \nhttps://flows.nodered.org/flow/1949af43de3db8133b039dac706372bd/in/YsSoz9IDM4Z_\n\nto the input add:\n1) button sending different pressed/released commands\n2) \"deCONZ in\" node with the light you want to dim and choose \"complete state payload\" + \"send state on start\"\n\nto the output add:\n1) \"deCONZ out\" node with the light you want to dim and choose command \"object json\". In my testing transition time = 8 worked best (despite the fact that new brightnesslevel is resent every 500 ms)","x":420,"y":36,"wires":[]},{"id":"d62abc9.279974","type":"change","z":"87cd25ce.6a67a8","name":"save snapshot","rules":[{"t":"set","p":"oldPowerstate","pt":"flow","to":"payload.on","tot":"msg"},{"t":"set","p":"oldBrightness","pt":"flow","to":"payload.bri","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":200,"wires":[[]]},{"id":"d570d72d.c3da98","type":"switch","z":"87cd25ce.6a67a8","name":"pressed/released?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"ButtonPressed","vt":"env"},{"t":"eq","v":"ButtonReleased","vt":"env"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":130,"y":120,"wires":[["2c5927e9.6a1538","680a9a68.02d2a4"],["e7cce410.826098","4154e695.4c12e8"],["6318ca88.e28934"]]},{"id":"2c5927e9.6a1538","type":"trigger","z":"87cd25ce.6a67a8","op1":"","op2":"true","op1type":"nul","op2type":"bool","duration":"500","extend":false,"units":"ms","reset":"","bytopic":"all","name":"Button held?","x":370,"y":280,"wires":[["35a11798.4ac1d8"]]},{"id":"b5a46c99.661d1","type":"change","z":"87cd25ce.6a67a8","name":"flow.next = 0","rules":[{"t":"set","p":"next","pt":"flow","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":400,"wires":[[]]},{"id":"34e6355b.017fba","type":"change","z":"87cd25ce.6a67a8","name":"flow.next = 1","rules":[{"t":"set","p":"next","pt":"flow","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":520,"wires":[[]]},{"id":"9db4163a.4e6a88","type":"trigger","z":"87cd25ce.6a67a8","op1":"Step","op2":"0","op1type":"env","op2type":"str","duration":"-500","extend":false,"units":"ms","reset":"","bytopic":"all","name":"","x":400,"y":440,"wires":[["b5a46c99.661d1","38a7138d.87851c"]]},{"id":"5ac933e7.dbbedc","type":"trigger","z":"87cd25ce.6a67a8","op1":"Step","op2":"0","op1type":"env","op2type":"str","duration":"-500","extend":false,"units":"ms","reset":"","bytopic":"all","name":"","x":400,"y":480,"wires":[["34e6355b.017fba","1f9d1b97.ac7124"]]},{"id":"b530b6e4.e6b068","type":"switch","z":"87cd25ce.6a67a8","name":"flow.next switch","property":"next","propertyType":"flow","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":160,"y":460,"wires":[["9db4163a.4e6a88"],["5ac933e7.dbbedc"]]},{"id":"e7cce410.826098","type":"change","z":"87cd25ce.6a67a8","name":"reset triggers","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":150,"y":280,"wires":[["9db4163a.4e6a88","5ac933e7.dbbedc","2c5927e9.6a1538"]]},{"id":"8591edaf.559a4","type":"change","z":"87cd25ce.6a67a8","name":"","rules":[{"t":"set","p":"newBrightness","pt":"flow","to":"oldBrightness","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":360,"wires":[["b530b6e4.e6b068"]]},{"id":"a6fb6989.a5a708","type":"switch","z":"87cd25ce.6a67a8","name":"toggle","property":"oldPowerstate","propertyType":"flow","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":730,"y":120,"wires":[["98ce5177.b0bb4"],["abb86974.d74388"]]},{"id":"98ce5177.b0bb4","type":"change","z":"87cd25ce.6a67a8","name":"{\"on\":false}","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"on\":false}","tot":"json"},{"t":"set","p":"oldPowerstate","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":200,"wires":[[]]},{"id":"66af08b1.cdafd8","type":"change","z":"87cd25ce.6a67a8","name":"{\"on\":true, \"bri\":255}","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"on\":true, \"bri\":255}","tot":"json"},{"t":"set","p":"oldPowerstate","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":240,"wires":[[]]},{"id":"35a11798.4ac1d8","type":"switch","z":"87cd25ce.6a67a8","name":"oldPowerstate true/false?","property":"oldPowerstate","propertyType":"flow","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":410,"y":320,"wires":[["8591edaf.559a4"],["e15a6164.c7553"]]},{"id":"e15a6164.c7553","type":"change","z":"87cd25ce.6a67a8","name":"newBrightness = 0","rules":[{"t":"set","p":"newBrightness","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":400,"wires":[["9db4163a.4e6a88"]]},{"id":"1f9d1b97.ac7124","type":"function","z":"87cd25ce.6a67a8","name":"decrease brightness","func":"var newBrightness = flow.get(\"newBrightness\") - env.get(\"Step\")||1;\nif (newBrightness < 2) { newBrightness = 2; }\nflow.set(\"newBrightness\", newBrightness);\nmsg.payload = { on:true, bri: newBrightness }\nreturn msg;","outputs":1,"noerr":0,"x":660,"y":480,"wires":[[]]},{"id":"38a7138d.87851c","type":"function","z":"87cd25ce.6a67a8","name":"increase brightness","func":"var newBrightness = flow.get(\"newBrightness\") + env.get(\"Step\")||1;\nif (newBrightness > 252) { newBrightness = 255; }\nflow.set(\"newBrightness\", newBrightness);\nmsg.payload = { on:true, bri: newBrightness }\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":440,"wires":[[]]},{"id":"6318ca88.e28934","type":"switch","z":"87cd25ce.6a67a8","name":"check payload","property":"payload.bri","propertyType":"msg","rules":[{"t":"istype","v":"number","vt":"number"}],"checkall":"true","repair":false,"outputs":1,"x":380,"y":160,"wires":[["d62abc9.279974"]]},{"id":"680a9a68.02d2a4","type":"change","z":"87cd25ce.6a67a8","name":"","rules":[{"t":"set","p":"PressedTime","pt":"flow","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":80,"wires":[[]]},{"id":"4154e695.4c12e8","type":"change","z":"87cd25ce.6a67a8","name":"","rules":[{"t":"set","p":"ReleasedTime","pt":"flow","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":120,"wires":[["50adfaf4.967774"]]},{"id":"50adfaf4.967774","type":"function","z":"87cd25ce.6a67a8","name":"Short press?","func":"if (flow.get(\"ReleasedTime\") - flow.get(\"PressedTime\") < 500)\n{\n msg.payload = \"Short press\";\n return msg;\n}","outputs":1,"noerr":0,"x":590,"y":120,"wires":[["a6fb6989.a5a708"]]},{"id":"abb86974.d74388","type":"switch","z":"87cd25ce.6a67a8","name":"Resume or full brightness?","property":"On state","propertyType":"env","rules":[{"t":"eq","v":"Full brightness","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":420,"y":240,"wires":[["66af08b1.cdafd8"],["326d4593.beea1a"]]},{"id":"326d4593.beea1a","type":"change","z":"87cd25ce.6a67a8","name":"{\"on\":true}","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"on\":true}","tot":"json"},{"t":"set","p":"oldPowerstate","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":280,"wires":[[]]},{"id":"cda9fadb.a9e348","type":"deconz-input","z":"adcbe66f.719f38","name":"","server":"67366b1c.354a54","device":"00:15:8d:00:04:50:70:a9-01-0012","device_name":"Smart Switch Flo : ZHASwitch","topic":"","state":"0","output":"always","outputAtStartup":true,"x":360,"y":740,"wires":[["dceeeb27.753ff8"],[]]},{"id":"9804aa4e.6ca588","type":"hue-light","z":"adcbe66f.719f38","name":"Esstischlampe","bridge":"73f9f7ee.93ded8","lightid":"12","colornamer":false,"skipevents":false,"x":1060,"y":740,"wires":[["ebf9dfdb.f3dc2","dceeeb27.753ff8"]]},{"id":"ebf9dfdb.f3dc2","type":"debug","z":"adcbe66f.719f38","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1270,"y":740,"wires":[]},{"id":"dceeeb27.753ff8","type":"subflow:87cd25ce.6a67a8","z":"adcbe66f.719f38","name":"","env":[],"x":730,"y":740,"wires":[["9804aa4e.6ca588"]]},{"id":"67366b1c.354a54","type":"deconz-server","z":"","name":"deCONZ","ip":"homeassistant.local","port":"40850","apikey":"60C8E3BB08","ws_port":"8081","secure":false,"polling":"15"},{"id":"73f9f7ee.93ded8","type":"hue-bridge","z":"","name":"Philips hue","bridge":"192.168.178.21","key":"TlZnMl5DIuakM3ncNKlbf9bca0wRb3QS6XmwSG3w","interval":"3000","disableupdates":false}]