HI,
Sharing my findings instructions covering using the IKEA On/OFF switch for
- Deconz Integration
- Use of the 6 possible actions of this button
- Toggle off/Action
- 2, 3, 4, 5 etc clicks to derive action
- Colour Loop (can be used for brightness)
Don’t be scared of the following - I’ll go in step by step
Getting the switch to work
- This is assuming you have paired it in Deconz
In Node Red - you need the node “node-red-contrib-deconz”
- Top right icon in Node-red, then “Manage Palette”, then swich to “Install” search “contrib-deconz” and install
We will use the node in (It will show as “deconz-input”
- First you need to configure the server
- Click on the pen beside server
- Put the IP address of your deconz (for me it’s the home assistant IP)
- Port: 40850
- skip API key for now
- Websocket port 8081
- leave rest as is.
- Go to your deconz “phoscon” in another browser window
- Top left menu > gateway > Advanced > Authenticate App
- Go back to Node-red and hit the “Get Settings”
- It should auto-populate the “API Key”. Update - and deploy node
- You can see if it works if there’s a green dot under the “deconz-input” node
- Editing this node, you should now be able to select your switch
- ** This was a nightmare for me. I got it to work with this solution
This was (hopefully) the most complicated part…
The 6 Actions possible
[{"id":"2a731f63.cb77c","type":"inject","z":"cbd6d85d.24f998","name":"ON - Click - Single","props":[{"p":"payload.buttonevent","v":"1002","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":190,"y":840,"wires":[["2562c3b8.d8088c"]]},{"id":"ae8eab08.f26fe8","type":"inject","z":"cbd6d85d.24f998","name":"ON - Click - Hold","props":[{"p":"payload.buttonevent","v":"1001","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":180,"y":880,"wires":[["2562c3b8.d8088c"]]},{"id":"9c229162.c6901","type":"inject","z":"cbd6d85d.24f998","name":"ON - Release - (After Long Hold)","props":[{"p":"payload.buttonevent","v":"1003","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":230,"y":920,"wires":[["2562c3b8.d8088c"]]},{"id":"26029b92.c88d84","type":"inject","z":"cbd6d85d.24f998","name":"OFF - Release - (After Long Hold)","props":[{"p":"payload.buttonevent","v":"2003","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":240,"y":1060,"wires":[["2562c3b8.d8088c"]]},{"id":"4fd7f4d3.0f1bfc","type":"inject","z":"cbd6d85d.24f998","name":"OFF - Click - Hold","props":[{"p":"payload.buttonevent","v":"2001","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":190,"y":1020,"wires":[["2562c3b8.d8088c"]]},{"id":"52857a77.4dbe14","type":"inject","z":"cbd6d85d.24f998","name":"OFF - Click - Single","props":[{"p":"payload.buttonevent","v":"2002","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":190,"y":980,"wires":[["2562c3b8.d8088c"]]},{"id":"41dd1ffd.bb468","type":"comment","z":"cbd6d85d.24f998","name":"Simulation ON/OFF switch","info":"","x":170,"y":800,"wires":[]},{"id":"2562c3b8.d8088c","type":"switch","z":"cbd6d85d.24f998","name":"Ikea on/off codes","property":"payload.buttonevent","propertyType":"msg","rules":[{"t":"eq","v":"1002","vt":"str"},{"t":"eq","v":"1001","vt":"str"},{"t":"eq","v":"1003","vt":"str"},{"t":"eq","v":"2002","vt":"str"},{"t":"eq","v":"2001","vt":"str"},{"t":"eq","v":"2003","vt":"str"}],"checkall":"true","repair":false,"outputs":6,"x":550,"y":920,"wires":[["df03dedc.d46d5"],["48c096f9.6e9298"],["ce6e4538.d1f118"],["300f76e2.30c01a"],["77853e3d.dc4a4"],["f5113739.dcb2c8"]],"outputLabels":["Single ON","Long ON","Long ON Release","Single OFF","Long OFF","Long OFF Release"],"info":"1001 long click on\n1002 single click on \n1003 release after long click on\n2001 long click off\n2002 single click off\n2003 release after long click off"},{"id":"fe94bc24.ea75c","type":"comment","z":"cbd6d85d.24f998","name":"Detect and switch","info":"Based on Ikea ON/OFF switch","x":550,"y":840,"wires":[]},{"id":"539fdf31.6e99","type":"deconz-input","z":"cbd6d85d.24f998","name":"Bed Button","server":"84275c62.5cd71","device":"68:0a:e2:ff:fe:78:98:b0-01-1000","device_name":"Lloyd Bed Button : ZHASwitch","topic":"","state":"0","output":"always","outputAtStartup":false,"x":120,"y":760,"wires":[["2562c3b8.d8088c"],[]]},{"id":"84275c62.5cd71","type":"deconz-server","name":"deoconz","ip":"192.168.86.67","port":"40850","apikey":"80F80F1CD0","ws_port":"8081","secure":false,"polling":"15"}]
This is pretty much self explanatory. The deconz-input will send different codes depending on what is pushed.
Useless info: If you didn’t know, the symbol I/O on the button of Ikea is… binary! I = 1 = Open, and O = 0 = Off… This symbol is universal instead of “on/off” which is… in English…
So per each side where you click on the button you can:
- Single Click
- Hold the Click
- Release after long Hold
Very simple example:
- Single Click = Light Toggle
- Hold the Click = keep colors of a lights slowly change until your favourite color comes, then release(next) to stop the change
- Release after long hold: Stop the loop of colors to the one you like
You could stop here and simply use this switch to do automations to your liking. Below are extras that could augment those flows.
Logic to "augment a toggle"
Why? I want to click the same button to either:
- A: Turn off several lights if any of those lights are on
- B: Only turn on one specific light
- (Think bedside lamp “on/off” but also “off” for any other lights in the room
To do this, you “fake” a toggle… Check the sate of “that single lamp”, if on - turn everything off, and then if off, turn only the bed lamp.
[{"id":"432109c8.2fad28","type":"inject","z":"cbd6d85d.24f998","name":"Plug this to your Ikea switch","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":180,"y":1300,"wires":[["aa4f818.d3a838"]]},{"id":"aa4f818.d3a838","type":"api-current-state","z":"cbd6d85d.24f998","name":"Light 1","server":"a0eea9da.0fe1d8","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.light_sleeping_room_1","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":370,"y":1340,"wires":[["a4bfd1bc.4fb97"],["9f384fad.dbfd2"]]},{"id":"9f384fad.dbfd2","type":"api-current-state","z":"cbd6d85d.24f998","name":"light 2","server":"a0eea9da.0fe1d8","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"slee","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":370,"y":1400,"wires":[["a4bfd1bc.4fb97"],["b4635c44.4adec"]]},{"id":"b4635c44.4adec","type":"api-current-state","z":"cbd6d85d.24f998","name":"light 3","server":"a0eea9da.0fe1d8","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.light_sleeping_room_3","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":370,"y":1460,"wires":[["a4bfd1bc.4fb97"],["cd268dcd.2df0b"]]},{"id":"cd268dcd.2df0b","type":"api-current-state","z":"cbd6d85d.24f998","name":"Bed Lamp","server":"a0eea9da.0fe1d8","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.stone_lamp","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":390,"y":1520,"wires":[["a4bfd1bc.4fb97"],["a4bfd1bc.4fb97"]]},{"id":"a4bfd1bc.4fb97","type":"switch","z":"cbd6d85d.24f998","name":"on somewhere?","property":"data.state","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":620,"y":1420,"wires":[["fbcdfdb6.819ce"],["ac9e378.2bd23c8"]]},{"id":"20f2e8dd.bccb38","type":"comment","z":"cbd6d85d.24f998","name":"This creates a \"sensor\"","info":"","x":140,"y":1340,"wires":[]},{"id":"fbcdfdb6.819ce","type":"api-call-service","z":"cbd6d85d.24f998","name":"All lights to OFF","server":"a0eea9da.0fe1d8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.light_sleeping_room_1, light.light_sleeping_room_2, , light.light_sleeping_room_3, , light.stone_lamp","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":830,"y":1380,"wires":[[]]},{"id":"ac9e378.2bd23c8","type":"api-call-service","z":"cbd6d85d.24f998","name":"Only Bed Light ON","server":"a0eea9da.0fe1d8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.stone_lamp","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":830,"y":1440,"wires":[[]]},{"id":"a0eea9da.0fe1d8","type":"server","name":"Home Assistant New","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
More with your switch with multiple clicks
- Single click = action 1
- Double Click = action 2
- Tripple Click = action 3
- Any more than that = action 4
- (You can make it ten clicks if you’re that kind of person - but remember, it’s “within a certain time”
And this can be applies both to the “on” button and to the “off” button of the Ikea Switch
[{"id":"3d629236.f811ee","type":"inject","z":"cbd6d85d.24f998","name":"Plug this to your Ikea switch","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":180,"y":1640,"wires":[["93b8e5d2.9b3958"]]},{"id":"93b8e5d2.9b3958","type":"function","z":"cbd6d85d.24f998","name":"Start Counting","func":"const arr = Array.from(Array(msg.payload), _ => msg);\nreturn [arr];","outputs":1,"noerr":0,"initialize":"","finalize":"","x":420,"y":1640,"wires":[["d9d8a08e.b82c3"]]},{"id":"d9d8a08e.b82c3","type":"function","z":"cbd6d85d.24f998","name":"Until...","func":"const timeout = 2000;\nlet count = context.get(\"count\") || 0;\nif(count === 0) {\n setTimeout(() => {\n node.status({});\n msg.count = context.get(\"count\") || 0;\n context.set(\"count\", 0);\n node.send(msg);\n }, timeout);\n}\ncontext.set(\"count\", ++count);\nnode.status({text: count});","outputs":1,"noerr":0,"initialize":"","finalize":"","x":450,"y":1680,"wires":[["943699bd.19bd28"]]},{"id":"943699bd.19bd28","type":"switch","z":"cbd6d85d.24f998","name":"1,2,3 or more clicks","property":"count","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"},{"t":"eq","v":"3","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":4,"x":630,"y":1660,"wires":[["e64fcf57.5d519"],["ef72c69c.c3cfa8"],["ebe408e8.bd5998"],["d427b705.049b18"]]},{"id":"e64fcf57.5d519","type":"api-call-service","z":"cbd6d85d.24f998","name":"Stone ON","server":"a0eea9da.0fe1d8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.stone_lamp","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":840,"y":1600,"wires":[[]]},{"id":"ef72c69c.c3cfa8","type":"api-call-service","z":"cbd6d85d.24f998","name":"sleepin ON (Dim)","server":"a0eea9da.0fe1d8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.sleeping_room","data":"{\"brightness_pct\":\"10\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":870,"y":1640,"wires":[[]]},{"id":"ebe408e8.bd5998","type":"api-call-service","z":"cbd6d85d.24f998","name":"sleepin ON (bright)","server":"a0eea9da.0fe1d8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.sleeping_room","data":"{\"brightness_pct\":\"100\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":870,"y":1680,"wires":[[]]},{"id":"d427b705.049b18","type":"api-call-service","z":"cbd6d85d.24f998","name":"More clicks - turn everything off","server":"a0eea9da.0fe1d8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.sleeping_room","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":910,"y":1720,"wires":[[]]},{"id":"a0eea9da.0fe1d8","type":"server","name":"Home Assistant New","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
The only thing you need to edit in the function nodes is the one called “until” if you want to change the timer (number of clicks within… 2 seconds). The code has 2000 milliseconds (2sec) so change to your liking. Test how quick you click… That’s why “10 clicks” starts to be a bit crazy. If you make it too slow, you will need to wait until it triggers.
Color Loop when holding a button pressed
You hold a button, the color loops, when you release the button, the color stops at the last color.
[{"id":"9cfbb638.d62368","type":"switch","z":"cbd6d85d.24f998","name":"Ikea on/off codes","property":"payload.buttonevent","propertyType":"msg","rules":[{"t":"eq","v":"1002","vt":"str"},{"t":"eq","v":"1001","vt":"str"},{"t":"eq","v":"1003","vt":"str"},{"t":"eq","v":"2002","vt":"str"},{"t":"eq","v":"2001","vt":"str"},{"t":"eq","v":"2003","vt":"str"}],"checkall":"true","repair":false,"outputs":6,"x":170,"y":1940,"wires":[[],["3e04f87d.8a79f8"],["2d43a3d2.4ea01c"],[],[],[]],"outputLabels":["Single ON","Long ON","Long ON Release","Single OFF","Long OFF","Long OFF Release"],"info":"1001 long click on\n1002 single click on \n1003 release after long click on\n2001 long click off\n2002 single click off\n2003 release after long click off"},{"id":"2d43a3d2.4ea01c","type":"change","z":"cbd6d85d.24f998","name":"Stop Color loop","rules":[{"t":"set","p":"stopcall","pt":"flow","to":"yes","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":1980,"wires":[["eabb43f4.0d68a"]]},{"id":"3e04f87d.8a79f8","type":"change","z":"cbd6d85d.24f998","name":"Color loop ON","rules":[{"t":"set","p":"stopcall","pt":"flow","to":"no","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":1860,"wires":[["eabb43f4.0d68a"]]},{"id":"eabb43f4.0d68a","type":"function","z":"cbd6d85d.24f998","name":"set var","func":"flow.set(\"i\", 0);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":490,"y":1900,"wires":[["2c906fa7.696c"]]},{"id":"1561ad84.a79722","type":"delay","z":"cbd6d85d.24f998","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":660,"y":1960,"wires":[["2c906fa7.696c"]]},{"id":"2c906fa7.696c","type":"function","z":"cbd6d85d.24f998","name":"change rgb","func":"var i = flow.get(\"i\");\nvar red = Math.round(Math.sin(0.3*i + 0) * 127 + 128);\nvar green = Math.round(Math.sin(0.3*i + 2) * 127 + 128);\nvar blue = Math.round(Math.sin(0.3*i + 4) * 127 + 128);\n\ni++;\nif (i>=32) {\n i = 0;\n}\n\nflow.set(\"i\", i);\n\nmsg.payload = {};\nmsg.payload.data = {};\nmsg.payload.data.rgb_color = \"[\" + red + \", \" + green + \", \" + blue + \"]\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":670,"y":1900,"wires":[["1561ad84.a79722","cf350b79.40bea8"]]},{"id":"5f22a4ce.47d18c","type":"switch","z":"cbd6d85d.24f998","name":"","property":"stopcall","propertyType":"flow","rules":[{"t":"eq","v":"no","vt":"str"},{"t":"eq","v":"yes","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":910,"y":1940,"wires":[["2c21cbb.5bfa034"],["90d86602.0e2aa8"]]},{"id":"cf350b79.40bea8","type":"template","z":"cbd6d85d.24f998","name":"admin","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{ \"data\": {\"entity_id\" : \"light.20334154d8bfc01379ff\", \"rgb_color\" : {{payload.data.rgb_color}} }}","output":"str","x":850,"y":1880,"wires":[["5f22a4ce.47d18c"]],"icon":"node-red-contrib-color-convert/color-convert.png"},{"id":"90d86602.0e2aa8","type":"change","z":"cbd6d85d.24f998","name":"stop call","rules":[{"t":"set","p":"stopcall","pt":"flow","to":"neutral","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1060,"y":1980,"wires":[[]]},{"id":"2c21cbb.5bfa034","type":"api-call-service","z":"cbd6d85d.24f998","name":"Cycle","server":"a0eea9da.0fe1d8","version":1,"debugenabled":false,"service_domain":"homeassistant","service":"turn_on","entityId":"","data":"{}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1070,"y":1900,"wires":[[]]},{"id":"813f0226.c9242","type":"comment","z":"cbd6d85d.24f998","name":"Hold to trigger color loop","info":"","x":150,"y":1860,"wires":[]},{"id":"a0eea9da.0fe1d8","type":"server","name":"Home Assistant New","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
Ok, this one was coded with the help of another use (I am useless in coding…).
- You need to use the “long hold button pressed” and “stop after long hold button pressed” switches for this one.
- You need to edit your light entity id in the code as shown in the screenshot. Make sure you only replace between the quotes - replace “light.20334154d8bfc01379ff” by “light.yourownlight”