I'm new to Node-RED, but not new to programming, so I have a basic understanding of what should work. Since I'm new though, I thought I'd see what you people say before I report a bug. I have the this setup in a change node.
I added a lot of images to clarify my case, but sadly this forum has some weird, unnecessary limits for new users.
Inputs are expected to be in the form of [true/false]-[true/false].
In my opinion, this should output a boolean true for input "true-true", and a boolean false for all other three options (true-false, false-true, false-false). Basically it's an AND gate.
The "true-true" input works fine, a boolean true comes out. All other three options though do not result in a boolean false, but a string false:
The same thing happens when I tell it to output a number 1, it outputs a string containing the number 1:
[{"id":"5f4fb69f255a7afd","type":"change","z":"f6f2187d.f17ca8","name":"Make boolean","rules":[{"t":"change","p":"payload","pt":"msg","from":"true-true","fromt":"str","to":"true","tot":"bool"},{"t":"change","p":"payload","pt":"msg","from":".*false.*","fromt":"re","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":2620,"y":900,"wires":[["f46e3f30e8f2459c"]]},{"id":"d25af463a7c58e7a","type":"inject","z":"f6f2187d.f17ca8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true-true","payloadType":"str","x":2420,"y":880,"wires":[["5f4fb69f255a7afd","a910c31af9a637b7"]]},{"id":"a0200cdbd74d6e7f","type":"inject","z":"f6f2187d.f17ca8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false-true","payloadType":"str","x":2420,"y":920,"wires":[["5f4fb69f255a7afd","a910c31af9a637b7"]]},{"id":"f46e3f30e8f2459c","type":"debug","z":"f6f2187d.f17ca8","name":"Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2770,"y":900,"wires":[]},{"id":"a910c31af9a637b7","type":"debug","z":"f6f2187d.f17ca8","name":"Input","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2590,"y":860,"wires":[]}]
I assume this is a bug of some sorts? It's some extremely confusing behavior to say the least.
Workaround
For those experiencing the same thing, I do have a workaround that works (as far as I've tested at least): Simply add another change item, to change the string 'false' to a boolean false.
I did change the change regex to boolean
to change regex to string
, so that when I come back to this after a long time, I don't look at this and go "hey that third item isn't required, it can be deleted", which would prevent my flow from working properly.
[{"id":"5f4fb69f255a7afd","type":"change","z":"f6f2187d.f17ca8","name":"Make boolean","rules":[{"t":"change","p":"payload","pt":"msg","from":"true-true","fromt":"str","to":"true","tot":"bool"},{"t":"change","p":"payload","pt":"msg","from":".*false.*","fromt":"re","to":"false","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"str","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":2620,"y":900,"wires":[["f46e3f30e8f2459c"]]},{"id":"d25af463a7c58e7a","type":"inject","z":"f6f2187d.f17ca8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true-true","payloadType":"str","x":2420,"y":880,"wires":[["5f4fb69f255a7afd","a910c31af9a637b7"]]},{"id":"a0200cdbd74d6e7f","type":"inject","z":"f6f2187d.f17ca8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false-true","payloadType":"str","x":2420,"y":920,"wires":[["5f4fb69f255a7afd","a910c31af9a637b7"]]},{"id":"f46e3f30e8f2459c","type":"debug","z":"f6f2187d.f17ca8","name":"Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2770,"y":900,"wires":[]},{"id":"a910c31af9a637b7","type":"debug","z":"f6f2187d.f17ca8","name":"Input","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2590,"y":860,"wires":[]}]