Logic gate doesn't seem to behave logically

Sorry about that. I have replaced the victron nodes with some values that should emulate the equipment I'm using.

I will have a look at that flow as my solution to make the AND gate is quite complicated.

You have not posted the modified flow

Yes I noticed it was wrong.

Here it is:

[{"id":"7e3990660f331109","type":"switch","z":"427b38e8dd718872","name":"SoC 50%","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"50","vt":"str"},{"t":"gte","v":"50","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":321.99999237060547,"y":234.0000057220459,"wires":[["628a04013a442d2b"],["4e3e1791d494f834"]]},{"id":"628a04013a442d2b","type":"change","z":"427b38e8dd718872","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":586.9999923706055,"y":189.0000057220459,"wires":[["4995e8047d8fdd51"]]},{"id":"0b4746d6483380ac","type":"switch","z":"427b38e8dd718872","name":"Charge <10 or >20 Amps","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"10","vt":"str"},{"t":"gte","v":"20","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":338,"y":291.99999046325684,"wires":[["6ac5d9e8daaaeb3c"],["0067a70dd6c12ae3"]]},{"id":"4e3e1791d494f834","type":"change","z":"427b38e8dd718872","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":586.9999923706055,"y":249.0000057220459,"wires":[["4995e8047d8fdd51","19276f61c8cb70b3"]]},{"id":"6ac5d9e8daaaeb3c","type":"change","z":"427b38e8dd718872","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":586.9999923706055,"y":294.0000057220459,"wires":[["4995e8047d8fdd51"]]},{"id":"0067a70dd6c12ae3","type":"change","z":"427b38e8dd718872","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":586.9999923706055,"y":354.0000057220459,"wires":[["4995e8047d8fdd51","e28726885a314705"]]},{"id":"4995e8047d8fdd51","type":"BooleanLogicUltimate","z":"427b38e8dd718872","name":"","payloadPropName":"payload","filtertrue":"both","persist":true,"sInitializeWith":"false","triggertopic":"trigger","outputtriggeredby":"all","inputCount":2,"topic":"result","restrictinputevaluation":false,"delayEvaluation":0,"x":811.9999923706055,"y":264.0000057220459,"wires":[[],[],[]]},{"id":"f26cafa0351159bd","type":"inject","z":"427b38e8dd718872","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"49","payloadType":"num","x":103.39614486694336,"y":174.9846248626709,"wires":[["7e3990660f331109"]]},{"id":"9695df4cc79af59d","type":"inject","z":"427b38e8dd718872","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"51","payloadType":"num","x":100.39998626708984,"y":229.9807643890381,"wires":[["7e3990660f331109"]]},{"id":"e9433ddce9df6e42","type":"inject","z":"427b38e8dd718872","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"9","payloadType":"num","x":102.40385437011719,"y":295.98077677001953,"wires":[["0b4746d6483380ac"]]},{"id":"c967e1b3125d8471","type":"inject","z":"427b38e8dd718872","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"21","payloadType":"num","x":97.39614868164062,"y":351.9769315551758,"wires":[["0b4746d6483380ac"]]},{"id":"e28726885a314705","type":"debug","z":"427b38e8dd718872","name":"debug 68","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":846.3999557495117,"y":416.4384651184082,"wires":[]},{"id":"19276f61c8cb70b3","type":"debug","z":"427b38e8dd718872","name":"debug 69","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850.4038696289062,"y":109.43846414794922,"wires":[]}]

Actually I can't get that to work. It works OK in my main flow with the Victron nodes but when I inject two values that should give a "true" or even link two inputs so they inject at the same time and I see both outputs from the Set nodes come out "true" yet the AND gate says "false".

Three strong hints that your flow fails because there is no way for the boolean logic node to tell which message is which yet your latest flow still does not set different msg.topics.

I think that setting the node to initialize all inputs to false may be wrong too.

2 Likes

Thanks guys, putting different words in the topic makes it work as expected!
That's not quite as simple as a logic gate. Probably should be called something else.

I don't understand what you mean by that. It needs a way of distinguishing which input is which. Using the topic to identify the data source is the way that many, many nodes work in node red.

Also notice that I pointed out that you needed topics in my very first post. If you do not understand something in a post then you please ask, do not not just ignore it.

A NR node only has one input point.
Two successive messages could be from the same source rather than two different sources.
Thus it needs to distinguish the source using msg.topic.

I had the same problems because NR only has one input.
The solution was to count the number of incoming messages and
link the messages with logical operations until all messages have arrived.
The result of logical operations is then sent to the output.

AND
XOR

The contact node are inputs of Raspberry Pi GPIO for example.

Yes I made a mistake in assuming the node could differentiate between the two inputs. To be honest I'm not sure yet about the meaning and importance of topics nor am I ready for Javascript but hopefully with a bit of help I will get it eventually!
The flow worked ok when I use the Victron nodes but they already have different topics I suppose. I didn't get the importance.

Is there actually a node with two separate inputs? Just out of interest.

I noticed in the given flow that in switch node Soc 50% , the evaluationis done on string and not number, how does that work?

Ah! Thanks for that. I had no idea what I was doing!
I don't know how it works but it seems to once I made the topics different.

may be NR treats strings that look like numbers as numbers?

No! Strings are compared character by character.
"51" is greater than "50" but "100" is less than "50"

2 Likes

Ah! That's good to know.

In fact it would have worked for all numbers in the range (a percentage) up to but not including 100. At that point it would have failed and I would be scratching my head again.

Well yes except "49" < "7" etc.

From 10 to 99 then?

1 Like

If you want to compare numbers then you should convert them from String type to Number first.