Johannes,
I "Billy-Bobbed" your code a bit to get exactly what I want, the output now goes to a label as msg.topic and behaves just like the stopwatch in my 1st post. Can't thank you enough for sticking with me!
var aVar
if (msg.payload === "stop" && context.get("running") === true) {
context.set("stop", true);
} else if (context.get("running") !== true) {
context.set("running",true);
const timestampStart = msg.payload;
everySecond = setInterval(()=>{
if (context.get("stop") === true) {
const ellapsed = ((Date.now() - timestampStart)/1000).toFixed(2);
node.send({payload:ellapsed});
context.set("stop",false);
context.set("running",false);
clearInterval(everySecond);
} else {
aVar = ((Date.now()-timestampStart)/1000).toFixed(2);
node.send({payload:aVar});
}
},100);
}
return null;
Here's the flow for anyone else wanting Johanne's stopwatch:
[{"id":"e076a3b0.b94978","type":"inject","z":"c199b9b6.017a2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":460,"y":1340,"wires":[["77cb7238.0744ac"]]},{"id":"2e3384f1.d9bfec","type":"inject","z":"c199b9b6.017a2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"stop","payloadType":"str","x":450,"y":1380,"wires":[["77cb7238.0744ac"]]},{"id":"77cb7238.0744ac","type":"function","z":"c199b9b6.017a2","name":"","func":"var aVar\nif (msg.payload === \"stop\" && context.get(\"running\") === true) {\n context.set(\"stop\", true);\n} else if (context.get(\"running\") !== true) {\n context.set(\"running\",true);\n const timestampStart = msg.payload;\n everySecond = setInterval(()=>{\n if (context.get(\"stop\") === true) {\n const ellapsed = ((Date.now() - timestampStart)/1000).toFixed(2);\n node.send({payload:ellapsed});\n context.set(\"stop\",false);\n context.set(\"running\",false);\n clearInterval(everySecond);\n } else {\n aVar = ((Date.now()-timestampStart)/1000).toFixed(2);\n node.send({payload:aVar});\n }\n },100);\n}\nreturn null;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":620,"y":1340,"wires":[["1a2ca2d0.ebf355"]],"info":"var aVar\nif (msg.payload === \"stop\" && context.get(\"running\") === true) {\n context.set(\"stop\", true);\n} else if (context.get(\"running\") !== true) {\n context.set(\"running\",true);\n const timestampStart = msg.payload;\n everySecond = setInterval(()=>{\n if (context.get(\"stop\") === true) {\n const ellapsed = ((Date.now() - timestampStart)/1000).toFixed(2);\n node.send({payload:ellapsed});\n context.set(\"stop\",false);\n context.set(\"running\",false);\n clearInterval(everySecond);\n } else {\n aVar = ((Date.now()-timestampStart)/1000).toFixed(2);\n node.send({payload:aVar});\n }\n },100);\n}\nreturn null;"},{"id":"1a2ca2d0.ebf355","type":"change","z":"c199b9b6.017a2","name":"msg Swap","rules":[{"t":"move","p":"payload","pt":"msg","to":"topic","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":1380,"wires":[["19d1cfe7.04ab7"]]},{"id":"19d1cfe7.04ab7","type":"ui_text","z":"c199b9b6.017a2","group":"36e6edd6.dd93b2","order":2,"width":2,"height":1,"name":"","label":"","format":"{{msg.topic}}","layout":"row-spread","x":780,"y":1350,"wires":[]},{"id":"36e6edd6.dd93b2","type":"ui_group","z":"","name":"Label Spacer","tab":"81831aab.f2f568","order":4,"disp":false,"width":"6","collapse":false},{"id":"81831aab.f2f568","type":"ui_tab","z":"","name":"GTO-500 Gate Opener","icon":"dashboard","disabled":false,"hidden":false}]
Thanks again!
Russ