IKEA Dimmer in NodeRED
I'm recreating the original functionality of the IKEA TRADFRI Wireless Dimmer in NodeRed so you could use the button with any NodeRED enabled devices, not just IKEA ones!
Instructions: You can read all set up instructions here
Features:
- ON|OFF toggle
- Brightness UP|DOWN
- Custom increment step
Settings
- Step increment brightness by X
[{"id":"8e94e1a7.00a86","type":"tab","label":"IKEA Dimmer in NodeRED","disabled":false,"info":"I'm recreating the original functionality of the IKEA TRADFRI Wireless Dimmer in NodeRed so you could use the button with any NodeRED enabled devices, not just IKEA ones!\n\n\n**Instructions:**\nYou can read all [set up instructions here](https://notenoughtech.com/featured/ikea-tradfri-wireless-dimmer-in-nodered/)\n\n---\n\n**Features**:\n\n- ON|OFF toggle\n- Brightness UP|DOWN\n- Custom increment step\n\n---\n# Settings\n - **Step** increment brightness by X "},{"id":"936ccd7a.892a6","type":"mqtt in","z":"8e94e1a7.00a86","name":"IKEA Remote","topic":"zigbee2mqtt/ikeaplugremote1","qos":"1","datatype":"json","broker":"1b17c099.182d2f","x":110,"y":320,"wires":[["122be369.522d0d"]]},{"id":"122be369.522d0d","type":"switch","z":"8e94e1a7.00a86","name":"Messages","property":"payload.click","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"},{"t":"eq","v":"brightness_stop","vt":"str"},{"t":"eq","v":"brightness_up","vt":"str"},{"t":"eq","v":"brightness_down","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":310,"y":320,"wires":[["3e775ea1.3f24f2"],["4ad0d1dd.81e03"],["93b24937.766a78"],["b7f4d86d.af78d8","b5601659.679848"],["783559bc.5c2b98","b5601659.679848"]]},{"id":"b7f4d86d.af78d8","type":"function","z":"8e94e1a7.00a86","name":"Brightness up","func":"var ikea_button = flow.get(\"ikea_button\");\n\nvar step = ikea_button.step;\nvar brightness = ikea_button.brightness;\n\nif(brightness >= 0){\n ikea_button.brightness = brightness + step;\n flow.set(\"ikea_button\", ikea_button);\n\t}\n\t\nif(brightness >= 255){\n ikea_button.brightness = 254;\n flow.set(\"press\", false);\n flow.set(\"ikea_button\", ikea_button);\n }\n\nmsg.payload = {\"state\":\"ON\",\n \"brightness\":brightness};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":740,"y":660,"wires":[["5e994c99.453e24","e4a2f94d.802018"]]},{"id":"783559bc.5c2b98","type":"function","z":"8e94e1a7.00a86","name":"Brightness down","func":"var ikea_button = flow.get(\"ikea_button\");\n\nvar step = ikea_button.step;\nvar brightness = ikea_button.brightness;\n\nif(brightness <= 255){\n ikea_button.brightness = brightness - step; \n flow.set(\"ikea_button\", ikea_button);\n\t}\n\t\nif(brightness <= 0){\n ikea_button.brightness = 1;\n flow.set(\"press\", false);\n flow.set(\"ikea_button\", ikea_button);\n }\n\nmsg.payload = {\"state\":\"ON\",\n \"brightness\":brightness};\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":740,"y":700,"wires":[["5e994c99.453e24","628d377.68711c8"]]},{"id":"1bad81a9.bd217e","type":"switch","z":"8e94e1a7.00a86","name":"Control loop","property":"press","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":1110,"y":840,"wires":[["783559bc.5c2b98"]]},{"id":"59bd3874.f1e618","type":"switch","z":"8e94e1a7.00a86","name":"Control loop","property":"press","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":1110,"y":880,"wires":[["b7f4d86d.af78d8"]]},{"id":"e4a2f94d.802018","type":"delay","z":"8e94e1a7.00a86","name":"","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":810,"y":880,"wires":[["59bd3874.f1e618"]]},{"id":"628d377.68711c8","type":"delay","z":"8e94e1a7.00a86","name":"","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":810,"y":840,"wires":[["1bad81a9.bd217e"]]},{"id":"24b9738d.41986c","type":"comment","z":"8e94e1a7.00a86","name":"loop every 500 ms","info":"","x":810,"y":800,"wires":[]},{"id":"bd57553f.d071a8","type":"comment","z":"8e94e1a7.00a86","name":"increase/decrease brightness","info":"","x":740,"y":620,"wires":[]},{"id":"b5601659.679848","type":"change","z":"8e94e1a7.00a86","name":"start","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1050,"y":420,"wires":[["f53bbfa7.deab4"]]},{"id":"93b24937.766a78","type":"change","z":"8e94e1a7.00a86","name":"stop","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1050,"y":460,"wires":[["f53bbfa7.deab4"]]},{"id":"f53bbfa7.deab4","type":"change","z":"8e94e1a7.00a86","name":"Control the loop","rules":[{"t":"set","p":"press","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1230,"y":435,"wires":[[]]},{"id":"b745b5a3.e19ad8","type":"comment","z":"8e94e1a7.00a86","name":"start/stop loop","info":"","x":1190,"y":405,"wires":[]},{"id":"a58d1bd0.40d498","type":"mqtt in","z":"8e94e1a7.00a86","name":"","topic":"zigbee2mqtt/ikeabulbc1","qos":"2","datatype":"json","broker":"1b17c099.182d2f","x":160,"y":180,"wires":[["1a24f6dd.ec62c9"]]},{"id":"5e994c99.453e24","type":"mqtt out","z":"8e94e1a7.00a86","name":"","topic":"zigbee2mqtt/ikeabulbc1/set","qos":"","retain":"","broker":"1b17c099.182d2f","x":960,"y":260,"wires":[]},{"id":"f4882226.d867a","type":"mqtt out","z":"8e94e1a7.00a86","name":"","topic":"zigbee2mqtt/ikeabulbc1/get","qos":"","retain":"","broker":"1b17c099.182d2f","x":420,"y":120,"wires":[]},{"id":"9ac185ae.e31608","type":"inject","z":"8e94e1a7.00a86","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"state\":\"\"}","payloadType":"json","x":140,"y":120,"wires":[["f4882226.d867a"]]},{"id":"3e775ea1.3f24f2","type":"function","z":"8e94e1a7.00a86","name":"ON","func":"var ikea_button = flow.get(\"ikea_button\");\nikea_button.state = true;\nflow.set(\"ikea_button\");\nmsg.payload = { \"state\":\"ON\"};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":550,"y":240,"wires":[["5e994c99.453e24"]]},{"id":"4ad0d1dd.81e03","type":"function","z":"8e94e1a7.00a86","name":"OFF","func":"var ikea_button = flow.get(\"ikea_button\");\nikea_button.state = false;\nflow.set(\"ikea_button\");\n\nmsg.payload = { \"state\":\"OFF\"};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":550,"y":280,"wires":[["5e994c99.453e24"]]},{"id":"1a24f6dd.ec62c9","type":"delay","z":"8e94e1a7.00a86","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":390,"y":180,"wires":[["9876d591.6d3ef8"]]},{"id":"9876d591.6d3ef8","type":"function","z":"8e94e1a7.00a86","name":"Update","func":"var ikea_button = flow.get(\"ikea_button\");\nvar brightness = msg.payload.brightness;\n\nikea_button.brightness = brightness;\nflow.set(\"ikea_button\") = ikea_button;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":560,"y":180,"wires":[[]]},{"id":"4a060db4.88ec34","type":"function","z":"8e94e1a7.00a86","name":"Serttings","func":"//see default values in Setup","outputs":1,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is deployed.\n\nvar ikea_button = flow.get(\"ikea_button\");\nvar press = flow.get(\"press\");\n\n\nif(ikea_button === undefined){\n ikea_button = {\"state\": false, \"brightness\": 0, \"step\": 30,};\n flow.set(\"ikea_button\", ikea_button);\n} \n\nif(press === undefined){\n press = false;\n flow.set(\"press\", press);\n} ","finalize":"","x":120,"y":80,"wires":[[]]},{"id":"1b17c099.182d2f","type":"mqtt-broker","z":"","name":"MQTT","broker":"dockerpi.local","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]