IKEA TRADFRI Smart Socket in NodeRED

enter image description here Free your IKEA TRADFRI Smart Socket! Add custom interface, unlimited timers, remote access, Alexa and Google Assistant intergration! There is no reason to keep using IKEA app when you can do so much more!

Features:

  • Alexa & Google Assistant compatible
  • Works on LAN only
  • Recovery of timers on reboot|restart
  • Unlimited timers
  • Dashboard Timers
  • Day of the week support
  • Online status of each timer
  • Easy integration with Home Assistant

You will need the following nodes:

  • node-red-contrib-alexa-home-skill
  • node-red-contrib-schedex
  • node-red-dashboard

Settings

  • **TimerNumber ** Unique Timer ID
  • PayloadON Payload sent when timer hits ON
  • PayloadOFF Payload sent when timer hits OFF

More about me:

If you want to get the latest updates to this project you can follow me via your preferred social media:

And if you feeling like buying me a coffee or supporting me in a more continuous way:

I hope you have enjoyed the project!

[{"id":"3abe8c84.455934","type":"subflow","name":"Timer Settings","info":"","category":"","in":[{"x":500,"y":320,"wires":[{"id":"1a38f6a5.cd4c29"}]}],"out":[{"x":740,"y":320,"wires":[{"id":"1a38f6a5.cd4c29","port":0}]}],"env":[{"name":"TimerNumber","type":"num","value":""},{"name":"PayloadON","type":"str","value":""},{"name":"PayloadOFF","type":"str","value":""}],"color":"#DDAA99"},{"id":"1a38f6a5.cd4c29","type":"function","z":"3abe8c84.455934","name":"","func":"var x = env.get(\"TimerNumber\"); \nvar y = env.get(\"PayloadON\"); \nvar z = env.get(\"PayloadOFF\"); \n\nflow.set(\"$parent.Timer\"+x, x);\nflow.set(\"$parent.Payload\"+x+\"_on\", y);\nflow.set(\"$parent.Payload\"+x+\"_off\", z);\n\n\n\nmsg.payload = \"Your timer \" + x + \" has been set\";\n\nreturn msg;\n","outputs":1,"noerr":0,"x":600,"y":320,"wires":[[]]},{"id":"63ccbb05.50e244","type":"tab","label":"IKEA Tradfri Socket in NodeRED","disabled":false,"info":"\n![enter image description here](https://notenoughtech.com/wp-content/uploads/2019/11/maxresdefault-3-640x360.jpg)\nFree your IKEA TRADFRI Smart Socket! Add custom interface, unlimited timers, remote access, Alexa and Google Assistant intergration! There is no reason to keep using IKEA app when you can do so much more!\n\n - [Complete instruction](https://notenoughtech.com/featured/the-coolest-heatsink-for-raspberry-pi-4/)\n\n\n**Features**:\n-   Alexa & Google Assistant compatible\n-   Works on LAN only\n-   Recovery of timers on reboot|restart\n-   Unlimited timers\n-   Dashboard Timers\n-   Day of the week support\n-   Online status of each timer\n-   Easy integration with Home Assistant\n\nYou will need the following nodes:\n\n - node-red-contrib-alexa-home-skill\n - node-red-contrib-schedex  \n - node-red-dashboard\n\n# Settings\n\n - **TimerNumber ** Unique Timer ID\n - **PayloadON** Payload  sent when timer hits ON\n - **PayloadOFF** Payload  sent when timer hits OFF\n "},{"id":"8311b366.9b52e","type":"mqtt in","z":"63ccbb05.50e244","name":"IKEA Smart Socket 1","topic":"zigbee2mqtt/ikeasmartplug1","qos":"1","datatype":"json","broker":"eca6af44.5297b","x":220,"y":280,"wires":[["29d8995e.a33fc6","101e9844.7ccf78"]]},{"id":"5f804662.e98eb8","type":"mqtt out","z":"63ccbb05.50e244","name":"IKEA Smart Plug 1 status","topic":"zigbee2mqtt/ikeasmartplug1/get","qos":"0","retain":"false","broker":"eca6af44.5297b","x":410,"y":140,"wires":[]},{"id":"4c2aa51b.94e12c","type":"inject","z":"63ccbb05.50e244","name":"","topic":"","payload":"{\"state\":\"\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":140,"wires":[["5f804662.e98eb8"]]},{"id":"5adf8879.e79d78","type":"ui_text","z":"63ccbb05.50e244","group":"9ab1ead6.da5a58","order":3,"width":"6","height":"1","name":"IKEA State","label":"Current State","format":"<font color= {{msg.color}} > {{msg.payload}} </font>","layout":"row-spread","x":820,"y":260,"wires":[]},{"id":"769df1e8.6a8a2","type":"function","z":"63ccbb05.50e244","name":"Format colours","func":"switch (msg.payload.state) {\n\ncase \"ON\" : \n    msg.color = \"green\";\n    msg.payload = \"ON\";\n    break;\n    \ncase \"OFF\" : \n    msg.color = \"red\";\n    msg.payload = \"OFF\";\n    break;\n    \ndefault : \n    msg.color = \"black\";\n    msg.payload = \"not updated\";\n    break;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":610,"y":280,"wires":[["5adf8879.e79d78","238c2fe2.ede93"]]},{"id":"238c2fe2.ede93","type":"ui_toast","z":"63ccbb05.50e244","position":"top right","displayTime":"3","highlight":"","sendall":true,"outputs":0,"ok":"OK","cancel":"","topic":"IKEA Socket set to","name":"","x":820,"y":320,"wires":[]},{"id":"29d8995e.a33fc6","type":"delay","z":"63ccbb05.50e244","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":420,"y":280,"wires":[["769df1e8.6a8a2","b9982a28.a5ca18"]]},{"id":"3cf0a531.fd30aa","type":"comment","z":"63ccbb05.50e244","name":"Force status update","info":"","x":210,"y":100,"wires":[]},{"id":"4f2bb0d5.9cfd9","type":"comment","z":"63ccbb05.50e244","name":"Display status ","info":"","x":170,"y":240,"wires":[]},{"id":"86b15bd4.7fb1c8","type":"ui_template","z":"63ccbb05.50e244","group":"9ab1ead6.da5a58","name":"","order":1,"width":"6","height":"6","format":"<img src=\"https://www.ikea.com/PIAimages/0515596_PE640308_S5.JPG?f=s\" style=\"width:250px;height:300px;\">    \n    \n    \n","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":180,"y":360,"wires":[[]]},{"id":"101e9844.7ccf78","type":"debug","z":"63ccbb05.50e244","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":410,"y":220,"wires":[]},{"id":"b0f4a96f.32c548","type":"alexa-home","z":"63ccbb05.50e244","conf":"4ec600a6.406ae","device":"68301","acknoledge":true,"name":"Bench","topic":"","x":190,"y":700,"wires":[["f5e6115c.d80ba"]]},{"id":"25a98cff.816ec4","type":"mqtt out","z":"63ccbb05.50e244","name":"gBridge Update","topic":"gBridge/u2491/IKEA/onoff/set","qos":"","retain":"","broker":"c4b43ba4.186ae8","x":820,"y":520,"wires":[]},{"id":"6b3f6beb.bc8444","type":"mqtt in","z":"63ccbb05.50e244","name":"IKEA Socket","topic":"gBridge/u2491/IKEA/onoff","qos":"0","datatype":"auto","broker":"c4b43ba4.186ae8","x":190,"y":560,"wires":[["94896e12.7826f"]]},{"id":"b30240de.63c5f","type":"comment","z":"63ccbb05.50e244","name":"Google Assistant","info":"","x":180,"y":520,"wires":[]},{"id":"740ebf3b.55b69","type":"comment","z":"63ccbb05.50e244","name":"Alexa","info":"","x":150,"y":660,"wires":[]},{"id":"b9982a28.a5ca18","type":"change","z":"63ccbb05.50e244","name":"Modify Payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.state","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":520,"wires":[["25a98cff.816ec4"]]},{"id":"881a634b.9afa3","type":"ui_switch","z":"63ccbb05.50e244","name":"Socket Switch","label":"Socket","tooltip":"","group":"9ab1ead6.da5a58","order":4,"width":"6","height":"1","passthru":true,"decouple":"false","topic":"","style":"","onvalue":"ON","onvalueType":"str","onicon":"","oncolor":"","offvalue":"OFF","offvalueType":"str","officon":"","offcolor":"","x":200,"y":420,"wires":[["e18c35d.5dfd0c8"]]},{"id":"f5e6115c.d80ba","type":"function","z":"63ccbb05.50e244","name":"Switch (Alexa)","func":"var x = msg.payload;\n\nif(x === true){\n    msg.payload = \"ON\";\n    return [msg, null];\n}\n\nif(x === false){\n    msg.payload = \"OFF\";\n    return [null, msg];\n}\n\n","outputs":2,"noerr":0,"x":400,"y":700,"wires":[["2d1cca8d.decaf6"],["2d1cca8d.decaf6"]]},{"id":"2d1cca8d.decaf6","type":"mqtt out","z":"63ccbb05.50e244","name":"IKEA Smart Plug 1","topic":"zigbee2mqtt/ikeasmartplug1/set","qos":"0","retain":"false","broker":"eca6af44.5297b","x":730,"y":700,"wires":[]},{"id":"94896e12.7826f","type":"function","z":"63ccbb05.50e244","name":"Switch (gBridge)","func":"var x = msg.payload;\n\nif(x === 1){\n    msg.payload = \"ON\";\n    return [msg, null];\n}\n\nif(x === 0){\n    msg.payload = \"OFF\";\n    return [null, msg];\n}\n\n","outputs":2,"noerr":0,"x":400,"y":560,"wires":[["1e068661.fce2ea"],["1e068661.fce2ea"]]},{"id":"1e068661.fce2ea","type":"mqtt out","z":"63ccbb05.50e244","name":"IKEA Smart Plug 1","topic":"zigbee2mqtt/ikeasmartplug1/set","qos":"0","retain":"false","broker":"eca6af44.5297b","x":830,"y":580,"wires":[]},{"id":"e18c35d.5dfd0c8","type":"mqtt out","z":"63ccbb05.50e244","name":"IKEA Smart Plug 1","topic":"zigbee2mqtt/ikeasmartplug1/set","qos":"0","retain":"false","broker":"eca6af44.5297b","x":430,"y":420,"wires":[]},{"id":"469e2a9f.ebd014","type":"comment","z":"63ccbb05.50e244","name":"Timer 1","info":"","x":150,"y":780,"wires":[]},{"id":"ea4d225.34516e","type":"schedex","z":"63ccbb05.50e244","name":"Timer","suspended":false,"lat":"54.525671","lon":"-1.3113165","ontime":"","ontopic":"","onpayload":"","onoffset":"","onrandomoffset":0,"offtime":"","offtopic":"","offpayload":"","offoffset":"","offrandomoffset":0,"mon":false,"tue":false,"wed":false,"thu":false,"fri":false,"sat":false,"sun":false,"x":1270,"y":1240,"wires":[["3022c9e5.353766","8b5e0830.c6e6e8"]]},{"id":"d58cc919.dea4e8","type":"ui_text_input","z":"63ccbb05.50e244","name":"T2 On","label":"","tooltip":"","group":"9ab1ead6.da5a58","order":6,"width":"4","height":"1","passthru":false,"mode":"time","delay":"0","topic":"Ton","x":570,"y":1020,"wires":[["6669cbe2.a15c14"]]},{"id":"6c7c2b6f.3c3fb4","type":"ui_button","z":"63ccbb05.50e244","name":"Set ON","group":"9ab1ead6.da5a58","order":9,"width":"2","height":"1","passthru":false,"label":"{{msg.topic}}","tooltip":"","color":"","bgcolor":"{{msg.color}}","icon":"","payload":"","payloadType":"str","topic":"buttonON","x":960,"y":960,"wires":[["78a10f9b.5d6dc"]]},{"id":"5a1d9bc8.802d04","type":"ui_text_input","z":"63ccbb05.50e244","name":"T2 Off","label":"","tooltip":"","group":"9ab1ead6.da5a58","order":7,"width":"4","height":"1","passthru":false,"mode":"time","delay":"0","topic":"Toff","x":570,"y":1060,"wires":[["6669cbe2.a15c14"]]},{"id":"f946439e.5689e","type":"ui_button","z":"63ccbb05.50e244","name":"Set OFF","group":"9ab1ead6.da5a58","order":8,"width":"2","height":"1","passthru":false,"label":"{{msg.topic}}","tooltip":"","color":"","bgcolor":"{{msg.color}}","icon":"","payload":"","payloadType":"str","topic":"buttonOFF","x":960,"y":1100,"wires":[["78a10f9b.5d6dc"]]},{"id":"9ed67e7b.7d18e","type":"ui_text","z":"63ccbb05.50e244","group":"9ab1ead6.da5a58","order":2,"width":"6","height":"1","name":"Timer Status","label":"{{msg.topic}}","format":"<font color= {{msg.color}} > {{msg.payload}} </font>","layout":"row-spread","x":1630,"y":1040,"wires":[]},{"id":"9bc1cdd.4e6983","type":"ui_button","z":"63ccbb05.50e244","name":"Reset Button","group":"9ab1ead6.da5a58","order":5,"width":"6","height":"1","passthru":false,"label":"Reset","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":130,"y":1260,"wires":[["3915ad9.85e2c52"]]},{"id":"6669cbe2.a15c14","type":"function","z":"63ccbb05.50e244","name":"Set T2 On","func":"var z = flow.get(\"Timer1\");\n\n//if timer on is set\nif(msg.topic === \"Ton\"){\n    flow.set(\"timer\"+z+\"_on\", msg.payload);\n    msg.color = \"red\";\n    msg.topic = \"Press\";\n    return [msg, null];\n    \n    \n}\n\n//if timer off is set\nif(msg.topic === \"Toff\"){\n    flow.set(\"timer\"+z+\"_off\", msg.payload);\n    msg.color = \"red\";\n    msg.topic = \"Press\";\n    return [null, msg];\n    \n}\n\n// reboot detected\nif(msg.topic === \"reboot\"){\n    msg.color = \"grey\";\n    msg.topic = \"Select Time\";\n    return [msg, msg];\n    \n}","outputs":2,"noerr":0,"x":740,"y":1040,"wires":[["6c7c2b6f.3c3fb4"],["f946439e.5689e"]]},{"id":"3915ad9.85e2c52","type":"function","z":"63ccbb05.50e244","name":"Reset","func":"var z = flow.get(\"Timer1\");\n\nvar timerlabel = \"Timer \"+ z;\nflow.set(\"$parent.timer\"+z+\"_on\", 0);\nflow.set(\"$parent.timer\"+z+\"_off\", 0);\nflow.set(\"$parent.T\"+z+\"on\", null);\nflow.set(\"$parent.T\"+z+\"off\", null);\n\nvar msg1 = {payload: \"Timer \"+z+\" reset\"};\nvar msg2 = {payload: 0};\nvar msg3 = {payload: \"disabled\",\n            topic: timerlabel,\n            color: \"red\"};\nvar msg4 = {color: \"grey\",\n            topic: \"Select Time\",\n};\n\nvar msg5 = {payload:{suspended: true}};\nvar msg6 = {payload: true};\n\nreturn [msg1, msg2, msg3, msg4, msg5, msg6];","outputs":6,"noerr":0,"x":310,"y":1260,"wires":[["2a587b2f.a1e944"],["5a1d9bc8.802d04","d58cc919.dea4e8"],["9ed67e7b.7d18e"],["6c7c2b6f.3c3fb4","f946439e.5689e"],["ea4d225.34516e"],["9fcca1f4.c837c","bb11d04e.ddb9","215f000b.e368e","327ba151.37fcce","35c1f24e.94f31e","a3c0bb49.521648","764270df.9643d"]]},{"id":"9fcca1f4.c837c","type":"ui_switch","z":"63ccbb05.50e244","name":"","label":"Mon","tooltip":"","group":"9ab1ead6.da5a58","order":10,"width":"2","height":"1","passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":570,"y":1300,"wires":[["1b53ef1b.8a8671"]]},{"id":"bb11d04e.ddb9","type":"ui_switch","z":"63ccbb05.50e244","name":"","label":"Tue","tooltip":"","group":"9ab1ead6.da5a58","order":11,"width":"2","height":"1","passthru":true,"decouple":"false","topic":"tue","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":570,"y":1340,"wires":[["bed5740c.ce22a8"]]},{"id":"215f000b.e368e","type":"ui_switch","z":"63ccbb05.50e244","name":"","label":"Wed","tooltip":"","group":"9ab1ead6.da5a58","order":12,"width":"2","height":"1","passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":570,"y":1380,"wires":[["d411c8e3.59f068"]]},{"id":"327ba151.37fcce","type":"ui_switch","z":"63ccbb05.50e244","name":"","label":"Thu","tooltip":"","group":"9ab1ead6.da5a58","order":13,"width":"2","height":"1","passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":570,"y":1420,"wires":[["a0e0a394.a773b"]]},{"id":"35c1f24e.94f31e","type":"ui_switch","z":"63ccbb05.50e244","name":"","label":"Fri","tooltip":"","group":"9ab1ead6.da5a58","order":14,"width":"2","height":"1","passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":570,"y":1460,"wires":[["ba2d679d.fe4008"]]},{"id":"a3c0bb49.521648","type":"ui_switch","z":"63ccbb05.50e244","name":"","label":"Sat","tooltip":"","group":"9ab1ead6.da5a58","order":15,"width":"2","height":"1","passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":570,"y":1500,"wires":[["bb53e943.80ec18"]]},{"id":"1b53ef1b.8a8671","type":"function","z":"63ccbb05.50e244","name":"Mon","func":"var z = flow.get(\"Timer1\");\n\nvar x = msg.payload;\nflow.set(\"Monday\"+z, x);\nmsg.payload = {mon: x};\n\nreturn msg;","outputs":1,"noerr":0,"x":730,"y":1300,"wires":[["ea4d225.34516e"]]},{"id":"bed5740c.ce22a8","type":"function","z":"63ccbb05.50e244","name":"Tue","func":"var z = flow.get(\"Timer1\");\n\nvar x = msg.payload;\nflow.set(\"Tuesday\"+z, x);\nmsg.payload = {tue: x};\n\nreturn msg;","outputs":1,"noerr":0,"x":730,"y":1340,"wires":[["ea4d225.34516e"]]},{"id":"d411c8e3.59f068","type":"function","z":"63ccbb05.50e244","name":"Wed","func":"var z = flow.get(\"Timer1\");\n\nvar x = msg.payload;\nflow.set(\"Wednesday\"+z, x);\nmsg.payload = {wed: x};\n\nreturn msg;","outputs":1,"noerr":0,"x":730,"y":1380,"wires":[["ea4d225.34516e"]]},{"id":"a0e0a394.a773b","type":"function","z":"63ccbb05.50e244","name":"Thu","func":"var z = flow.get(\"Timer1\");\n\nvar x = msg.payload;\nflow.set(\"Thursday\"+z, x);\nmsg.payload = {thu: x};\n\nreturn msg;","outputs":1,"noerr":0,"x":730,"y":1420,"wires":[["ea4d225.34516e"]]},{"id":"ba2d679d.fe4008","type":"function","z":"63ccbb05.50e244","name":"Fri","func":"var z = flow.get(\"Timer1\");\n\n\nvar x = msg.payload;\nflow.set(\"Friday\"+z, x);\nmsg.payload = {fri: x};\n\nreturn msg;","outputs":1,"noerr":0,"x":730,"y":1460,"wires":[["ea4d225.34516e"]]},{"id":"bb53e943.80ec18","type":"function","z":"63ccbb05.50e244","name":"Sat","func":"var z = flow.get(\"Timer1\");\n\n\nvar x = msg.payload;\nflow.set(\"Saturday\"+z, x);\nmsg.payload = {sat: x};\n\nreturn msg;","outputs":1,"noerr":0,"x":730,"y":1500,"wires":[["ea4d225.34516e"]]},{"id":"c4e361b.55226a","type":"function","z":"63ccbb05.50e244","name":"Sun","func":"var z = flow.get(\"Timer1\");\n\n\nvar x = msg.payload;\nflow.set(\"Sunday\"+z, x);\nmsg.payload = {sun: x};\n\nreturn msg;","outputs":1,"noerr":0,"x":730,"y":1540,"wires":[["ea4d225.34516e"]]},{"id":"68daf64.19c9b08","type":"inject","z":"63ccbb05.50e244","name":"","topic":"","payload":"Started!","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":830,"y":1180,"wires":[["2482bc5d.5dbdc4"]]},{"id":"2482bc5d.5dbdc4","type":"function","z":"63ccbb05.50e244","name":"Apply stored values ","func":"var z = flow.get(\"Timer1\");\nvar pon = flow.get(\"Payload\"+z+\"_on\");\nvar poff = flow.get(\"Payload\"+z+\"_off\");\n\n\n// restore days\nvar mon = flow.get(\"Monday\"+z);\nvar tue = flow.get(\"Tuesday\"+z);\nvar wed = flow.get(\"Wednesday\"+z);\nvar thu = flow.get(\"Thursday\"+z);\nvar fri = flow.get(\"Friday\"+z);\nvar sat = flow.get(\"Saturday\"+z);\nvar sun = flow.get(\"Sunday\"+z);\n\n//restore timers\nvar timeON = flow.get(\"T\"+z+\"on\");\nvar timeOFF = flow.get(\"T\"+z+\"off\");\nvar timerlabel = \"Timer \"+ z;\n\n\n\nvar msg1 = {payload: {ontime: \"ontime \" + timeON}, onpayload: pon,};\nvar msg2 = {payload: {offtime: \"offtime \" + timeOFF}, offpayload: poff,};\nvar msg3 = {topic: timerlabel};\nvar msg4 = {payload : { \"mon\": mon,\n                \"tue\": tue,\n                \"wed\": wed,\n                \"thu\": thu,\n                \"fri\": fri,\n                \"sat\": sat,\n                \"sun\": sun,}\n};\n                     \n    \nreturn [msg1, msg2, msg3];","outputs":4,"noerr":0,"x":1050,"y":1180,"wires":[["ea4d225.34516e"],["ea4d225.34516e"],["9ed67e7b.7d18e"],["ea4d225.34516e"]]},{"id":"26339209.52ecde","type":"comment","z":"63ccbb05.50e244","name":"Reboot Fix","info":"","x":820,"y":1140,"wires":[]},{"id":"22ac2c41.175a54","type":"inject","z":"63ccbb05.50e244","name":"","topic":"reboot","payload":"Started!","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":560,"y":960,"wires":[["6669cbe2.a15c14"]]},{"id":"9f922936.7b9848","type":"comment","z":"63ccbb05.50e244","name":"Set Button","info":"","x":540,"y":920,"wires":[]},{"id":"2a587b2f.a1e944","type":"ui_toast","z":"63ccbb05.50e244","position":"top right","displayTime":"3","highlight":"","sendall":true,"outputs":0,"ok":"OK","cancel":"","topic":"Timer 1","name":"","x":270,"y":1140,"wires":[]},{"id":"78a10f9b.5d6dc","type":"function","z":"63ccbb05.50e244","name":"On button press","func":"var z = flow.get(\"Timer1\");\nvar pon = flow.get(\"Payload\"+z+\"_on\");\nvar poff = flow.get(\"Payload\"+z+\"_off\");\n\nfunction calcTime(hh){\n    var hours = (\"0\"+Math.floor((hh%86400)/3600)).slice(-2);\n    var minutes = (\"0\"+Math.floor((hh%3600)/60)).slice(-2);\n    return hours + \":\" + minutes;\n}\n\nvar time = null;\nvar timerlabel = \"Timer \"+ z;\n\n\n// when button on is pressed\nif(msg.topic === \"buttonON\"){\n    var t1  = flow.get(\"timer\"+z+\"_on\")/1000;\n    time = calcTime(t1);\n    flow.set(\"T\"+z+\"on\", time);\n    //send to text element\n    var msg1 = {payload: \"SET\", topic: timerlabel, color: \"green\"};\n    //send to schedex\n    var msg2 = {payload: {ontime: \"ontime \" + time,\n                          onpayload: pon,\n                          suspended: false},\n                topic: \"SET\",\n                color:   \"green\"};\n    return [msg1,msg2,null,null];\n}\n// when button off is pressed\nif(msg.topic === \"buttonOFF\"){\n    var t2 = flow.get(\"timer\"+z+\"_off\")/1000;\n    time = calcTime(t2);\n    flow.set(\"T\"+z+\"off\", time);\n    //send to text element\n    var msg3 = {payload: \"SET\", topic: timerlabel, color: \"green\"};\n    //send to schedex\n    var msg4 = {payload: {offtime: \"offtime \" + time,\n                          offpayload: poff,\n                          suspended: false},\n                topic: \"SET\",\n                color:   \"green\"};\n    return [null,null,msg3,msg4];\n    \n}\n\nreturn msg;","outputs":4,"noerr":0,"x":1160,"y":1040,"wires":[["9ed67e7b.7d18e"],["ea4d225.34516e","6c7c2b6f.3c3fb4"],["9ed67e7b.7d18e"],["ea4d225.34516e","f946439e.5689e"]]},{"id":"555d2e0f.f38a8","type":"inject","z":"63ccbb05.50e244","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":840,"wires":[["ebc58699.46bfe8"]]},{"id":"f201b9c0.091bc8","type":"debug","z":"63ccbb05.50e244","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":750,"y":840,"wires":[]},{"id":"ebc58699.46bfe8","type":"subflow:3abe8c84.455934","z":"63ccbb05.50e244","name":"Timer 1","env":[{"name":"TimerNumber","value":"1","type":"num"},{"name":"PayloadON","value":"ON","type":"str"},{"name":"PayloadOFF","value":"OFF","type":"str"}],"x":440,"y":820,"wires":[["f201b9c0.091bc8"]],"icon":"node-red/cog.svg"},{"id":"764270df.9643d","type":"ui_switch","z":"63ccbb05.50e244","name":"","label":"Sun","tooltip":"","group":"9ab1ead6.da5a58","order":16,"width":"2","height":"1","passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":570,"y":1540,"wires":[["c4e361b.55226a"]]},{"id":"3022c9e5.353766","type":"mqtt out","z":"63ccbb05.50e244","name":"IKEA Smart Plug 1","topic":"zigbee2mqtt/ikeasmartplug1/set","qos":"0","retain":"false","broker":"eca6af44.5297b","x":1950,"y":1240,"wires":[]},{"id":"8b5e0830.c6e6e8","type":"debug","z":"63ccbb05.50e244","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1360,"y":1400,"wires":[]},{"id":"eca6af44.5297b","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":""},{"id":"9ab1ead6.da5a58","type":"ui_group","z":"","name":"IKEA Smart Socket","tab":"b710e2ce.a662a","order":2,"disp":true,"width":"6","collapse":false},{"id":"4ec600a6.406ae","type":"alexa-home-conf","z":"","username":"quintaar"},{"id":"c4b43ba4.186ae8","type":"mqtt-broker","z":"","name":"Gbridge","broker":"mqtt.gbridge.io","port":"8883","tls":"47c99f2f.8b1c1","clientid":"","usetls":true,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"b710e2ce.a662a","type":"ui_tab","z":"","name":"IKEA Smart Socket","icon":"dashboard","disabled":false,"hidden":false},{"id":"47c99f2f.8b1c1","type":"tls-config","z":"","name":"TLS Gbridge","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","servername":"mqtt.gbridge.io","verifyservercert":true}]

Flow Info

Created 5 years, 3 months ago
Updated 5 years, 1 month ago
Rating: not yet rated

Actions

Rate:

Node Types

Core
  • change (x1)
  • comment (x7)
  • debug (x3)
  • delay (x1)
  • function (x15)
  • inject (x4)
  • mqtt in (x2)
  • mqtt out (x6)
  • mqtt-broker (x2)
  • tls-config (x1)
Other
  • alexa-home (x1)
  • alexa-home-conf (x1)
  • schedex (x1)
  • subflow (x1)
  • subflow:3abe8c84.455934 (x1)
  • tab (x1)
  • ui_button (x3)
  • ui_group (x1)
  • ui_switch (x8)
  • ui_tab (x1)
  • ui_template (x1)
  • ui_text (x2)
  • ui_text_input (x2)
  • ui_toast (x2)

Tags

  • IKEA
  • TRADFRI
  • smart
  • socket
  • timer
  • dashboard
  • alexa
  • google
  • assistant
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option