# Change value: 1 to true

**URL:** https://discourse.nodered.org/t/change-value-1-to-true/28861
**Category:** General
**Created:** [24 June 2020 06:01 UTC](https://discourse.nodered.org/t/change-value-1-to-true/28861 "2020-06-24T06:01:50Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![carmar19](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/carmar19/32/27468_2.png) [@carmar19](https://discourse.nodered.org/u/carmar19)
#### Post date: [24 June 2020 06:01 UTC](https://discourse.nodered.org/t/change-value-1-to-true/28861/1 "2020-06-24T06:01:50Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/5/d52da41a45f177a696a24c63b52334633a133b03.png)

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/9/193c90fbc648fab3aff5bb575a5cc00194057c04.png)

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/4/64c3d89d075bbac435ac063061ae10848255ce51.png)

Thank you in advance for your help

---

<div class="post-metadata">

### Author: ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)
#### Post date: [24 June 2020 06:27 UTC](https://discourse.nodered.org/t/change-value-1-to-true/28861/2 "2020-06-24T06:27:39Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/3/c370d5983002c94e52467ee6f927327ad1b43191.jpeg)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [24 June 2020 07:49 UTC](https://discourse.nodered.org/t/change-value-1-to-true/28861/3 "2020-06-24T07:49:42Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![carmar19](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/carmar19/32/27468_2.png) [@carmar19](https://discourse.nodered.org/u/carmar19)
#### Post date: [24 June 2020 15:05 UTC](https://discourse.nodered.org/t/change-value-1-to-true/28861/5 "2020-06-24T15:05:17Z")

</div>

With this flow works well the output of the plc is activated  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/2/b2d794e2523972c0fac451f3b08c38f7a5e68a48.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/e/1e59afd03618c0d5022100e7917c0111fc39f604.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/f/6f309185d008133fc2dc6b860b281488a3e360fd.png)

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/f/1fc4269cade4690cc0d4130d27f83bdd6454a5cb.png)

---

<div class="post-metadata">

### Author: ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)
#### Post date: [25 June 2020 08:56 UTC](https://discourse.nodered.org/t/change-value-1-to-true/28861/6 "2020-06-25T08:56:06Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/8/989830f048f21166aa8199e7cbc764bcb9b40e7b.jpeg)

```auto
[{"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:

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

```

and no change node at all.

---

<div class="post-metadata">

### Author: ![carmar19](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/carmar19/32/27468_2.png) [@carmar19](https://discourse.nodered.org/u/carmar19)
#### Post date: [26 June 2020 06:40 UTC](https://discourse.nodered.org/t/change-value-1-to-true/28861/7 "2020-06-26T06:40:22Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [21 July 2020 04:03 UTC](https://discourse.nodered.org/t/change-value-1-to-true/28861/8 "2020-07-21T04:03:18Z")

</div>

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