Help with contexts please

Here is one with ui:


[{"id":"c1fd7048.fbcb48","type":"delay","z":"f954564f.03e718","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":460,"y":760,"wires":[["f07ada4b.c33cb8"]]},{"id":"f07ada4b.c33cb8","type":"function","z":"f954564f.03e718","name":"decrement","func":"const previouspayload = context.get(\"previous_payload\");\nconst stop = context.get(\"stop\") || false;\nif(msg.payload == \"stop\"){\n    context.set(\"stop\", true);\n    msg.payload = \"stopped\";\n    return [msg, null];\n} else if(msg.topic == \"start\" && msg.payload != previouspayload){\n    msg.topic = \"counting\";\n    context.set(\"previous_payload\", parseFloat(msg.payload));\n    context.set(\"newcount\", true);\n    context.set(\"stop\", false);\n    return [msg, msg];\n} else if(msg.topic == \"counting\" && msg.payload > 1 && !stop){\n    const newcount = context.get(\"newcount\");\n    let countvalue = previouspayload;\n    if(newcount && msg.payload != countvalue) return null;\n    context.set(\"newcount\", false);\n    msg.payload = countvalue - 1;\n    context.set(\"previous_payload\", msg.payload);\n    return [msg, msg];\n} else if(msg.payload == 1 && !stop){\n    msg.payload = \"finished\";\n    return [msg, null];\n}","outputs":2,"noerr":0,"x":450,"y":700,"wires":[["757c3701.47806"],["c1fd7048.fbcb48"]]},{"id":"78a83b75.26d8c4","type":"ui_numeric","z":"f954564f.03e718","name":"","label":"set start count","tooltip":"","group":"d619b4d0.780aa8","order":1,"width":0,"height":0,"wrap":false,"passthru":false,"topic":"","format":"{{msg.payload}}","min":0,"max":"100","step":1,"x":160,"y":580,"wires":[["463c0cad.ce804c"]]},{"id":"c99a569d.8a0998","type":"ui_button","z":"f954564f.03e718","name":"","group":"d619b4d0.780aa8","order":2,"width":0,"height":0,"passthru":false,"label":"start countdown","tooltip":"","color":"","bgcolor":"","icon":"","payload":"startcount","payloadType":"flow","topic":"start","x":160,"y":700,"wires":[["f07ada4b.c33cb8","1ac5dad4.5007ed"]]},{"id":"463c0cad.ce804c","type":"change","z":"f954564f.03e718","name":"","rules":[{"t":"set","p":"startcount","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":580,"wires":[[]]},{"id":"757c3701.47806","type":"ui_text","z":"f954564f.03e718","group":"d619b4d0.780aa8","order":3,"width":0,"height":0,"name":"","label":"Countdown","format":"{{msg.payload}}","layout":"row-spread","x":630,"y":700,"wires":[]},{"id":"1ac5dad4.5007ed","type":"change","z":"f954564f.03e718","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":160,"y":640,"wires":[["78a83b75.26d8c4"]]},{"id":"cdc32fdf.291988","type":"ui_button","z":"f954564f.03e718","name":"","group":"d619b4d0.780aa8","order":4,"width":0,"height":0,"passthru":false,"label":"Stop countdown","tooltip":"","color":"","bgcolor":"","icon":"","payload":"stop","payloadType":"str","topic":"","x":170,"y":780,"wires":[["f07ada4b.c33cb8"]]},{"id":"d619b4d0.780aa8","type":"ui_group","z":"","name":"Countdown","tab":"b2566dcf.0415","order":2,"disp":true,"width":"6","collapse":false},{"id":"b2566dcf.0415","type":"ui_tab","z":"","name":"Countdown","icon":"dashboard","order":2,"disabled":false,"hidden":false}]
2 Likes