# Change node problem

**URL:** <https://discourse.nodered.org/t/change-node-problem/14963>\
**Category:** General\
**Created:** [30 August 2019 20:57 UTC](https://discourse.nodered.org/t/change-node-problem/14963 "2019-08-30T20:57:42Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![seymour](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@seymour](https://discourse.nodered.org/u/seymour)\
**Post date:** [30 August 2019 20:57 UTC](https://discourse.nodered.org/t/change-node-problem/14963/1 "2019-08-30T20:57:42Z")

</div>

Hi, I'm trying to change a command from true to on and from false to off in order to make a state node for alexa work but It doesn't change the message and still give back TRUE and FALSE, I'll attach some pics.

What did i do wrong?  
Thanks  
 ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/9df7fe3e58779700fdee48ba1e25fc2a664c4485.png) ![2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/e5ec3ac7ada43870820bdc9985071f2b9a56e6f6.png)

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [30 August 2019 20:59 UTC](https://discourse.nodered.org/t/change-node-problem/14963/2 "2019-08-30T20:59:27Z")

</div>

is it a string true and false (see the a z ) or Boolean True and False?

You should be able to tell by looking at the debug message.

---

<div class="post-metadata">

**Author:** ![seymour](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@seymour](https://discourse.nodered.org/u/seymour)\
**Post date:** [30 August 2019 21:03 UTC](https://discourse.nodered.org/t/change-node-problem/14963/3 "2019-08-30T21:03:38Z")

</div>

I really don't know, this is the message

30 Aug 23:01:28 - [warn] [alexa-smart-home-v3-state:Luce Cucina] Luce Cucina sta te node: msg.payload missing state element!  
30 Aug 23:01:28 - [info] [debug:8164d137.6a184] false  
30 Aug 23:01:40 - [warn] [alexa-smart-home-v3-state:Luce Cucina] Luce Cucina state node: msg.payload missing state element!  
30 Aug 23:01:40 - [info] [debug:8164d137.6a184] true  
30 Aug 23:01:28 - [warn] [alexa-smart-home-v3-state:Luce Cucina] Luce Cucina sta te node: msg.payload missing state element!  
30 Aug 23:01:28 - [info] [debug:8164d137.6a184] false  
30 Aug 23:01:40 - [warn] [alexa-smart-home-v3-state:Luce Cucina] Luce Cucina state node: msg.payload missing state element!

---

<div class="post-metadata">

**Author:** ![seymour](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@seymour](https://discourse.nodered.org/u/seymour)\
**Post date:** [30 August 2019 21:09 UTC](https://discourse.nodered.org/t/change-node-problem/14963/4 "2019-08-30T21:09:28Z")

</div>

I checked, it's a string (switch?) not boolean

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [30 August 2019 21:10 UTC](https://discourse.nodered.org/t/change-node-problem/14963/5 "2019-08-30T21:10:00Z")

</div>

Try;

```auto
[{"id":"46272d11.0c1764","type":"inject","z":"c53060.842a0fa","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":1090,"wires":[["7c2fb603.bd9348"]]},{"id":"3b944448.a4189c","type":"inject","z":"c53060.842a0fa","name":"","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":1150,"wires":[["7c2fb603.bd9348"]]},{"id":"7c2fb603.bd9348","type":"change","z":"c53060.842a0fa","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"ON","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":1120,"wires":[["dc0fb137.8cb1b"]]},{"id":"dc0fb137.8cb1b","type":"debug","z":"c53060.842a0fa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":620,"y":1120,"wires":[]}]

```

True & False are boolean operators NOT strings!

---

<div class="post-metadata">

**Author:** ![seymour](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@seymour](https://discourse.nodered.org/u/seymour)\
**Post date:** [30 August 2019 21:12 UTC](https://discourse.nodered.org/t/change-node-problem/14963/6 "2019-08-30T21:12:01Z")

</div>

> [@Paul-Reed](#):
>
> ```auto
> [{"id":"46272d11.0c1764","type":"inject","z":"c53060.842a0fa","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":1090,"wires":[["7c2fb603.bd9348"]]},{"id":"3b944448.a4189c","type":"inject","z":"c53060.842a0fa","name":"","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":1150,"wires":[["7c2fb603.bd9348"]]},{"id":"7c2fb603.bd9348","type":"change","z":"c53060.842a0fa","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"ON","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":1120,"wires":[["dc0fb137.8cb1b"]]},{"id":"dc0fb137.8cb1b","type":"debug","z":"c53060.842a0fa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":620,"y":1120,"wires":[]}]
> 
> ```

Ok it's working, thank you 🙂

---

<div class="post-metadata">

**Author:** ![Poodlepapa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/poodlepapa/32/8174_2.png) [@Poodlepapa](https://discourse.nodered.org/u/Poodlepapa)\
**Post date:** [21 October 2019 20:02 UTC](https://discourse.nodered.org/t/change-node-problem/14963/7 "2019-10-21T20:02:00Z")

</div>

I am having the same issue only with numbers. My issue is that some of my devices use TIP120's and others use relays. The logic for each is opposite 0= on for relay or 1 = on for TIPS  
I made a simple change node to convert them (using numbers and it works to convert the 1 to a zero but not the other way)

I have attached a picture of the debug screen and the change node configuration. I have tried many types of message types and none seem to work.  
What am I missing?

 ![04%20AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/afd35756e5d6f87b9d5e8dc2f058456ebf3a1556.png)

---

<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:** [21 October 2019 20:22 UTC](https://discourse.nodered.org/t/change-node-problem/14963/8 "2019-10-21T20:22:51Z")

</div>

Consider what happens when you pass in 0. The first Change will change it to a 1. Unfortunately the second will then change it back to a 0.

---

<div class="post-metadata">

**Author:** ![Poodlepapa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/poodlepapa/32/8174_2.png) [@Poodlepapa](https://discourse.nodered.org/u/Poodlepapa)\
**Post date:** [21 October 2019 20:27 UTC](https://discourse.nodered.org/t/change-node-problem/14963/9 "2019-10-21T20:27:50Z")

</div>

OK thank you, so how do I create a something that will flip a 1 to a 0 and a 0 to a 1? this is a bit of an issue for me because of the different hardware that I've used. I'm planning on rebuilding most of these and going to strictly relays but until then is there a way to convert one to the other?

---

<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:** [21 October 2019 20:28 UTC](https://discourse.nodered.org/t/change-node-problem/14963/10 "2019-10-21T20:28:16Z")

</div>

Try this

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/318291b1fbdb95c8af7733314e525d054104f340.png)

---

<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:** [21 October 2019 20:30 UTC](https://discourse.nodered.org/t/change-node-problem/14963/11 "2019-10-21T20:30:58Z")

</div>

Or the same in a function

```auto
msg.payload = msg.payload ? 0 : 1

```

which relies on anything non zero being the same as true in a test

---

<div class="post-metadata">

**Author:** ![Poodlepapa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/poodlepapa/32/8174_2.png) [@Poodlepapa](https://discourse.nodered.org/u/Poodlepapa)\
**Post date:** [21 October 2019 20:37 UTC](https://discourse.nodered.org/t/change-node-problem/14963/12 "2019-10-21T20:37:59Z")

</div>

That worked! thank you very much! That helps with many of these nodes! I'm going to save that thing. Thanks

---

<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:** [21 October 2019 20:43 UTC](https://discourse.nodered.org/t/change-node-problem/14963/13 "2019-10-21T20:43:46Z")

</div>

That (and similar) is the one bit of JSONata that I use regularly. The rest just does not seem to fit the shape of my brain.

---

<div class="post-metadata">

**Author:** ![Poodlepapa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/poodlepapa/32/8174_2.png) [@Poodlepapa](https://discourse.nodered.org/u/Poodlepapa)\
**Post date:** [21 October 2019 20:53 UTC](https://discourse.nodered.org/t/change-node-problem/14963/14 "2019-10-21T20:53:23Z")

</div>

last thing, how do I make the output numbers not strings?

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [21 October 2019 20:56 UTC](https://discourse.nodered.org/t/change-node-problem/14963/15 "2019-10-21T20:56:46Z")

</div>

multiply by 1

---

<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:** [21 October 2019 21:09 UTC](https://discourse.nodered.org/t/change-node-problem/14963/16 "2019-10-21T21:09:56Z")

</div>

> [@Poodlepapa](#):
>
> how do I make the output numbers not strings?

My Jsonata example does generate numbers, for me anyway

```auto
[{"id":"ec018307.e0a388","type":"debug","z":"514a90a5.c7bae8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":561,"y":480,"wires":[]},{"id":"2121b60e.d3670a","type":"inject","z":"514a90a5.c7bae8","name":"","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":156,"y":441,"wires":[["55f36242.6a68dc"]]},{"id":"d916496a.267c58","type":"inject","z":"514a90a5.c7bae8","name":"","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":154,"y":503,"wires":[["55f36242.6a68dc"]]},{"id":"55f36242.6a68dc","type":"change","z":"514a90a5.c7bae8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload=1 ? 0 : 1","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":346,"y":480,"wires":[["ec018307.e0a388"]]}]

```

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [22 October 2019 18:30 UTC](https://discourse.nodered.org/t/change-node-problem/14963/18 "2019-10-22T18:30:57Z")

</div>

This may be a good case where converting the hw-specific outputs to a String (i.e. "on" or "off") would make your flows more maintainable... at least your other nodes won't have to wonder if they are testing for the string "1" or the number 1.

FYI, in JS you can also coerce numeric "strings" to numbers by using the unary `+` function:

```auto
msg.payload = +msg.payload;
return msg;

```

Of course, if you do not always expect your payload to be a valid numeric string, you should check to see if the unary `+` returns a `NaN` (not a number).
