you missed the conversation i believe.
there was an inadvertant setting mistake in switch
node, which was noticed, and since 'string' value happen to evaluate as expected, the error was not noted.
you missed the conversation i believe.
there was an inadvertant setting mistake in switch
node, which was noticed, and since 'string' value happen to evaluate as expected, the error was not noted.
So are the actual values coming in Strings or Numbers?
the OP says it is from a certain Victron
Nodes and they are numeric, the switch node used however were wrongly set to 'string'. but the issue was not that actually
(it was due to not using different topics for inject nodes to maually simulate the conditon (was working with Victron nodes but not with inject nodes simulation since inject did not have different topics),
this wrong setting would also come into effect in right circumstances. (or wrong circumstances)
The data from the Victron nodes that I am using is Battery State of Charge between 0 and 100 (%) and Charge Current which could theoretically be between 100 Amps and -100 Amps.
I had no idea what I was doing when I used that switch node so I didn't even notice it was set to "string".
Node-RED is MESSAGE based. Logic gates are STATE based. Messages are classified using the TOPIC of the message as a classifier. The gate is defined as 2 input.
The topics are different, therefore input ONE and TWO. The states are expressed in the payload defined as boolean type. The ultimate logic outputs , AND, OR, XOR are shown. The message state is 'remembered' as you insert them ONE and TWO. The Output state changes with the input messages.
Hi, thanks for the explanation but I am still having trouble understanding why I get unexpected outputs. I am currently inputting a "1" and a "0" into a logic gate and getting AND "true".
Add a debug node showing what is going into the gate node and show us what is there. Also show us how you now have the gate node configured.
Set the debug node to output the complete message.
I thought I had read somewhere above that you have it working?
So that we can understand and perhaps explain what's going on, please post an export of a flow in which you can inject a 1 and a 0 but the AND output is "true".
No Victron nodes though, use inject nodes to inject identical data to the Vicron output.
Does the topic
of a payload
, also flow into next node, if a switch
node is used in between?
Edit: I just did a check in a test flow and it does. So please ignore the query,
I was just thinking since the OP is taking data from Victron nodes, checking the condition through switch node to generate the 1 or 0 and then feeding the gate, there may be an issue with topic.
The below flow, gives me correctly. if i inject true/true I get true in AND operation as expected.
[{"id":"02c360c9c0900403","type":"inject","z":"370cbf905893daf4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"one","payload":"true","payloadType":"bool","x":240,"y":1800,"wires":[["bc23e3c2bc383775"]]},{"id":"bc23e3c2bc383775","type":"switch","z":"370cbf905893daf4","name":"","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"30","vt":"num"},{"t":"gte","v":"30","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":430,"y":1830,"wires":[["6aaef2607b6df86a","f2ae016f782a3c2b"],["6aaef2607b6df86a","f2ae016f782a3c2b"]]},{"id":"a32d1b90fd97e444","type":"inject","z":"370cbf905893daf4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"two","payload":"false","payloadType":"bool","x":240,"y":2040,"wires":[["e27e9ff8e86e9007"]]},{"id":"6aaef2607b6df86a","type":"BooleanLogicUltimate","z":"370cbf905893daf4","name":"","payloadPropName":"payload","filtertrue":"both","persist":true,"sInitializeWith":"WaitForPayload","triggertopic":"trigger","outputtriggeredby":"all","inputCount":2,"topic":"result","restrictinputevaluation":false,"delayEvaluation":0,"x":620,"y":1920,"wires":[["c73f201bac554932"],[],[]]},{"id":"f2eb784ce7a91e88","type":"inject","z":"370cbf905893daf4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"one","payload":"false","payloadType":"bool","x":240,"y":1860,"wires":[["bc23e3c2bc383775"]]},{"id":"0c308dd276ff04f2","type":"inject","z":"370cbf905893daf4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"two","payload":"true","payloadType":"bool","x":230,"y":1980,"wires":[["e27e9ff8e86e9007"]]},{"id":"e27e9ff8e86e9007","type":"switch","z":"370cbf905893daf4","name":"","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"30","vt":"num"},{"t":"gte","v":"30","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":430,"y":2010,"wires":[["6aaef2607b6df86a","e6c09bf2c7622f1a"],["6aaef2607b6df86a","e6c09bf2c7622f1a"]]},{"id":"c73f201bac554932","type":"debug","z":"370cbf905893daf4","name":"debug 412","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":800,"y":1890,"wires":[]},{"id":"f2ae016f782a3c2b","type":"debug","z":"370cbf905893daf4","name":"debug 413","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":640,"y":1800,"wires":[]},{"id":"e6c09bf2c7622f1a","type":"debug","z":"370cbf905893daf4","name":"debug 414","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":650,"y":2040,"wires":[]}]
I think my issues may come from the node waiting for 2 inputs and some of the rules around that. Sometimes the gate says true when one of the inputs is false but it is perhaps waiting for a second new message before it changes state. Your example there is fine but you always input 2 messages so you always get a correct result but it seems these nodes need two inputs each time for a change of state, i.e. you cannot expect a change if you only send one new input.
At least I think that is what's happening but I am happy to be corrected.
I believe that the node has a setting to change that.
I would love to know how. I've messed with the settings a fair amount and still not sure if I've really got it working the way it "should".
Boolean states are expressed like ON/OFF. For most programming like Javascript the values are expressed as True/False. True/False is used in Logic because Logic statements are expressed as a False Statement or a True Statement. False is evaluated to 0 and True is evaluated to 1. For bit logic gates, 1 is 5 volts and then 0 is 0 Volts or common. The gate in Node-RED will accept a 0 number and a 1 number bit values are not an actual 1 or 0, but states On/Off or also True/False. It is convenient to express states as 1 & 0. It then outputs the logical result as True/False. You can convert False = 0 and True = 1 through a Switch node.
A boolean logic example.
Lets say, This = True, That = False.
This AND That is False, 0
This AND NOT That is True, 1
This OR That is True, 1
Only for the first time, subsequently every single input it evaluates, by comparing last two inputs.
in this logic gate the inputs are sent to the same input, The topic will separate them to input ONE or input TWO. This is so that you don't have to worry about the input, but change the name of the input message to say if it's input ONE or TWO.
Message Topic = ONE or TWO. Payload = State True/False.
The example flow I posted shows you the payload 'state' and the Topic name. You can also send more topic names. Then also you can configure the logic gate node to how many inputs you'd like. If you have physical inputs you have to wire them. Here, you don't need to worry about it, just wire them all to the single input.
I understand all that you say about logic gates, that's not my issue at all. What I am puzzled by is that I have found (or at least I think I have) that sometimes the debug nodes are showing a "1" and a "0" on the node input yet the AND output is "true".
I think I have got over this but I can't remember exactly how (!) so it seems to be working fine but when my flow restarts in a while I will watch it for that and take a screenshot.
I have changed away from Ultimate boolean to another node but when I was trying with Ultimate I used the node in that mode.
Here is a screenshot of what I am talking about:
Look at debug 272 and 280
That tells us nothing unless you do what I asked, which is to set the debug nodes to output the complete message and show us the debug sequence output in the debug pane.