Supergiovane / node-red-contrib-boolean-logic-ultimate

Enhanced boolean logic with persistent values after reboot and more
https://www.youtube.com/watch?v=sYc6L5QQrTw&list=PL9Yh1bjbLAYoRH4IyQB7EL5srHAihiKpy
MIT License
27 stars 3 forks source link

null in the notification area #4

Closed GeorgeCastanza closed 4 years ago

GeorgeCastanza commented 4 years ago

Hi there,

I'm using your Boolean Ultimate Logic node (a lot). it's been great. Recently I added a created a new flow, and I'm getting lots of null's in the notification area. I'm unsure as to why. I know they have received the right amount of payloads (3 if expecting 3).

I have two flows that receive the same (but reversed) payloads, one is showing as it should, the second is showing nulls.

image

Supergiovane commented 4 years ago

Hello George I need to view, what are you passing to the boolean Logic node. Can you please paste here the code of your flow? Not all flow, you can paste only the affected portion.

GeorgeCastanza commented 4 years ago

[{"id":"34f57d5.da43382","type":"function","z":"1adc6153.89ed1f","name":"TV Lux?","func":"var lux = flow.get(\"tv_lux\");\nif (lux < 12 ) {\n msg.topic1 = 'tvlux';\n msg.payload1 = true;\n msg.payload2 = false;\n node.status({text:\"Dark in TV\"});\n} else if (lux >= 12) {\n msg.topic1 = 'tvlux';\n msg.payload1 = false;\n msg.payload2 = true;\n node.status({text:\"Bright in TV\"});\n}\nvar msg1 = {topic:msg.topic1, payload:msg.payload1 };\nvar msg2 = {topic:msg.topic1, payload:msg.payload2 };\nreturn [ msg1, msg2 ];\n","outputs":2,"noerr":0,"x":115,"y":560,"wires":[["b606c3fd.fd7d4"],["64942ab8.996ca4"]],"outputLabels":["dark","bright"],"l":false},{"id":"fb6f30c9.b15dc","type":"link in","z":"1adc6153.89ed1f","name":"","links":["f99f441e.190ff8"],"x":35,"y":560,"wires":[["34f57d5.da43382"]]},{"id":"508bda0d.dcd224","type":"link in","z":"1adc6153.89ed1f","name":"","links":["77652a37.be5b14"],"x":35,"y":500,"wires":[["88995e31.20d67"]]},{"id":"88995e31.20d67","type":"function","z":"1adc6153.89ed1f","name":"Outside Lux?","func":"if (global.get(\"lux_out\") ===\"dark\") {\n msg.topic1 = 'outlux';\n msg.payload1 = true;\n msg.payload2 = false;\n node.status({text:\"Dark Outside\"});\n} else if (global.get(\"lux_out\") ===\"bright\") {\n msg.topic1 = 'outlux';\n msg.payload1 = false;\n msg.payload2 = true;\n node.status({text:\"Bright Outside\"});\n}\nvar msg1 = {topic:msg.topic1, payload:msg.payload1 };\nvar msg2 = {topic:msg.topic1, payload:msg.payload2 };\nreturn [ msg1, msg2 ];","outputs":2,"noerr":0,"x":115,"y":500,"wires":[["b606c3fd.fd7d4"],["64942ab8.996ca4"]],"outputLabels":["Dark","Bright"],"l":false},{"id":"b606c3fd.fd7d4","type":"BooleanLogicUltimate","z":"1adc6153.89ed1f","name":"Dark (TV OR Out)","filtertrue":"onlytrue","persist":true,"sInitializeWith":"false","triggertopic":"trigger","outputtriggeredby":"all","inputCount":"3","topic":"dark","x":340,"y":500,"wires":[[],["bebe7627.eb5bc8"],[]]},{"id":"64942ab8.996ca4","type":"BooleanLogicUltimate","z":"1adc6153.89ed1f","name":"Bright (Out AND TV)","filtertrue":"onlytrue","persist":true,"sInitializeWith":"WaitForPayload","triggertopic":"trigger","outputtriggeredby":"all","inputCount":"3","topic":"bright","x":350,"y":580,"wires":[["bebe7627.eb5bc8"],[],[]]},{"id":"a415de99.f8ae5","type":"hue-light","z":"1adc6153.89ed1f","name":"Light - Curtain lights (Hue)","bridge":"5f7ec117.46945","lightid":"10","colornamer":true,"skipevents":false,"x":55,"y":620,"wires":[["6aea7b30.b6e6f4"]],"l":false},{"id":"6aea7b30.b6e6f4","type":"function","z":"1adc6153.89ed1f","name":"","func":"switch (msg.payload.on) {\n case true:\n var newmsg1 = {topic: \"hue_light\", payload: true}\n var newmsg3 = {topic: \"hue_light\", payload: false}\n return [newmsg1, newmsg3]\n case false:\n var newmsg2 = {topic: \"hue_light\", payload: false}\n var newmsg4 = {topic: \"hue_light\", payload: true}\n return [newmsg2, newmsg4]\n}","outputs":2,"noerr":0,"x":115,"y":620,"wires":[["b606c3fd.fd7d4"],["64942ab8.996ca4"]],"l":false},{"id":"5f7ec117.46945","type":"hue-bridge","z":"","name":"Philips hue","bridge":"192.168.1.221","key":"edited","interval":"3000","disableupdates":false}]

Supergiovane commented 4 years ago

Hello ther's an issue in inporting the code. Cannot paste it into my flows because of a json error. Can you try to zip the exported flow and then attach it here?

GeorgeCastanza commented 4 years ago

[{"id":"34f57d5.da43382","type":"function","z":"1adc6153.89ed1f","name":"TV Lux?","func":"var lux = flow.get(\"tv_lux\");\nif (lux < 12 ) {\n msg.topic1 = 'tvlux';\n msg.payload1 = true;\n msg.payload2 = false;\n node.status({text:\"Dark in TV\"});\n} else if (lux >= 12) {\n msg.topic1 = 'tvlux';\n msg.payload1 = false;\n msg.payload2 = true;\n node.status({text:\"Bright in TV\"});\n}\nvar msg1 = {topic:msg.topic1, payload:msg.payload1 };\nvar msg2 = {topic:msg.topic1, payload:msg.payload2 };\nreturn [ msg1, msg2 ];\n","outputs":2,"noerr":0,"x":115,"y":560,"wires":[["b606c3fd.fd7d4"],["64942ab8.996ca4"]],"outputLabels":["dark","bright"],"l":false},{"id":"fb6f30c9.b15dc","type":"link in","z":"1adc6153.89ed1f","name":"","links":["f99f441e.190ff8"],"x":35,"y":560,"wires":[["34f57d5.da43382"]]},{"id":"508bda0d.dcd224","type":"link in","z":"1adc6153.89ed1f","name":"","links":["77652a37.be5b14"],"x":35,"y":500,"wires":[["88995e31.20d67"]]},{"id":"88995e31.20d67","type":"function","z":"1adc6153.89ed1f","name":"Outside Lux?","func":"if (global.get(\"lux_out\") ===\"dark\") {\n msg.topic1 = 'outlux';\n msg.payload1 = true;\n msg.payload2 = false;\n node.status({text:\"Dark Outside\"});\n} else if (global.get(\"lux_out\") ===\"bright\") {\n msg.topic1 = 'outlux';\n msg.payload1 = false;\n msg.payload2 = true;\n node.status({text:\"Bright Outside\"});\n}\nvar msg1 = {topic:msg.topic1, payload:msg.payload1 };\nvar msg2 = {topic:msg.topic1, payload:msg.payload2 };\nreturn [ msg1, msg2 ];","outputs":2,"noerr":0,"x":115,"y":500,"wires":[["b606c3fd.fd7d4"],["64942ab8.996ca4"]],"outputLabels":["Dark","Bright"],"l":false},{"id":"b606c3fd.fd7d4","type":"BooleanLogicUltimate","z":"1adc6153.89ed1f","name":"Dark (TV OR Out)","filtertrue":"onlytrue","persist":true,"sInitializeWith":"false","triggertopic":"trigger","outputtriggeredby":"all","inputCount":"3","topic":"dark","x":340,"y":500,"wires":[[],["bebe7627.eb5bc8"],[]]},{"id":"64942ab8.996ca4","type":"BooleanLogicUltimate","z":"1adc6153.89ed1f","name":"Bright (Out AND TV)","filtertrue":"onlytrue","persist":true,"sInitializeWith":"WaitForPayload","triggertopic":"trigger","outputtriggeredby":"all","inputCount":"3","topic":"bright","x":350,"y":580,"wires":[["bebe7627.eb5bc8"],[],[]]},{"id":"a415de99.f8ae5","type":"hue-light","z":"1adc6153.89ed1f","name":"Light - Curtain lights (Hue)","bridge":"5f7ec117.46945","lightid":"10","colornamer":true,"skipevents":false,"x":55,"y":620,"wires":[["6aea7b30.b6e6f4"]],"l":false},{"id":"6aea7b30.b6e6f4","type":"function","z":"1adc6153.89ed1f","name":"","func":"switch (msg.payload.on) {\n case true:\n var newmsg1 = {topic: \"hue_light\", payload: true}\n var newmsg3 = {topic: \"hue_light\", payload: false}\n return [newmsg1, newmsg3]\n case false:\n var newmsg2 = {topic: \"hue_light\", payload: false}\n var newmsg4 = {topic: \"hue_light\", payload: true}\n return [newmsg2, newmsg4]\n}","outputs":2,"noerr":0,"x":115,"y":620,"wires":[["b606c3fd.fd7d4"],["64942ab8.996ca4"]],"l":false},{"id":"5f7ec117.46945","type":"hue-bridge","z":"","name":"Philips hue","bridge":"192.168.1.221","key":"edited","interval":"3000","disableupdates":false}]

GeorgeCastanza commented 4 years ago

Sorry, I put this in the code quotes. And imported back into NodeRed, and it worked. Thanks for your help on this. Compared to yesterday, the other Boolean Ulitmate is showing null, so something is amiss, unless there is a change, but I checked the changelog.

Supergiovane commented 4 years ago

Hi If global.get("lux_out") doesn't return "dark" or "bright", you'll sent a message with undefined payload to the boolean logic. I suspect that boolean logic node, receives a message input before global.get("lux_out") has been set. Please replace the first two functions with this:

[{"id":"a2c17479.0c1cd","type":"function","z":"92e37572.5947f8","name":"TV Lux?","func":"var lux = flow.get(\"tv_lux\");\nif (lux < 12 ) {\n msg.topic1 = 'tvlux';\n msg.payload1 = true;\n msg.payload2 = false;\n node.status({text:\"Dark in TV\"});\n} else if (lux >= 12) {\n msg.topic1 = 'tvlux';\n msg.payload1 = false;\n msg.payload2 = true;\n node.status({text:\"Bright in TV\"});\n}else{\n return;\n}\nvar msg1 = {topic:msg.topic1, payload:msg.payload1 };\nvar msg2 = {topic:msg.topic1, payload:msg.payload2 };\nreturn [ msg1, msg2 ];\n","outputs":2,"noerr":0,"x":195,"y":320,"wires":[["9da08256.65355"],["896a1250.db2488"]],"outputLabels":["dark","bright"],"l":false},{"id":"6bab34d2.38e2ac","type":"function","z":"92e37572.5947f8","name":"Outside Lux?","func":"if (global.get(\"lux_out\") ===\"dark\") {\n msg.topic1 = 'outlux';\n msg.payload1 = true;\n msg.payload2 = false;\n node.status({text:\"Dark Outside\"});\n} else if (global.get(\"lux_out\") ===\"bright\") {\n msg.topic1 = 'outlux';\n msg.payload1 = false;\n msg.payload2 = true;\n node.status({text:\"Bright Outside\"});\n}else{\n return;\n}\nvar msg1 = {topic:msg.topic1, payload:msg.payload1 };\nvar msg2 = {topic:msg.topic1, payload:msg.payload2 };\nreturn [ msg1, msg2 ];","outputs":2,"noerr":0,"x":195,"y":260,"wires":[["9da08256.65355"],["896a1250.db2488"]],"outputLabels":["Dark","Bright"],"l":false}]

GeorgeCastanza commented 4 years ago

Thanks for bearing with me. However, the global variable has been set for many months. It's either, dark or light. Never anything else. Anyway, I tried your suggested code, and it's still showing the error. Note: the error is not with the output of the Node, only the text shown under the Node itself in light gray.

Notice how the null is now in the bottom node, whereas in my post above (post 1), it was the top node. The null should be showing "false".

image

Supergiovane commented 4 years ago

Hello, yes i saw this. null null null, means that the node is not outputting any message, because all 3 input topics are false. You set the boolean logic to output only "true" values. That's normal. "Null" means "no values are sent". In the next version, i'll replace "null" with something more meaningfull.

GeorgeCastanza commented 4 years ago

Ahh, Ok. Then there is no error. My apologies.

GeorgeCastanza commented 4 years ago

Are you able to update the docs for future people. Great node by the way!