Single button deCONZ dimmer (subflow)

Subflow to be used with node-red-contrib-deconz

Here's what's inside the subflow: Single button deCONZ

How to use the subflow - Example 1: Single button deCONZ

How to use the subflow - Example 2: Single button deCONZ

The deCONZ light input node should be configured as follows (this is the default): Single button deCONZ

The deCONZ light output node should be configured as follows (same light entity as input): Single button deCONZ


Copy the subflow below to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option

[{"id":"dbe92732.d4c7a8","type":"subflow","name":"Single button deCONZ dimmer","info":"","category":"","in":[{"x":70,"y":200,"wires":[{"id":"98586b6c.dc98a8"}]}],"out":[{"x":880,"y":240,"wires":[{"id":"7727ea50.84e024","port":0},{"id":"df5c48b2.3096c8","port":0},{"id":"8f48107d.e81fe","port":0},{"id":"2afc4d06.b0d442","port":0},{"id":"8189b62a.1c9a38","port":0},{"id":"df8d2d15.50a4f","port":0}]}],"env":[{"name":"ButtonPressed","type":"str","value":"0"},{"name":"ButtonReleased","type":"str","value":"1"},{"name":"TransitionTime","type":"num","value":"30","ui":{"label":{"en-US":"Transition time (10-100)"},"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"}]}}}],"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":880,"y":450,"wires":[{"id":"b148b811.6752e8","port":0}]}},{"id":"ccfae278.fa94e","type":"comment","z":"dbe92732.d4c7a8","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\". Leave transition time empty.","x":410,"y":40,"wires":[]},{"id":"7f542d56.032e54","type":"change","z":"dbe92732.d4c7a8","name":"save snapshot","rules":[{"t":"set","p":"LightTurnedOn","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":570,"y":450,"wires":[["b148b811.6752e8"]]},{"id":"98586b6c.dc98a8","type":"switch","z":"dbe92732.d4c7a8","name":"Input filter","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":170,"y":200,"wires":[["4695a743.ec9008","bad2e7c8.9bc958"],["71a8e1b5.2414b","7d1230fb.c96bf","2afc4d06.b0d442"],["ba63e850.62c8b8"]]},{"id":"4695a743.ec9008","type":"trigger","z":"dbe92732.d4c7a8","op1":"","op2":"true","op1type":"nul","op2type":"bool","duration":"500","extend":false,"units":"ms","reset":"","bytopic":"all","name":"Button held?","x":390,"y":320,"wires":[["60907f92.76824"]]},{"id":"fa80e330.ffb07","type":"switch","z":"dbe92732.d4c7a8","name":"Last increased?","property":"increased","propertyType":"flow","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":400,"y":370,"wires":[["8189b62a.1c9a38"],["df8d2d15.50a4f"]]},{"id":"71a8e1b5.2414b","type":"change","z":"dbe92732.d4c7a8","name":"Button not held","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":150,"y":320,"wires":[["4695a743.ec9008"]]},{"id":"f17c1842.f122f8","type":"switch","z":"dbe92732.d4c7a8","name":"toggle","property":"LightTurnedOn","propertyType":"flow","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":530,"y":230,"wires":[["7727ea50.84e024"],["613cb9a.bd49d48"]]},{"id":"7727ea50.84e024","type":"change","z":"dbe92732.d4c7a8","name":"Off","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"on\":false}","tot":"json"},{"t":"set","p":"LightTurnedOn","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":220,"wires":[[]]},{"id":"df5c48b2.3096c8","type":"change","z":"dbe92732.d4c7a8","name":"Full brightness","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"on\":true, \"bri\":255}","tot":"json"},{"t":"set","p":"oldPowerstate","pt":"flow","to":"true","tot":"bool"},{"t":"set","p":"increased","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":260,"wires":[[]]},{"id":"60907f92.76824","type":"switch","z":"dbe92732.d4c7a8","name":"LightTurnedOn?","property":"LightTurnedOn","propertyType":"flow","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":150,"y":370,"wires":[["fa80e330.ffb07"],["3c65b390.51e9ec"]]},{"id":"ba63e850.62c8b8","type":"switch","z":"dbe92732.d4c7a8","name":"light state?","property":"payload.bri","propertyType":"msg","rules":[{"t":"istype","v":"number","vt":"number"}],"checkall":"true","repair":false,"outputs":1,"x":390,"y":450,"wires":[["7f542d56.032e54"]]},{"id":"bad2e7c8.9bc958","type":"change","z":"dbe92732.d4c7a8","name":"","rules":[{"t":"set","p":"PressedTime","pt":"flow","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":100,"wires":[[]]},{"id":"7d1230fb.c96bf","type":"change","z":"dbe92732.d4c7a8","name":"","rules":[{"t":"set","p":"ReleasedTime","pt":"flow","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":180,"wires":[["b7e030e0.89282"]]},{"id":"b7e030e0.89282","type":"function","z":"dbe92732.d4c7a8","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":390,"y":230,"wires":[["f17c1842.f122f8"]]},{"id":"613cb9a.bd49d48","type":"switch","z":"dbe92732.d4c7a8","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":440,"y":280,"wires":[["df5c48b2.3096c8"],["8f48107d.e81fe"]]},{"id":"8f48107d.e81fe","type":"change","z":"dbe92732.d4c7a8","name":"Resume","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"on\":true}","tot":"json"},{"t":"set","p":"LightTurnedOn","pt":"flow","to":"true","tot":"bool"},{"t":"set","p":"increased","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":300,"wires":[[]]},{"id":"2afc4d06.b0d442","type":"template","z":"dbe92732.d4c7a8","name":"Stop increasing/decreasing brightness","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"bri_inc\":0}","output":"json","x":470,"y":140,"wires":[[]]},{"id":"df8d2d15.50a4f","type":"function","z":"dbe92732.d4c7a8","name":"start increasing brightness","func":"flow.set(\"increased\",true);\nvar oldBrightness = flow.get(\"oldBrightness\")||1;\nvar TransitionTime = env.get(\"TransitionTime\")||40;\nvar CalculatedTime = Math.round((TransitionTime/255*(255-oldBrightness)))\nif (CalculatedTime < 10) {CalculatedTime = 10;}\nmsg.payload = { on:true, bri: 255, transitiontime: CalculatedTime}\nreturn msg;","outputs":1,"noerr":0,"x":680,"y":380,"wires":[[]]},{"id":"8189b62a.1c9a38","type":"function","z":"dbe92732.d4c7a8","name":"start decreasing brightness","func":"flow.set(\"increased\",false);\nvar oldBrightness = flow.get(\"oldBrightness\")||1;\nvar TransitionTime = env.get(\"TransitionTime\")||40;\nvar CalculatedTime = Math.round((TransitionTime/255*oldBrightness))\nif (CalculatedTime < 10) {CalculatedTime = 10;}\nmsg.payload = { on:true, bri: 2, transitiontime: CalculatedTime}\nreturn msg;","outputs":1,"noerr":0,"x":680,"y":340,"wires":[[]]},{"id":"3c65b390.51e9ec","type":"change","z":"dbe92732.d4c7a8","name":"Start from brightness = 0","rules":[{"t":"set","p":"oldBrightness","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":410,"wires":[["df8d2d15.50a4f"]]},{"id":"b148b811.6752e8","type":"function","z":"dbe92732.d4c7a8","name":"share status","func":"msg.payload = { on:flow.get(\"LightTurnedOn\"), bri: flow.get(\"oldBrightness\")}\nreturn msg;","outputs":1,"noerr":0,"x":760,"y":450,"wires":[[]]}]

Collection Info

prev

Flow Info

Created 4 years, 5 months ago
Updated 2 years, 8 months ago
Rating: 5 3

Owner

Actions

Rate:

Node Types

Core
  • change (x8)
  • comment (x1)
  • function (x4)
  • switch (x6)
  • template (x1)
  • trigger (x1)
Other
  • subflow (x1)

Tags

Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option