Change value: 1 to true

good night i am new to this program and i find it very interesting i am learning from the good going to the problem and connected a nano plc and i want to activate the output the registry votes me a value 1 but i want to change that to true to be able to activate the output that solution could have here. Thank you.

in this graph the value is shown

In this other graph the value that it reads from msg to change it to true or false but without good result

and in the latter what I wrote in the function to be able to have the value

Thank you in advance for your help

your change node is not working because you are looking for the 0 in the wrong place. You’re msg.payload is an object. instead of payload put the path to the value key that you already have in the function into your change node:

Also if you are dealing with numbers rather than strings (which I think you are) then you should test for equals 0 rather then search for 0.

With this flow works well the output of the plc is activated
image

Taking as reference this flow that works correctly I try to do the same with the block of ubidots with which I have no results with the first flow it works well for me (MQTT) but with the second it does not respond there are no changes in the plc I already did the indicated for you but without improvement

Have a play with this. You don’t need the function but just one change node:

[{"id":"2652ecbf.ebc88c","type":"inject","z":"20693e98.c7fb2a","name":"","topic":"","payload":"{\"pulse_2\":{\"value\":0}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":820,"wires":[["b9a390ee.5e7d98"]]},{"id":"5f063935.ddf168","type":"inject","z":"20693e98.c7fb2a","name":"","topic":"","payload":"{\"pulse_2\":{\"value\":1}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":900,"wires":[["b9a390ee.5e7d98"]]},{"id":"b9a390ee.5e7d98","type":"change","z":"20693e98.c7fb2a","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.pulse_2.value","tot":"msg"},{"t":"change","p":"payload","pt":"msg","from":"0","fromt":"num","to":"false","tot":"bool"},{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"num","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":860,"wires":[["c912584d.a2b9f"]]},{"id":"c912584d.a2b9f","type":"debug","z":"20693e98.c7fb2a","name":"true/false?","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":670,"y":860,"wires":[]}]

if you would want to do it in a function it would only be the function instead of the change node:

msg.payload = (msg.payload.pulse_2.value === 0) ? false : true; 
return msg;

and no change node at all.

1 Like

Thanks JGKK in both ways I work excellent the node thank you very much for your support.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.