Need help with the error part please! Cannot display error

I am trying to display an error if the value is less than or equal to zero, but it for some reasons isn't working. I have tried searching, but no luck. I know it is probably something very small that needs to be fixed though I am not able to figure it out. I have been struggling on this for 2 days now. Any help will be appreciated. I am not sure if there is a way to add a node or display it within the code.
I prefer if I can add a separate node to display error. I have attached my flow below. If someone can please help me with the solution for this.

[{"id":"cb816b24.fe39e8","type":"inject","z":"350d0535.68069a","name":"LuxReading","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Lux:340","payloadType":"str","x":210,"y":360,"wires":[["a47c5a17.2edfb8"]]},{"id":"aea09e2c.4c494","type":"split","z":"350d0535.68069a","name":"","splt":":","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":530,"y":360,"wires":[["7fcd5036.5961b"]]},{"id":"7fcd5036.5961b","type":"switch","z":"350d0535.68069a","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":690,"y":360,"wires":[["29a1d2c9.5eefee"]]},{"id":"29a1d2c9.5eefee","type":"function","z":"350d0535.68069a","name":"Comparison ","func":"msg.payload = Number (msg.payload);\nmsg.Lux; // new stored value\nvar actualLux = 400;\n\n//comapring reading and the actual value for red\nif(msg.payload <= 0) // if less than or equal to zero then it should\n                     // disaply error\n{\n    msg.Lux = \"Something is wrong\";\n    return msg;\n}\nelse if (msg.payload == actualLux)  // keeps it same if matches\n{\n   return msg;\n}\nelse if(msg.payload > actualLux) // adjust the value accordingly\n{\n    correction = msg.payload - actualLux;\n    msg.Lux = msg.payload - correction;\n    return msg;\n}\nelse if(msg.payload < actualLux)  // adjust the value accordingly\n{\n    correction = actualLux - msg.payload;\n    msg.Lux = msg.payload + correction;\n    return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":850,"y":360,"wires":[["a4c764cf.6e1a38"]]},{"id":"a4c764cf.6e1a38","type":"debug","z":"350d0535.68069a","name":"Lux_Value","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1040,"y":360,"wires":[]},{"id":"a47c5a17.2edfb8","type":"switch","z":"350d0535.68069a","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"Lux","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":370,"y":360,"wires":[["aea09e2c.4c494"]]}]

Thank you!!

Looking at the switch node.

Which message will be passed ? One that has a value larger than 0.
So the function node will never see a payload <1

I dont understand the split node either.
Maybe something like this.

[{"id":"2f34c5ac.444dca","type":"inject","z":"8d22ae29.7df6d","name":"LuxReading","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Lux:340","payloadType":"str","x":160,"y":3201,"wires":[["e4e62746.44a79"]]},{"id":"e4e62746.44a79","type":"switch","z":"8d22ae29.7df6d","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"Lux","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":320,"y":3200,"wires":[["d20169ec.017868"]]},{"id":"d20169ec.017868","type":"function","z":"8d22ae29.7df6d","name":"Comparison ","func":"msg.payload = Number (msg.payload.split(\":\")[1]);\nmsg.Lux = 0; // new stored value\nvar actualLux = 400;\n\n//comapring reading and the actual value for red\nif(msg.payload <= 0 || isNaN(msg.payload)) // if less than or equal to zero then it should\n                     // disaply error\n{\n    node.warn(\"Something is wrong\");\n    return;\n}\nelse if (msg.payload == actualLux)  // keeps it same if matches\n{\n   return msg;\n}\nelse if(msg.payload > actualLux) // adjust the value accordingly\n{\n    correction = msg.payload - actualLux;\n    msg.Lux = msg.payload - correction;\n    return msg;\n}\nelse if(msg.payload < actualLux)  // adjust the value accordingly\n{\n    correction = actualLux - msg.payload ;\n    msg.Lux = msg.payload + correction;\n    return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":480,"y":3200,"wires":[["cfc5e4c3.db4838"]]},{"id":"f7e9ea6c.f6b3d","type":"inject","z":"8d22ae29.7df6d","name":"lux 440","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Lux:440","payloadType":"str","x":120,"y":3260,"wires":[["e4e62746.44a79"]]},{"id":"4036ee2e.6b1b","type":"inject","z":"8d22ae29.7df6d","name":"Lux junk","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Lux:dd","payloadType":"str","x":140,"y":3300,"wires":[["e4e62746.44a79"]]},{"id":"d47fc6e8.d057d8","type":"inject","z":"8d22ae29.7df6d","name":"Lux < 0","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Lux:-1","payloadType":"str","x":140,"y":3340,"wires":[["e4e62746.44a79"]]},{"id":"cfc5e4c3.db4838","type":"debug","z":"8d22ae29.7df6d","name":"Lux_Value","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":650,"y":3200,"wires":[]}]
1 Like

Thank you so much for your response. I have a question: Is there a way I can do a pop message and how would that work. Also, is it possible to do within the code?

Oh so I can pass multiple inside the switch node?

split node I used to catch the colon sign so it splits the Lux and the value using colon. Also do I have to inject the less than zero in a separate node for it to show error message?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.