I'm looking to making an adjustable timer for a sprinkling system. I'm very new to coding and have found a forum post with a code that looks like it is exactly what i want but just cant get it to work.
I believe i have everything where they should be and have the numerical topic set to "value" and the button topic "start". I'm sure I'm missing something I just don't know what.
Here is the code:
[{"id":"ce5534a3.3f8b98","type":"function","z":"be10358d.5f3058","name":"","func":"\nvar value = context.get('value') || 60000;\n\nif (msg.topic == "value")\n{\n value = msg.payload * 60000;\n context.set('value',value); \n}\n\nelse if (msg.topic == "start")\n{\n\nvar timer = setTimeout(function(){msg.payload = "now";node.send([msg,{ payload: "Ende" }]);var countdownstop = context.get('countdown');clearInterval(countdownstop)},value);\ncontext.set('timer',timer); \n\nvar count = value/60000;\n//count = count -1 ;\nmsg.payload=count;\nnode.send([null,msg]);\nvar countdown = setInterval(function() {count=count-1;msg.payload=count; node.send([null,msg]) }, 60000);\ncontext.set('countdown',countdown);\n\n}\n\nelse if (msg.topic == "stop")\n{\nvar timerstop = context.get('timer')\nclearTimeout(timerstop);\n\nvar countdownstop = context.get('countdown')\nclearInterval(countdownstop);\n\n}\n\n\n","outputs":"2","noerr":0,"x":410,"y":220,"wires":[["a70f86ce.c18f58"],["fa7c7eb.15f9d8"]]},{"id":"a70f86ce.c18f58","type":"debug","z":"be10358d.5f3058","name":"","active":true,"console":"false","complete":"payload","x":590,"y":180,"wires":},{"id":"6c4f84d8.656ebc","type":"ui_button","z":"be10358d.5f3058","name":"","group":"637d8cb3.d53d74","order":0,"width":0,"height":0,"label":"Start","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"start","x":190,"y":200,"wires":[["ce5534a3.3f8b98"]]},{"id":"1f4a748.bcd498c","type":"ui_numeric","z":"be10358d.5f3058","name":"","label":"Minuten","group":"637d8cb3.d53d74","order":0,"width":0,"height":0,"passthru":true,"topic":"value","format":"{{value}}","min":"1","max":"300","step":1,"x":180,"y":280,"wires":[["ce5534a3.3f8b98"]]},{"id":"8dba67c8.f2a418","type":"ui_button","z":"be10358d.5f3058","name":"","group":"637d8cb3.d53d74","order":0,"width":0,"height":0,"label":"Stop","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"stop","x":190,"y":240,"wires":[["ce5534a3.3f8b98"]]},{"id":"fa7c7eb.15f9d8","type":"ui_text","z":"be10358d.5f3058","group":"637d8cb3.d53d74","order":0,"width":0,"height":0,"name":"","label":"Restzeit","format":"{{msg.payload}} Minuten","layout":"row-spread","x":600,"y":240,"wires":},{"id":"637d8cb3.d53d74","type":"ui_group","z":"","name":"Default","tab":"7fe8c0a9.8eebd","disp":true,"width":"6"},{"id":"7fe8c0a9.8eebd","type":"ui_tab","z":"","name":"tests","icon":"dashboard"}]