Switch node not Consistent

recently i noticed that my flows were not getting executed consistently. i did an analysis and found that it was switch node that was creating the problem. it works inconsistently. some times it forwards the input and at times it remains idle. it is messing up almost all my flows..and when i deleted the node and made a new one just as the deleted one,it works..any advises?

First tell us what hardware and operating system you are running on, then show us the node-red startup log you get from restarting node-red, starting with the Welcome to node-red message.

I am running node red from my hassio system which is running in orange Pi PC 2. is this the log you have asked for.

Welcome to Node-RED
===================
6 Jun 19:27:33 - [info] Node-RED version: v0.20.5
6 Jun 19:27:33 - [info] Node.js  version: v10.14.2
6 Jun 19:27:33 - [info] Linux 4.19.13 arm64 LE
6 Jun 19:27:35 - [info] Loading palette nodes
6 Jun 19:27:49 - [warn] rpi-gpio : Raspberry Pi specific node set inactive
6 Jun 19:27:50 - [info] Dashboard version 2.15.4 started at /endpoint/ui
6 Jun 19:27:54 - [info] Settings file  : /etc/node-red/config.js
6 Jun 19:27:54 - [info] Context store  : 'default' [module=memory]
6 Jun 19:27:54 - [info] User directory : /config/node-red/
6 Jun 19:27:54 - [warn] Projects disabled : editorTheme.projects.enabled=false
6 Jun 19:27:54 - [info] Flows file     : /config/node-red/flows.json
6 Jun 19:27:54 - [info] Server now running at http://127.0.0.1:46836/
[19:27:54] INFO: Starting NGinx...
6 Jun 19:27:55 - [info] Starting flows
nginx: [alert] detected a LuaJIT version which is not OpenResty's; many optimizations will be disabled and performance will be compromised (see https://github.com/openresty/luajit2 for OpenResty's LuaJIT or, even better, consider using the OpenResty releases from https://openresty.org/en/download.html)
6 Jun 19:27:57 - [info] Started flows
6 Jun 19:27:57 - [info] [mqtt-broker:Mosquitto] Connected to broker: mqtt://192.168.33.250:1883
6 Jun 19:27:58 - [error] [alexa-home-conf:ba964fdb.7ae7a] Error: connect ECONNREFUSED 34.240.81.189:8883
6 Jun 19:27:59 - [error] [api-call-service:Isha prayer Time] Call-Service attempted without connection to server.
6 Jun 19:27:59 - [error] [api-call-service:TV Mute] Call-Service attempted without connection to server.
6 Jun 19:28:00 - [info] [server:Home Assistant] WebSocket Connected to http://hassio/homeassistant

When you say it remains idle do you mean it is not passing on some messages? If so have you got an Otherwise output on the node? If not then add one and put a debug node on it and see if anything appears.
If still no joy then show us the config for the switch node and put debug nodes on the input and outputs of the Switch node and show us which messages it is misbehaving on.

By idle i mean that the message is not sent through at times. Some time the message is transferred through. So there is complete inconsistency. When I am designing the flow the switch would be working perfectly even in testing. but afterwards it fails to sent messages through. i have checked with inject node and debug node at input and output respectively with affected switch node. during testing it fails. Then i deleted the node and made a node with the same characteristics. at that time it worked.

You have only answered the first question in my post. Remaining to be answered:
Have you got an Otherwise output on the node? If not then add one and put a debug node on it and see if anything appears.
If still no joy then show us the config for the switch node and put debug nodes on the input and outputs of the Switch node and show us which messages it is misbehaving on.

@sheminasalam Isn't it the ui_switch node you are referring to? (Just to clear things up :smiley:)

Tried Otherwise rule and it worked for now.If i spot anything odd, will get back you.

Yes.....its the thing

What thing? You replied that adding the Otherwise rule worked, which implies it is a Switch node, but your latest posts suggests it is a dashboard ui_switch node, not a Switch node.

sorry i said its the switch node...pardon for being in-discrete. its switch node only not dashboard ui switch

I am running into this same issue. It seems that the switch node (not the UI switch) only outputs if the condition is within some sort of percentage of the set value. In my case, I am evaluating an interval length based on how long my swampcooler has been on. I want it to pass on the message if the cooler has been on for less than 10 minutes. This works fine is the time is over about 3 minutes or so. If the time reported to the node is 2m 25s (an actual reading) this is not sent through, and is instead sent to the "otherwise" output. To get around this, I added additional conditions to the switch node. So, I have output 1 set to < 10m 1s, output 2 set to 6m 30s, output 3 set to 3m 1s, and output 4 set to "otherwise". When I have a time reported to the node of 1m 31.7s (an actual reading), it outputs only on outputs 2 and 3, even though it is clearly less than 10m 1s. So, to anyone who may be researching this issue, this may be a work around. The question is, why is this the case? And, whether or not this is intentional, there should be some documentation as to what the limit/percentage is that it will report. During testing of my flow, I was using <10s to generate an output, but it wouldn't output if it was lower than 3s. This is why I believe it outputs based on a percentage. It has to be within a percentage of the set number to generate an output. So, a setting of <60s will not generate an output of 3s. A setting of <10m will not generate an output of 2m 30s. This has been a consistent problem for me. I would like to hear others thoughts on this.

I am using a Raspberry Pi 4 with 4GB Ram, running Home Assistant with the Node-Red add-on.

Can you share a screenshot of your switch node settings. The values you speak of 10m, 10s etc would be strings & it is no wonder you have the results you see.

Yes, they are strings because this is the output that is generated by the interval length node when set to "human readable". The node works fine and consistently as long as it is within some percentage. Which is why is outputs on the <6m 30s and <3m 1s conditions, but not the 10m 1s conditions.
Here is a screenshot of the switch node settings.

Strings are compared letter by letter.

Therefore 6m 5s is > 10m

When you do a compare on a string it does an alphanumeric compare. It does not know they are numbers. So A is less than B and so on. If you want to compare times then convert them all to seconds (or probably better milliseconds) and convert them back to human readable form, if you need to, when you display them.

It doesn't seem to be working that way... Maybe I'm confused. Here is the flow that I an essentially using to test the time.

[{"id":"3bb5abc462460e7e","type":"ui_text","z":"6a68026e32f5ba52","group":"377d6acc.b0a0fe","order":22,"width":0,"height":0,"name":"","label":"Last Power ON Timestamp","format":"<font color=\"green\"> {{msg.payload}} </font>","layout":"col-center","x":680,"y":380,"wires":[]},{"id":"0d1f6b7b89ed92fb","type":"ui_text","z":"6a68026e32f5ba52","group":"377d6acc.b0a0fe","order":22,"width":0,"height":0,"name":"","label":"Last Power OFF Timestamp","format":"<font color=\"red\"> {{msg.payload}} </font>","layout":"col-center","x":680,"y":420,"wires":[]},{"id":"258bc0751d30a1c6","type":"change","z":"6a68026e32f5ba52","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$now('[M01].[D01].[Y0001] [H01]:[m01]:[s01]', '-0600')","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":380,"wires":[["3bb5abc462460e7e","bbb628a2b47c6123"]]},{"id":"60a0f27431acb290","type":"change","z":"6a68026e32f5ba52","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$now('[M01].[D01].[Y0001] [H01]:[m01]:[s01]', '-0600')","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":420,"wires":[["0d1f6b7b89ed92fb","bbb628a2b47c6123"]]},{"id":"ff0dbcfc6f24b90c","type":"switch","z":"6a68026e32f5ba52","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"ON","vt":"str"},{"t":"eq","v":"OFF","vt":"str"}],"checkall":"true","outputs":2,"x":270,"y":400,"wires":[["258bc0751d30a1c6"],["60a0f27431acb290","cbe53eec6fdd92b1"]]},{"id":"bbb628a2b47c6123","type":"interval-length","z":"6a68026e32f5ba52","format":"human","bytopic":false,"minimum":"","maximum":"","window":"","timeout":false,"msgTimeout":"","minimumunit":"mins","maximumunit":"mins","windowunit":"mins","msgTimeoutUnit":"hours","reset":false,"startup":false,"msgField":"payload","timestampField":"timestamp","repeatTimeout":false,"name":"","x":640,"y":460,"wires":[["b0e771f05731b993"],[]]},{"id":"d1937342f7f770e3","type":"ui_text","z":"6a68026e32f5ba52","group":"377d6acc.b0a0fe","order":22,"width":0,"height":0,"name":"","label":"Cycle Time ON Timestamp","format":"<font color=\"green\"> {{msg.payload}} </font>","layout":"col-center","x":1080,"y":440,"wires":[]},{"id":"e4f1476d6c262c96","type":"switch","z":"6a68026e32f5ba52","name":"","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"10m 1s","vt":"str"},{"t":"lt","v":"6m 30s","vt":"str"},{"t":"lt","v":"3m 1s","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":4,"x":1010,"y":380,"wires":[["8f95491314f35713"],["92d7b8589075a7b5"],["a8be29f8bb30e8f2"],["35759519914dc3ca"]]},{"id":"8abb5b66bf8c60b9","type":"debug","z":"6a68026e32f5ba52","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1030,"y":320,"wires":[]},{"id":"cbe53eec6fdd92b1","type":"debug","z":"6a68026e32f5ba52","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":430,"y":500,"wires":[]},{"id":"72db5522cb6d70cb","type":"inject","z":"6a68026e32f5ba52","name":"Pow2 ON","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"stat/swampcooler/POWER2","payload":"ON","payloadType":"str","x":120,"y":400,"wires":[["ff0dbcfc6f24b90c"]]},{"id":"a8be29f8bb30e8f2","type":"debug","z":"6a68026e32f5ba52","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1190,"y":640,"wires":[]},{"id":"92d7b8589075a7b5","type":"debug","z":"6a68026e32f5ba52","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1190,"y":600,"wires":[]},{"id":"8f95491314f35713","type":"debug","z":"6a68026e32f5ba52","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1190,"y":560,"wires":[]},{"id":"35759519914dc3ca","type":"debug","z":"6a68026e32f5ba52","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1190,"y":680,"wires":[]},{"id":"151295fe0e3d4b9c","type":"change","z":"6a68026e32f5ba52","name":"Enable TIME","rules":[{"t":"set","p":"TIME-ENABLED","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":220,"wires":[[]]},{"id":"a33be7dc8b4ac853","type":"inject","z":"6a68026e32f5ba52","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":450,"y":220,"wires":[["151295fe0e3d4b9c"]]},{"id":"2e6760ea8db6f177","type":"ui_text","z":"6a68026e32f5ba52","group":"377d6acc.b0a0fe","order":22,"width":0,"height":0,"name":"","label":"Cycle Time OFF Timestamp","format":"<font color=\"red\"> {{msg.payload}} </font>","layout":"col-center","x":1080,"y":480,"wires":[]},{"id":"a7c2bf9b0e9f8107","type":"debug","z":"6a68026e32f5ba52","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1030,"y":520,"wires":[]},{"id":"b0e771f05731b993","type":"switch","z":"6a68026e32f5ba52","name":"TIME ENABLED","property":"TIME-ENABLED","propertyType":"flow","rules":[{"t":"false"},{"t":"true"}],"checkall":"true","repair":false,"outputs":2,"x":840,"y":460,"wires":[["d1937342f7f770e3","8abb5b66bf8c60b9","e4f1476d6c262c96"],["2e6760ea8db6f177","a7c2bf9b0e9f8107"]]},{"id":"377d6acc.b0a0fe","type":"ui_group","name":"Cooling System","tab":"c804efc8.e6e3","order":4,"disp":true,"width":"6","collapse":false},{"id":"c804efc8.e6e3","type":"ui_tab","name":"Raspberry Pi3 - Home Automation Control","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

So, in my testing just now, 1m 26.8s is less than 6m 30s and 3m 1s, but not less than 10m 1s.... I don't understand that.... I get that they are strings, but I guess I don't understand the string order of numbers. 1 should still be less than 10, right?

So, I still don't really understand it, but I've decided to do what was suggested and just do milliseconds for the time comparison. It works and is seems to be very accurate. Thank you for the help you guys!

Alphabetically, "1" is less than "10" but "1m" is greater than "10"