TCP sockets is purely via mqtt in out... and a bit of dashboard serving.... and a bit of Telegram notification and control...
The timeout is used in the data stream from a wifi switch on mqtt mostly... If a wifi switch doesn't report in within a pre determined time, for instance, the timeout activates and sends an alert... I also use it if there are "raw" powered sonoffs that I monitor ... If the power goes off, the switch doesn't report in and the voltage/current/power payloads are set to 0.... I have a few switches in the "outlying" non power backed up areas that need constant monitoring... ie a wet basement where the switch turns on a sump pump... or in another case, one of my buildings is about 300m from my household proper... If miscreants dig up and cut the power cables, it goes off line and an alert is raised through non-response....
I have found it handy in quite a few diverse ways...
Regds
Ed
PS: I have written another little sub-flow that is a delay on/off timer that I use a LOT for staggering appliance turn on/off etc... Its probably way simple and done in a complicated manner, but I doubt that this one would give a Skt count up either(not on its own, anyway)... FYI... Here it is:
[
{
"id": "4ea703af.383ab4",
"type": "subflow",
"name": "ON/OFF Delay",
"info": "\n\nVariable timer... Independent\nsettings of On or Off delay...\nput in values in SECONDS...\n\nWhile under delay to on or off,\na off or on will cancel the timer\nrespectively....\n\nif off and 0 rec'd, it sends 0\nif on and 1 rec'd, it sends 1",
"category": "Utility",
"in": [
{
"x": 70,
"y": 100,
"wires": [
{
"id": "ed5090e2.56163"
}
]
}
],
"out": [
{
"x": 330,
"y": 100,
"wires": [
{
"id": "ed5090e2.56163",
"port": 1
}
]
},
{
"x": 330,
"y": 150,
"wires": [
{
"id": "ed5090e2.56163",
"port": 2
}
]
}
],
"env": [
{
"name": "OnDelay",
"type": "num",
"value": "5"
},
{
"name": "OffDelay",
"type": "num",
"value": "5"
}
],
"color": "#777777",
"inputLabels": [
"0/1"
],
"outputLabels": [
"Out",
"Inv"
],
"icon": "node-red/timer.svg",
"status": {
"x": 330,
"y": 50,
"wires": [
{
"id": "ed5090e2.56163",
"port": 0
}
]
}
},
{
"id": "ed5090e2.56163",
"type": "function",
"z": "4ea703af.383ab4",
"name": "Delay On/Off",
"func": "var OnDelay = env.get(\"OnDelay\"); //env.get for SubFlow,flow.get for Function\nOffDelay = env.get(\"OffDelay\"); //env.get for SubFlow,flow.get for Function\nSigStat = context.get(\"SigStat\");\nif (isNaN(SigStat)){SigStat=0} //Check if it exists, if not, make it default off...\nSignal = msg.payload;\n\nTOF = context.get(\"TOF\") //Current Timer Object if any\n\nif(OnDelay<0){OnDelay=0} //chk neg, Zerise if neg\nif(OffDelay<0){OffDelay=0} //chk neg, Zerise if neg\n\nOnDelay = OnDelay * 1000; //to mS (Timeout function is ms based)\nOffDelay = OffDelay * 1000; //to mS\n\n\nif(Signal > 0){Signal = 1} //Anything > 0 is on signal\n else {Signal = 0} //Anything else is off signal\n\n//******************Cancellation Routine******************\nif(Signal == 1){ \n if (SigStat == 1){ //its already on...Cancel any possible off Progress, just send and leave\n clearTimeout(TOF)//Scrap the current timer progress\n //statusMsg = \"OffCancel\"\n statusMsg = ({ fill:\"green\", shape:\"dot\", text:\"OffCancel\"+\" OnD:\"+OnDelay/1000+\" OffD:\"+OffDelay/1000});\n node.status(statusMsg)\n node.send([{payload:statusMsg}, {payload:1}, {payload:0}]);\n return;\n }\n}\nif(Signal=== 0){ \n if (SigStat === 0){ //its already off...Cancel any possible \"\"on\" Progress, just send and leave\n clearTimeout(TOF)//Scrap the current timer progress\n statusMsg = ({ fill:\"red\", shape:\"dot\", text:\"OnCancel\"+\" OnD:\"+OnDelay/1000+\" OffD:\"+OffDelay/1000});\n node.status(statusMsg)\n node.send([{payload:statusMsg}, {payload:0}, {payload:1}]);\n return;\n }\n}\n//******************Cancellation Routine End**************\n//********************Main Routine************************\nif(Signal == 1){ \n if (SigStat === 0){ //its off...Turn it on with delay\n context.set(\"TOF\", setTimeout(function(){\n statusMsg = ({ fill:\"green\", shape:\"dot\", text:\"On \"+\" OnD:\"+OnDelay/1000+\" OffD:\"+OffDelay/1000});\n node.status(statusMsg);\n node.send([{payload:statusMsg}, {payload:1}, {payload:0}]);\n context.set(\"SigStat\", 1);\n }, OnDelay));\n statusMsg = ({ fill:\"blue\", shape:\"ring\", text:\"0->1\"+\" OnD:\"+OnDelay/1000+\" OffD:\"+OffDelay/1000});\n node.status(statusMsg)\n node.send([{payload:statusMsg}]);\n node.done();//forgot\n return;//\n }\n} \nif(Signal ===0){\n if (SigStat == 1){ //its on...Turn it off with delay\n context.set(\"TOF\", setTimeout(function(){\n statusMsg = ({ fill:\"red\", shape:\"dot\", text:\"Off \"+\" OnD:\"+OnDelay/1000+\" OffD:\"+OffDelay/1000});\n node.status(statusMsg);\n node.send([{payload:statusMsg}, {payload:0}, {payload:1}]);\n context.set(\"SigStat\", 0);\n }, OffDelay));\n statusMsg = ({ fill:\"blue\", shape:\"ring\", text:\"1->0\"+\" OnD:\"+OnDelay/1000+\" OffD:\"+OffDelay/1000});\n node.status(statusMsg)\n node.send([{payload:statusMsg}]);\n node.done();//forgot?\n return;//\n }\n} \n \n",
"outputs": 3,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 200,
"y": 100,
"wires": [
[],
[],
[]
],
"inputLabels": [
"0/1"
],
"outputLabels": [
"Status",
"Out",
"inv"
],
"icon": "node-red-contrib-chronos/chronos_scheduler.svg"
}
]
Woohoo!! I got it Right!! (Posting the code, anyway!)
Lol ... Ed