|
[{"id":"20f5b48f.283ffc","type":"subflow","name":"Timer Settings (2)","info":"","category":"","in":[{"x":500,"y":320,"wires":[{"id":"dd09ea56.667bf8"}]}],"out":[{"x":740,"y":320,"wires":[{"id":"dd09ea56.667bf8","port":0}]}],"env":[{"name":"TimerNumber","type":"num","value":""},{"name":"PayloadON","type":"str","value":""},{"name":"PayloadOFF","type":"str","value":""}],"color":"#DDAA99"},{"id":"dd09ea56.667bf8","type":"function","z":"20f5b48f.283ffc","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":"860a82e0.55f59","type":"tab","label":"Timer in Dashboard","disabled":false,"info":"A neat online timer made in Dashboard. You can link it with any automation setup in NodeRED, deploy multiple timers and add schedules to your devices. \nYou can customise the payload to suit your needs.\n![enter image description here](https://notenoughtech.com/wp-content/uploads/2019/11/YouTube-Thumb.jpg)\n\n**Instructions:**\nYou can read all [set up instructions here](https://notenoughtech.com/home-automation/nodered-home-automation/a-timer-in-nodered/)\n\n---\n\n**Features**:\n\n - **Modular (as a subflow)**\n - **Unlimited timers per device**\n - **Supports “days of the week”**\n - **works offline**\n - **Dashboard interface**\n - **One button reset** \n\n**You will need the following nodes:**\n\n - node-red-dashboard\n - node-red-contrib-schedex\n---\n# Settings\n - **PayloadON** payload message sent on ON action\n - **PayloadOFF** payload message sent on OFF action\n - **TimerNumber** timer ID (unique for each timer)\n"},{"id":"fa5136ce.2a2c98","type":"schedex","z":"860a82e0.55f59","name":"Timer","passthroughunhandled":false,"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":1050,"y":520,"wires":[["92cb1dcf.7a3f3"]]},{"id":"90f5d76f.c93ae8","type":"ui_text_input","z":"860a82e0.55f59","name":"T2 On","label":"","tooltip":"","group":"b662ff46.2c09c","order":2,"width":"4","height":"1","passthru":false,"mode":"time","delay":"0","topic":"Ton","x":470,"y":240,"wires":[["45f12d1d.d35c74"]]},{"id":"d77abd7b.e5589","type":"ui_button","z":"860a82e0.55f59","name":"Set ON","group":"b662ff46.2c09c","order":3,"width":"2","height":"1","passthru":false,"label":"{{msg.topic}}","tooltip":"","color":"","bgcolor":"{{msg.color}}","icon":"","payload":"","payloadType":"str","topic":"buttonON","x":840,"y":200,"wires":[["de37d89e.2c1fa8"]]},{"id":"5440d628.4afea8","type":"ui_text_input","z":"860a82e0.55f59","name":"T2 Off","label":"","tooltip":"","group":"b662ff46.2c09c","order":4,"width":"4","height":"1","passthru":false,"mode":"time","delay":"0","topic":"Toff","x":470,"y":280,"wires":[["45f12d1d.d35c74"]]},{"id":"394df375.b6654c","type":"ui_button","z":"860a82e0.55f59","name":"Set OFF","group":"b662ff46.2c09c","order":5,"width":"2","height":"1","passthru":false,"label":"{{msg.topic}}","tooltip":"","color":"","bgcolor":"{{msg.color}}","icon":"","payload":"","payloadType":"str","topic":"buttonOFF","x":840,"y":320,"wires":[["de37d89e.2c1fa8"]]},{"id":"f2301d3e.87eda","type":"ui_button","z":"860a82e0.55f59","name":"Reset Button","group":"b662ff46.2c09c","order":6,"width":"6","height":"1","passthru":false,"label":"Reset","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":110,"y":400,"wires":[["c21152eb.de612"]]},{"id":"45f12d1d.d35c74","type":"function","z":"860a82e0.55f59","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":670,"y":260,"wires":[["d77abd7b.e5589"],["394df375.b6654c"]]},{"id":"c21152eb.de612","type":"function","z":"860a82e0.55f59","name":"Reset","func":"var z = flow.get(\"Timer1\");\n\nvar timerlabel = \"Timer \"+ z;\n\n\nflow.set(\"timer\"+z+\"_on\", 0);\nflow.set(\"timer\"+z+\"_off\", 0);\nflow.set(\"T\"+z+\"on\", null);\nflow.set(\"T\"+z+\"off\", null);\n\n\n\nvar msg1 = {payload: \"Timer\"+z+\" reset\", topic: timerlabel,};\nvar msg2 = {payload: 0};\n\nvar msg3 = {color: \"grey\",\n topic: \"Select Time\",\n};\n\nvar msg4 = {payload:{suspended: true}};\nvar msg5 = {payload: true};\n\nreturn [msg1, msg2, msg3, msg4, msg5];","outputs":5,"noerr":0,"x":290,"y":400,"wires":[["5fd8db43.2df974"],["5440d628.4afea8","90f5d76f.c93ae8"],["d77abd7b.e5589","394df375.b6654c"],["fa5136ce.2a2c98"],["8042440f.c4ae28","d9da8537.398b28","d0b50712.8b2098","faf557e7.3aad28","173eae7b.e69872","64c7ff12.b418d","30bb90ad.f1322"]]},{"id":"8042440f.c4ae28","type":"ui_switch","z":"860a82e0.55f59","name":"","label":"Mon","tooltip":"","group":"b662ff46.2c09c","order":7,"width":"2","height":"1","passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":550,"y":560,"wires":[["97132fca.3d7b5"]]},{"id":"d9da8537.398b28","type":"ui_switch","z":"860a82e0.55f59","name":"","label":"Tue","tooltip":"","group":"b662ff46.2c09c","order":8,"width":"2","height":"1","passthru":true,"decouple":"false","topic":"tue","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":550,"y":600,"wires":[["9b547ed1.665b"]]},{"id":"d0b50712.8b2098","type":"ui_switch","z":"860a82e0.55f59","name":"","label":"Wed","tooltip":"","group":"b662ff46.2c09c","order":9,"width":"2","height":"1","passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":550,"y":640,"wires":[["9a004f2c.f4301"]]},{"id":"faf557e7.3aad28","type":"ui_switch","z":"860a82e0.55f59","name":"","label":"Thu","tooltip":"","group":"b662ff46.2c09c","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":550,"y":680,"wires":[["93cdeb25.9fe6b8"]]},{"id":"173eae7b.e69872","type":"ui_switch","z":"860a82e0.55f59","name":"","label":"Fri","tooltip":"","group":"b662ff46.2c09c","order":11,"width":"2","height":"1","passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":550,"y":720,"wires":[["9f022d2e.00199"]]},{"id":"64c7ff12.b418d","type":"ui_switch","z":"860a82e0.55f59","name":"","label":"Sat","tooltip":"","group":"b662ff46.2c09c","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":550,"y":760,"wires":[["32c2807c.e7bde"]]},{"id":"97132fca.3d7b5","type":"function","z":"860a82e0.55f59","name":"Mon","func":"var z = flow.get(\"Timer1\");\n\nif(z !== undefined){\n var x = msg.payload;\n flow.set(\"Monday\"+z, x);\n msg.payload = {mon: x};\n\n return msg;\n}\n","outputs":1,"noerr":0,"x":710,"y":560,"wires":[["fa5136ce.2a2c98"]]},{"id":"9b547ed1.665b","type":"function","z":"860a82e0.55f59","name":"Tue","func":"var z = flow.get(\"Timer1\");\n\n\nif(z !== undefined){\n var x = msg.payload;\n flow.set(\"Tuesday\"+z, x);\n msg.payload = {tue: x};\n \n return msg;\n\n}\n\n","outputs":1,"noerr":0,"x":710,"y":600,"wires":[["fa5136ce.2a2c98"]]},{"id":"9a004f2c.f4301","type":"function","z":"860a82e0.55f59","name":"Wed","func":"var z = flow.get(\"Timer1\");\nif(z !== undefined){\n\n\nvar x = msg.payload;\nflow.set(\"Wednesday\"+z, x);\nmsg.payload = {wed: x};\n\nreturn msg;\n\n}","outputs":1,"noerr":0,"x":710,"y":640,"wires":[["fa5136ce.2a2c98"]]},{"id":"93cdeb25.9fe6b8","type":"function","z":"860a82e0.55f59","name":"Thu","func":"var z = flow.get(\"Timer1\");\nif(z !== undefined){\nvar x = msg.payload;\nflow.set(\"Thursday\"+z, x);\nmsg.payload = {thu: x};\n\nreturn msg;\n}","outputs":1,"noerr":0,"x":710,"y":680,"wires":[["fa5136ce.2a2c98"]]},{"id":"9f022d2e.00199","type":"function","z":"860a82e0.55f59","name":"Fri","func":"var z = flow.get(\"Timer1\");\n\nif(z !== undefined){\nvar x = msg.payload;\nflow.set(\"Friday\"+z, x);\nmsg.payload = {fri: x};\n}\nreturn msg;","outputs":1,"noerr":0,"x":710,"y":720,"wires":[["fa5136ce.2a2c98"]]},{"id":"32c2807c.e7bde","type":"function","z":"860a82e0.55f59","name":"Sat","func":"var z = flow.get(\"Timer1\");\nif(z !== undefined){\n\nvar x = msg.payload;\nflow.set(\"Saturday\"+z, x);\nmsg.payload = {sat: x};\n}\nreturn msg;","outputs":1,"noerr":0,"x":710,"y":760,"wires":[["fa5136ce.2a2c98"]]},{"id":"34f20933.30f306","type":"function","z":"860a82e0.55f59","name":"Sun","func":"var z = flow.get(\"Timer1\");\n\nif(z !== undefined){\nvar x = msg.payload;\nflow.set(\"Sunday\"+z, x);\nmsg.payload = {sun: x};\n}\nreturn msg;","outputs":1,"noerr":0,"x":710,"y":800,"wires":[["fa5136ce.2a2c98"]]},{"id":"85912f07.bdb98","type":"inject","z":"860a82e0.55f59","name":"","topic":"","payload":"Started!","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":620,"y":440,"wires":[["45eb25e9.cacb6c"]]},{"id":"45eb25e9.cacb6c","type":"function","z":"860a82e0.55f59","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\nmsg.payload = { \"ontime\": \"ontime \" + timeON, \"onpayload\": pon,\n \"offtime\": \"offtime \" + timeOFF, \"offpayload\": poff,\n \"mon\": mon,\n \"tue\": tue,\n \"wed\": wed,\n \"thu\": thu,\n \"fri\": fri,\n \"sat\": sat,\n \"sun\": sun\n}\n\n \nreturn msg;","outputs":1,"noerr":0,"x":830,"y":440,"wires":[["fa5136ce.2a2c98"]]},{"id":"b43b80e8.cf98d","type":"comment","z":"860a82e0.55f59","name":"Reboot Fix","info":"","x":600,"y":400,"wires":[]},{"id":"30742d84.196c52","type":"inject","z":"860a82e0.55f59","name":"","topic":"reboot","payload":"Started!","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":80,"y":600,"wires":[["442289b7.850598"]]},{"id":"ceea6095.7c354","type":"comment","z":"860a82e0.55f59","name":"Set Button","info":"","x":440,"y":120,"wires":[]},{"id":"5fd8db43.2df974","type":"ui_toast","z":"860a82e0.55f59","position":"top right","displayTime":"3","highlight":"","sendall":true,"outputs":0,"ok":"OK","cancel":"","raw":false,"topic":"","name":"","x":250,"y":280,"wires":[]},{"id":"de37d89e.2c1fa8","type":"function","z":"860a82e0.55f59","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 msg1 = {payload: {ontime: \"ontime \" + time,\n onpayload: pon,\n suspended: false},\n topic: \"SET\",\n color: \"green\"};\n return [msg1,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 msg2 = {payload: {offtime: \"offtime \" + time,\n offpayload: poff,\n suspended: false},\n topic: \"SET\",\n color: \"green\"};\n return [null,msg2];\n \n}\n\nreturn msg;","outputs":2,"noerr":0,"x":1060,"y":240,"wires":[["fa5136ce.2a2c98","d77abd7b.e5589"],["fa5136ce.2a2c98","394df375.b6654c"]]},{"id":"64927dcb.95eb24","type":"inject","z":"860a82e0.55f59","name":"Set after deployment","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":60,"wires":[["622b7006.10068"]]},{"id":"400257e.47ba9a8","type":"debug","z":"860a82e0.55f59","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":490,"y":60,"wires":[]},{"id":"622b7006.10068","type":"subflow:20f5b48f.283ffc","z":"860a82e0.55f59","name":"Settings","env":[{"name":"TimerNumber","value":"1","type":"num"},{"name":"PayloadON","value":"true","type":"bool"},{"name":"PayloadOFF","value":"false","type":"bool"}],"x":340,"y":60,"wires":[["400257e.47ba9a8"]],"icon":"node-red/cog.svg"},{"id":"30bb90ad.f1322","type":"ui_switch","z":"860a82e0.55f59","name":"","label":"Sun","tooltip":"","group":"b662ff46.2c09c","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":550,"y":800,"wires":[["34f20933.30f306"]]},{"id":"92cb1dcf.7a3f3","type":"debug","z":"860a82e0.55f59","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1270,"y":520,"wires":[]},{"id":"442289b7.850598","type":"function","z":"860a82e0.55f59","name":"Restore Dashboard","func":"var z = flow.get(\"Timer1\");\n\nif(z !== undefined){\n var mon = flow.get(\"Monday\"+z);\n var tue = flow.get(\"Tuesday\"+z);\n var wed = flow.get(\"Wednesday\"+z);\n var thu = flow.get(\"Thursday\"+z);\n var fri = flow.get(\"Friday\"+z);\n var sat = flow.get(\"Saturday\"+z);\n var sun = flow.get(\"Sunday\"+z); \n\n // update dashboard days\n var msg5 = {payload: mon};\n var msg6 = {payload: tue};\n var msg7 = {payload: wed};\n var msg8 = {payload: thu};\n var msg9 = {payload: fri};\n var msg10 = {payload: sat};\n var msg11 = {payload: sun};\n \n \n // update dashboard times\n var timeON = flow.get(\"T\"+z+\"on\");\n var timeOFF = flow.get(\"T\"+z+\"off\");\n var msg1 = {payload: timeON};\n var msg2 = {payload: timeOFF};\n \n \n // update dash buttons\n var msg3 = {payload: {color: \"green\"}, topic: \"SET\"};\n var msg4 = {payload: {color: \"green\"}, topic: \"SET\"};\n \n \nreturn[msg1, msg2, msg3, msg4, msg5, msg6, msg7, msg8, msg9, msg10, msg11]; \n \n}\n\n","outputs":11,"noerr":0,"x":250,"y":660,"wires":[["90f5d76f.c93ae8"],["5440d628.4afea8"],["d77abd7b.e5589"],["394df375.b6654c"],["8042440f.c4ae28"],["d9da8537.398b28"],["d0b50712.8b2098"],["faf557e7.3aad28"],["173eae7b.e69872"],["64c7ff12.b418d"],["30bb90ad.f1322"]]},{"id":"b662ff46.2c09c","type":"ui_group","z":"","name":"Evening","tab":"404aace1.054814","order":2,"disp":true,"width":"6","collapse":false},{"id":"404aace1.054814","type":"ui_tab","z":"","name":"Entry Light","icon":"dashboard","order":9,"disabled":false,"hidden":false}] |
Hello Mat,
I have read through your tutorials and they are a very good intro to node-red, thanks for spending the time writing them. However, I am still slightly confused as to how to use you timer. Here is what I have done so far:
I have imported your flow onto my node red instance. This has now put a timer on my dashboard. I can enter times and press the buttons. As I understand it I would need to duplicate the flow for every timer to get another set of dashboard widgets?
To use the timer I drag the subflow onto a flow that I am working on as per the instruction:
"I promised the node to be simple to deploy and use. To use it in your NodeRED flow, deploy the subflow and edit the environmental variables."
This is where I am getting stuck! I am probably being thick and as I am a bit new to node-red but I cannot figure out how to wire up the settings? I am not sure where to edit the environmental variables?
If I press the button on the timer in your flow it says the timer has been set. If I wire up a debug to the timer on the far right of your flow nothing happens when the timer start that I have set in the dashboard is reached.
Sorry for the length of my question, just a couple of hints to get me going would be really helpful? Thanks again for your hard work on this.
Martyn