I have one of those ui_LEDs on my dashboard.
(Big picture)
I compare two inputs.
If they are less than 'n' different it is good.
If they are greater than 'n' different, it is bad.
So the output is basically:
true
if good and false
if bad.
It supposedly works, but every time I load that page, the LED is blank/grey.
I have 3 inject
nodes connected to it.
ture
, false
and "blah" - to wipe it.
I have a debug
node from the function
node and I see the true
being sent.
The only quibble is that it is BLUE, not ORANGE as true
/false
signals are.
But the inject
nodes produce the same result in the output (debug on the right of the screen).
Pressing the true
button it says it is injected, but the LED stays off.
But if I press the false
button (and either look at the dashboard then or wait) the LED is then working.
So I can press false
'trueand the LED is green. Or I just press
falseand the LED is red, until the next _cycle_ comes around with a
true` and it turns green.
The is the important part of the flow.
It shows the function
node and you can look at its outputs. You see the debug
node, the LED
node, and the 3 inject
nodes.
Clarification:
The LED is GREY - no input.
There is a pulsed output from the function node
(say every 18 seconds) of true
.
The LED stays GREY.
Pressing the true
button nothing happens.
It is only when I press the false
button that it turns RED and then starts to obey the function
node output.
And: typicall as I am posting this, it is behaving itself. But only now is it doing that.
When I started it wasn't.
I know: Hard to believe. So I am not sure what to say.
It sometimes works. But a lot of the time it doesn't.
Code:
[{"id":"eed5dd50.fd5f48","type":"ui_led","z":"e2bd5a4e.5597e8","group":"44e9ffdf.d2d948","order":1,"label":"Time sync","colorForValue":[{"color":"red","value":"false","valueType":"bool"},{"color":"lime","value":"true","valueType":"bool"}],"name":"","x":900,"y":2330,"wires":[]},{"id":"45f33aee.ea5af4","type":"inject","z":"e2bd5a4e.5597e8","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":700,"y":2470,"wires":[["eed5dd50.fd5f48"]]},{"id":"98458eac.83762","type":"inject","z":"e2bd5a4e.5597e8","name":"","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":700,"y":2510,"wires":[["eed5dd50.fd5f48"]]},{"id":"839e9da.fa9976","type":"inject","z":"e2bd5a4e.5597e8","name":"","topic":"","payload":"wipe","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":700,"y":2550,"wires":[["eed5dd50.fd5f48"]]},{"id":"16df7bcf.f3953c","type":"debug","z":"e2bd5a4e.5597e8","name":"Time Sync LED","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1060,"y":2310,"wires":[]},{"id":"80e3a376.889948","type":"function","z":"e2bd5a4e.5597e8","name":"","func":"var threshold = context.get('threshold')|| 60;\ncontext.set('threshold', threshold);\nmsg3 = {payload: threshold};\n\nif (msg.topic == 'Debug')\n{\n if (msg.payload === true)\n {\n context.set('db', 1);\n } else\n if (msg.payload === false)\n {\n context.set('db', 0);\n }\n}\nvar db = context.get('db');\n\n//---------------------\nif (msg.topic == 'slip')\n{\n if (db == 1)\n {\n node.warn(\"**************************\");\n node.warn(\"Threshold set to \" + msg.payload);\n }\n context.set('threshold', msg.payload);\n}\n//---------------------\nif (msg.topic == \"RTC\")\n{\n context.set('RTC',msg.payload);\n //node.warn(\"RTC \" + context.get('RTC'));\n}\nif (msg.topic == \"local\")\n{\n context.set('local', msg.payload);\n //node.warn(\"Local \" + context.get('local'));\n}\nif (db == 1)\n{\n node.warn(\"Stored RTC value \" + context.get('RTC'));\n node.warn(\"Stored RPI value \" + context.get('local'));\n node.warn(\"Stored threshold value \" + context.get('threshold'));\n}\n\nif (context.get('RTC') !== 0)\n{\n if (context.get('local') !== 0)\n {\n var a = context.get('RTC');\n var b = context.get('local');\n var r = a - b;\n }\n if (db == 1)\n {\n node.warn(\"Error is \" + r);\n }\n if (r > threshold)\n {\n // ** We have a problem! **\n if (db == 1)\n {\n node.warn(\"Part 1\");\n }\n node.status({fill:\"red\",shape:\"dot\",text:\"Time error\"});\n msg1 = {payload: false};\n msg2 = {payload: r};\n return [msg1, msg2, msg3];\n } \n if (r < 0)\n {\n r = b - a;\n if (r > threshold)\n {\n // ** We have a problem! **\n if (db == 1)\n {\n node.warn(\"Part 2\");\n }\n node.status({fill:\"red\",shape:\"dot\",text:\"Time error\"});\n msg1 = {payload: false};\n msg2 = {payload: r};\n return [msg1, msg2, msg3];\n }\n }\n else\n {\n // All Good!\n if (db == 1)\n {\n node.warn(\"Part 3\");\n }\n node.status({fill:\"green\",shape:\"dot\",text:\"Time good\"});\n msg1 = {payload: true};\n msg2 = {payload: r};\n return [msg1, msg2, msg3];\n }\n}\n","outputs":3,"noerr":0,"x":740,"y":2330,"wires":[["eed5dd50.fd5f48","627aca75.54ebfc","e4853e2f.376418","b9b46c55.6fae6","16df7bcf.f3953c"],["b8dac5dc.347b2","bd2b18ee.4803c8"],["c9fb0e46.8a1908","cc9de920.79fa58"]],"outputLabels":["state","difference","threshold"]},{"id":"44e9ffdf.d2d948","type":"ui_group","z":"","name":"Local Time","tab":"173dcde5.96e88a","order":2,"disp":true,"width":"11","collapse":false},{"id":"173dcde5.96e88a","type":"ui_tab","z":"","name":"Local Readings","icon":"dashboard","order":3,"disabled":false,"hidden":false}]
Are there any elephants in there?
(or maybe: Gremlins?)