Hi,
I just need a simple way to convert a true or false to 1 or 0 from a payload message .
Any help would be much appreciated
Hi,
I just need a simple way to convert a true or false to 1 or 0 from a payload message .
Any help would be much appreciated
Hi @bceyresy,
The below will do it.
msg.payload = Number(msg.payload)
The JSONata way
$number(payload)
Thank you very much. Works fine.
Or
msg.payload += 0;
return msg;
Or low code
In a change node you can use the change option
[{"id":"43677a7267cf52d6","type":"inject","z":"b779de97.b1b46","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":150,"y":2640,"wires":[["53d978f68843dfa5"]]},{"id":"53d978f68843dfa5","type":"change","z":"b779de97.b1b46","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"1","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":2640,"wires":[["54c42fe9661c1a17"]]},{"id":"9cfdacc3b4d6b311","type":"inject","z":"b779de97.b1b46","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":150,"y":2700,"wires":[["53d978f68843dfa5"]]},{"id":"54c42fe9661c1a17","type":"debug","z":"b779de97.b1b46","name":"debug 2461","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":550,"y":2700,"wires":[]}]
Thanks E1Ccid. Both work well. I have another question,
I have 2 Sources of MQTT data coming in, i need a function that deducts them from each other. The issue is there is a slight delay between messages coming in, so i dont get the output.
[admin, have move this to its own topic.]
3 posts were split to a new topic: Subtract two separte messages