Dimming lights with IKEA remote

So I've been searching around and finding some information in this forum and other places. Just thought I'd share what I've done so far.

First off, I've been using Node-RED for two days so nothing ground breaking and I know that tons can be improved! Feel free to comment what you would have done differently!

I'm using an unraid server with separate docker containers for home assistan, mqtt, node red and deconz (conbee 2 usb dongle).

deconz router:

[{"id":"86a3d213.f8fed","type":"tab","label":"deconz router","disabled":false,"info":""},{"id":"d8eb9742.663f18","type":"deconz-event","z":"86a3d213.f8fed","name":"","server":"23bf38f1.10d1b8","device_name":null,"x":90,"y":500,"wires":[["1c89a503.e839fb"]]},{"id":"1c89a503.e839fb","type":"switch","z":"86a3d213.f8fed","name":"","property":"payload.id","propertyType":"msg","rules":[{"t":"eq","v":"12","vt":"str"},{"t":"eq","v":"3","vt":"str"},{"t":"eq","v":"14","vt":"str"},{"t":"eq","v":"13","vt":"str"},{"t":"eq","v":"8","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":250,"y":500,"wires":[["f7e0d97.293db28"],["8465d294.95921"],["8465d294.95921"],["a39df0e7.e68b2"],["b2ebeb9c.3fc468"]]},{"id":"f7e0d97.293db28","type":"switch","z":"86a3d213.f8fed","name":"","property":"payload.state.buttonevent","propertyType":"msg","rules":[{"t":"eq","v":"1001","vt":"str"},{"t":"eq","v":"1003","vt":"str"},{"t":"eq","v":"2001","vt":"str"},{"t":"eq","v":"2003","vt":"str"},{"t":"eq","v":"1002","vt":"str"},{"t":"eq","v":"2002","vt":"str"}],"checkall":"true","repair":false,"outputs":6,"x":450,"y":140,"wires":[["c32c07a1.f42188"],["c32c07a1.f42188"],["c32c07a1.f42188"],["c32c07a1.f42188"],["8a7ee65.b9a9f18"],["8a7ee65.b9a9f18"]]},{"id":"c32c07a1.f42188","type":"function","z":"86a3d213.f8fed","name":"set params","func":"if (msg.payload.state.buttonevent === 1001 || msg.payload.state.buttonevent === 2001) {\n   global.set('bedroom/desk/dim', true);\n} else {\n   global.set('bedroom/desk/dim', false);\n}\n\nglobal.set('bedroom/desk/buttonevent', msg.payload.state.buttonevent);\n\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":120,"wires":[["f9eadc6b.7775a"]]},{"id":"f9eadc6b.7775a","type":"mqtt out","z":"86a3d213.f8fed","name":"","topic":"home/bedroom/desk/lights/dim","qos":"2","retain":"","broker":"2fccef58.45c9c","x":890,"y":100,"wires":[]},{"id":"8a7ee65.b9a9f18","type":"mqtt out","z":"86a3d213.f8fed","name":"","topic":"home/bedroom/desk/lights/toggle","qos":"2","retain":"","broker":"2fccef58.45c9c","x":900,"y":160,"wires":[]},{"id":"8465d294.95921","type":"switch","z":"86a3d213.f8fed","name":"","property":"payload.state.buttonevent","propertyType":"msg","rules":[{"t":"eq","v":"1001","vt":"str"},{"t":"eq","v":"1003","vt":"str"},{"t":"eq","v":"2001","vt":"str"},{"t":"eq","v":"2003","vt":"str"},{"t":"eq","v":"1002","vt":"str"},{"t":"eq","v":"2002","vt":"str"}],"checkall":"true","repair":false,"outputs":6,"x":450,"y":340,"wires":[["402c0364.7fd79c"],["402c0364.7fd79c"],["402c0364.7fd79c"],["402c0364.7fd79c"],["bf33353a.6088e8"],["b6b43fc9.fd6f5"]]},{"id":"402c0364.7fd79c","type":"function","z":"86a3d213.f8fed","name":"set params","func":"if (msg.payload.state.buttonevent === 1001 || msg.payload.state.buttonevent === 2001) {\n   global.set('livingroom/practical/dim', true);\n} else {\n   global.set('livingroom/practical/dim', false);\n}\n\nglobal.set('livingroom/practical/buttonevent', msg.payload.state.buttonevent);\n\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":320,"wires":[["6210f94d.508418"]]},{"id":"6210f94d.508418","type":"mqtt out","z":"86a3d213.f8fed","name":"","topic":"home/livingroom/practical/lights/dim","qos":"2","retain":"","broker":"2fccef58.45c9c","x":900,"y":300,"wires":[]},{"id":"bf33353a.6088e8","type":"mqtt out","z":"86a3d213.f8fed","name":"","topic":"home/livingroom/corner/lights/toggle","qos":"2","retain":"","broker":"2fccef58.45c9c","x":910,"y":360,"wires":[]},{"id":"5bf1fee2.9d731","type":"comment","z":"86a3d213.f8fed","name":"bedroom / desk","info":"","x":480,"y":80,"wires":[]},{"id":"8df3dc43.5bec3","type":"comment","z":"86a3d213.f8fed","name":"living room / cozy","info":"","x":480,"y":280,"wires":[]},{"id":"b6b43fc9.fd6f5","type":"mqtt out","z":"86a3d213.f8fed","name":"","topic":"home/livingroom/practial/lights/toggle","qos":"","retain":"","broker":"2fccef58.45c9c","x":910,"y":420,"wires":[]},{"id":"165d7381.2fb31c","type":"comment","z":"86a3d213.f8fed","name":"Eventlistener","info":"","x":90,"y":460,"wires":[]},{"id":"99e8dafd.9c8358","type":"comment","z":"86a3d213.f8fed","name":"ID","info":"12 - Skrivbordslampa\n3  - Mysbelysning i vardagsrummet\n14 - Mysbelysning i vardagsrummet\n13 - Garderob i vardagsrummet\n8  - Matsal, spotlights","x":250,"y":440,"wires":[]},{"id":"a39df0e7.e68b2","type":"switch","z":"86a3d213.f8fed","name":"","property":"payload.state.buttonevent","propertyType":"msg","rules":[{"t":"eq","v":"1001","vt":"str"},{"t":"eq","v":"1003","vt":"str"},{"t":"eq","v":"2001","vt":"str"},{"t":"eq","v":"2003","vt":"str"},{"t":"eq","v":"1002","vt":"str"},{"t":"eq","v":"2002","vt":"str"}],"checkall":"true","repair":false,"outputs":6,"x":450,"y":580,"wires":[["37ef223f.c1425e"],["37ef223f.c1425e"],["37ef223f.c1425e"],["37ef223f.c1425e"],["94bbe3fc.b0c23"],["94bbe3fc.b0c23"]]},{"id":"37ef223f.c1425e","type":"function","z":"86a3d213.f8fed","name":"set params","func":"if (msg.payload.state.buttonevent === 1001 || msg.payload.state.buttonevent === 2001) {\n   global.set('livingroom/closet/dim', true);\n} else {\n   global.set('livingroom/closet/dim', false);\n}\n\nglobal.set('livingroom/closet/buttonevent', msg.payload.state.buttonevent);\n\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":560,"wires":[["5d764b92.ac30a4"]]},{"id":"5d764b92.ac30a4","type":"mqtt out","z":"86a3d213.f8fed","name":"","topic":"home/livingroom/closet/lights/dim","qos":"2","retain":"","broker":"2fccef58.45c9c","x":900,"y":540,"wires":[]},{"id":"94bbe3fc.b0c23","type":"mqtt out","z":"86a3d213.f8fed","name":"","topic":"home/livingroom/closet/lights/toggle","qos":"2","retain":"","broker":"2fccef58.45c9c","x":900,"y":600,"wires":[]},{"id":"2a00f7c8.7075d8","type":"comment","z":"86a3d213.f8fed","name":"living room / closet","info":"","x":490,"y":520,"wires":[]},{"id":"b2ebeb9c.3fc468","type":"switch","z":"86a3d213.f8fed","name":"","property":"payload.state.buttonevent","propertyType":"msg","rules":[{"t":"eq","v":"3001","vt":"str"},{"t":"eq","v":"3003","vt":"str"},{"t":"eq","v":"2001","vt":"str"},{"t":"eq","v":"2003","vt":"str"},{"t":"eq","v":"1002","vt":"str"},{"t":"eq","v":"4002","vt":"str"},{"t":"eq","v":"5002","vt":"str"}],"checkall":"true","repair":false,"outputs":7,"x":450,"y":760,"wires":[["fa16d093.65cca"],["fa16d093.65cca"],["fa16d093.65cca"],["fa16d093.65cca"],["3758cde9.e02c22"],["23ec2f08.cfe1e"],["23ec2f08.cfe1e"]]},{"id":"fa16d093.65cca","type":"function","z":"86a3d213.f8fed","name":"set params","func":"if (msg.payload.state.buttonevent === 2001 || msg.payload.state.buttonevent === 3001) {\n   global.set('diningroom/spotligts/dim', true);\n} else {\n   global.set('diningroom/spotligts/dim', false);\n}\n\nglobal.set('diningroom/spotligts/buttonevent', msg.payload.state.buttonevent);\n\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":740,"wires":[["39c5bee3.377d92"]]},{"id":"39c5bee3.377d92","type":"mqtt out","z":"86a3d213.f8fed","name":"","topic":"home/diningroom/spot/lights/dim","qos":"2","retain":"","broker":"2fccef58.45c9c","x":890,"y":720,"wires":[]},{"id":"3758cde9.e02c22","type":"mqtt out","z":"86a3d213.f8fed","name":"","topic":"home/diningroom/spot/lights/toggle","qos":"2","retain":"","broker":"2fccef58.45c9c","x":900,"y":780,"wires":[]},{"id":"1fdf9c23.65f134","type":"comment","z":"86a3d213.f8fed","name":"dining room / spotligts","info":"","x":500,"y":700,"wires":[]},{"id":"23ec2f08.cfe1e","type":"mqtt out","z":"86a3d213.f8fed","name":"","topic":"home/diningroom/spot/lights/fastdim","qos":"2","retain":"","broker":"2fccef58.45c9c","x":910,"y":840,"wires":[]},{"id":"23bf38f1.10d1b8","type":"deconz-server","z":"","name":"Phoscon-GW","ip":"192.168.1.2","port":"666","apikey":"C1AA02E1AC","ws_port":"8080","secure":false,"polling":"15"},{"id":"2fccef58.45c9c","type":"mqtt-broker","z":"","name":"mqtt","broker":"192.168.1.2","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

A light witht two bulbs in it:

[{"id":"526d5e40.823a1","type":"tab","label":"Bedroom","disabled":false,"info":""},{"id":"c27b6e59.3e5d2","type":"mqtt in","z":"526d5e40.823a1","name":"","topic":"home/bedroom/desk/lights/dim","qos":"2","datatype":"auto","broker":"2fccef58.45c9c","x":170,"y":120,"wires":[["c740dd5c.355c8"]]},{"id":"c740dd5c.355c8","type":"json","z":"526d5e40.823a1","name":"","property":"payload","action":"","pretty":false,"x":390,"y":120,"wires":[["744eb043.55245"]]},{"id":"5c3a632.dbbeb9c","type":"while-loop","z":"526d5e40.823a1","name":"","condi":"msg.dim === true","x":710,"y":120,"wires":[[],["73be2541.bc25ec"]]},{"id":"b506116f.8775b","type":"api-current-state","z":"526d5e40.823a1","name":"current brightness 1","server":"c942ff9c.138c3","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.sovrum_skrivbord_1","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":200,"y":200,"wires":[["865f50d3.97dd2"]]},{"id":"2bc1da26.c27166","type":"function","z":"526d5e40.823a1","name":"brightness","func":"let brightness;\n\nif (global.get('bedroom/desk/buttonevent') === 1001) {\n    brightness = msg.data.attributes.brightness + 5;    \n} else if (global.get('bedroom/desk/buttonevent') === 2001) {\n    brightness = msg.data.attributes.brightness - 5;    \n}\n\nif (brightness <= 0) {\n    brightness = 1;\n} else if (brightness >= 255) {\n    brightness = 255;\n}\n\nlet payloadAttribute = msg.payload;\n\nmsg.payload = {};\nmsg.payload['state'] = payloadAttribute;\nmsg.payload['data'] = {};\nmsg.payload['data']['brightness'] = brightness;\n\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":200,"wires":[["46a7236b.aede9c"]]},{"id":"46a7236b.aede9c","type":"api-call-service","z":"526d5e40.823a1","name":"dim","server":"c942ff9c.138c3","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.sovrum_skrivbord_1","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":670,"y":200,"wires":[["1a8c1367.d6eb9d"]]},{"id":"865f50d3.97dd2","type":"switch","z":"526d5e40.823a1","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":370,"y":200,"wires":[["2bc1da26.c27166"]]},{"id":"1a8c1367.d6eb9d","type":"delay","z":"526d5e40.823a1","name":"","pauseType":"delay","timeout":"0","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":810,"y":200,"wires":[["84355e4.626efa"]]},{"id":"744eb043.55245","type":"function","z":"526d5e40.823a1","name":"","func":"msg.dim = global.get('bedroom/desk/dim');\nreturn msg;","outputs":1,"noerr":0,"x":530,"y":120,"wires":[["5c3a632.dbbeb9c"]]},{"id":"73be2541.bc25ec","type":"link out","z":"526d5e40.823a1","name":"to dimmer","links":["b182e851.4ec138"],"x":855,"y":120,"wires":[]},{"id":"b182e851.4ec138","type":"link in","z":"526d5e40.823a1","name":"","links":["73be2541.bc25ec"],"x":55,"y":200,"wires":[["b506116f.8775b"]]},{"id":"84355e4.626efa","type":"link out","z":"526d5e40.823a1","name":"to dimmer repeat","links":["7799c15c.eb52b"],"x":935,"y":200,"wires":[]},{"id":"acb9de26.c7a72","type":"link in","z":"526d5e40.823a1","name":"","links":["818949b9.8267e8","9103d637.207608"],"x":415,"y":160,"wires":[["744eb043.55245"]]},{"id":"ba4e32c6.41f84","type":"comment","z":"526d5e40.823a1","name":"Sovrum, skrivbordslampa","info":"","x":150,"y":40,"wires":[]},{"id":"7a85c5e0.e4a4dc","type":"api-call-service","z":"526d5e40.823a1","name":"Sovrum, skrivbordslampa, ON/OFF","server":"c942ff9c.138c3","version":1,"debugenabled":false,"service_domain":"light","service":"toggle","entityId":"light.sovrum_skrivbord","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":580,"y":400,"wires":[[]]},{"id":"b3216c26.4eee4","type":"comment","z":"526d5e40.823a1","name":"Dimma","info":"","x":90,"y":80,"wires":[]},{"id":"ff269cfa.61d84","type":"comment","z":"526d5e40.823a1","name":"On/Off","info":"","x":90,"y":360,"wires":[]},{"id":"9714d79c.81f578","type":"mqtt in","z":"526d5e40.823a1","name":"","topic":"home/bedroom/desk/lights/toggle","qos":"2","datatype":"auto","broker":"2fccef58.45c9c","x":170,"y":400,"wires":[["1a745bfe.025374"]]},{"id":"1a745bfe.025374","type":"json","z":"526d5e40.823a1","name":"","property":"payload","action":"","pretty":false,"x":370,"y":400,"wires":[["7a85c5e0.e4a4dc"]]},{"id":"f2736861.5b2998","type":"api-current-state","z":"526d5e40.823a1","name":"current brightness 2","server":"c942ff9c.138c3","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.sovrum_skrivbord_2","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":200,"y":260,"wires":[["246a3521.e476da"]]},{"id":"3af05378.63123c","type":"function","z":"526d5e40.823a1","name":"brightness","func":"let brightness;\n\nif (global.get('bedroom/desk/buttonevent') === 1001) {\n    brightness = msg.data.attributes.brightness + 5;    \n} else if (global.get('bedroom/desk/buttonevent') === 2001) {\n    brightness = msg.data.attributes.brightness - 5;    \n}\n\nif (brightness <= 0) {\n    brightness = 1;\n} else if (brightness >= 255) {\n    brightness = 255;\n}\n\nlet payloadAttribute = msg.payload;\n\nmsg.payload = {};\nmsg.payload['state'] = payloadAttribute;\nmsg.payload['data'] = {};\nmsg.payload['data']['brightness'] = brightness;\n\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":260,"wires":[["8e1e4c8d.ac095"]]},{"id":"8e1e4c8d.ac095","type":"api-call-service","z":"526d5e40.823a1","name":"dim","server":"c942ff9c.138c3","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.sovrum_skrivbord_2","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":670,"y":260,"wires":[["fdc2eeaf.6fc17"]]},{"id":"246a3521.e476da","type":"switch","z":"526d5e40.823a1","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":370,"y":260,"wires":[["3af05378.63123c"]]},{"id":"fdc2eeaf.6fc17","type":"delay","z":"526d5e40.823a1","name":"","pauseType":"delay","timeout":"25","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":810,"y":260,"wires":[["9103d637.207608"]]},{"id":"7799c15c.eb52b","type":"link in","z":"526d5e40.823a1","name":"","links":["84355e4.626efa"],"x":55,"y":260,"wires":[["f2736861.5b2998"]]},{"id":"9103d637.207608","type":"link out","z":"526d5e40.823a1","name":"to dimmer repeat","links":["acb9de26.c7a72"],"x":935,"y":260,"wires":[]},{"id":"2fccef58.45c9c","type":"mqtt-broker","z":"","name":"mqtt","broker":"192.168.1.2","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"c942ff9c.138c3","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Feel free to ask away and comment :slight_smile:

Some parts are in swedish. Sorry about that. Hope you can figure out what's what :smiley:

moved to #share-your-projects

You also for your flow to be importable you need to wrap your flow in ```

Like so? :slight_smile:

Unfortunately not.Please read the following post How to share code or flow json and then edit the above message.

Now it looks correct (i think)!
Thanks for pointing me in the right direction :slight_smile: