# Change Payload Value in Text

**URL:** <https://discourse.nodered.org/t/change-payload-value-in-text/85347>\
**Category:** General\
**Created:** [9 February 2024 07:57 UTC](https://discourse.nodered.org/t/change-payload-value-in-text/85347 "2024-02-09T07:57:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stefan8485](https://avatars.discourse-cdn.com/v4/letter/s/838e76/32.png) [@Stefan8485](https://discourse.nodered.org/u/Stefan8485)\
**Post date:** [9 February 2024 07:57 UTC](https://discourse.nodered.org/t/change-payload-value-in-text/85347/1 "2024-02-09T07:57:18Z")

</div>

Hello,

i have noting find in the search.  
is it possible to change the Payload Value 1 and 0 in a text for sending?

in attachment a picture from my test, but the sending is only 0 or 1 i don`t can change the value.

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

Thank you  
Stefan

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [9 February 2024 08:11 UTC](https://discourse.nodered.org/t/change-payload-value-in-text/85347/2 "2024-02-09T08:11:12Z")

</div>

Welcome.

sorry could not understand the requirement, but see if this is what you expected.

```auto
[{"id":"59d9020ac04ecaba","type":"inject","z":"53edcbb0228e136a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"This is a payload containing 0 and 1","payloadType":"str","x":590,"y":3540,"wires":[["689cb6fcabaa3307","d18685ac97441002"]]},{"id":"1ca1175f85b08435","type":"debug","z":"53edcbb0228e136a","name":"debug 2507","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":940,"y":3540,"wires":[]},{"id":"689cb6fcabaa3307","type":"change","z":"53edcbb0228e136a","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"0","fromt":"str","to":"(this was zero)","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"str","to":"(this was one)","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":3540,"wires":[["1ca1175f85b08435"]]},{"id":"d18685ac97441002","type":"debug","z":"53edcbb0228e136a","name":"debug 2508","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":920,"y":3470,"wires":[]}]

```

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

---

<div class="post-metadata">

**Author:** ![Stefan8485](https://avatars.discourse-cdn.com/v4/letter/s/838e76/32.png) [@Stefan8485](https://discourse.nodered.org/u/Stefan8485)\
**Post date:** [9 February 2024 08:18 UTC](https://discourse.nodered.org/t/change-payload-value-in-text/85347/3 "2024-02-09T08:18:41Z")

</div>

I'll try again. In the said payload, the open state 0 closed and 1 open of a door sensor is delivered. But I want to convert the value 0 or 1 into a string and then send it as a message  
0 should be changed to "door closed"  
1 should be changed to “Door opened”

I hope the description is now clearer?

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [9 February 2024 08:23 UTC](https://discourse.nodered.org/t/change-payload-value-in-text/85347/4 "2024-02-09T08:23:27Z")

</div>

This will look for "0" and replace with "door closed"

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

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [9 February 2024 08:31 UTC](https://discourse.nodered.org/t/change-payload-value-in-text/85347/5 "2024-02-09T08:31:20Z")

</div>

```auto
[{"id":"8a510de3a49fa2b4","type":"inject","z":"53edcbb0228e136a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"str","x":510,"y":3640,"wires":[["a2bdf0700c85f27a"]]},{"id":"a2bdf0700c85f27a","type":"switch","z":"53edcbb0228e136a","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":650,"y":3660,"wires":[["30f5ea8ca1724766"],["519a67a4268810d1"]]},{"id":"63eed357b8ebfdc5","type":"inject","z":"53edcbb0228e136a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"str","x":510,"y":3690,"wires":[["a2bdf0700c85f27a"]]},{"id":"30f5ea8ca1724766","type":"change","z":"53edcbb0228e136a","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"The Door is Closed","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":3630,"wires":[["5cb68d24453f2a05"]]},{"id":"519a67a4268810d1","type":"change","z":"53edcbb0228e136a","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"The Door is Open","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":3680,"wires":[["5cb68d24453f2a05"]]},{"id":"5cb68d24453f2a05","type":"debug","z":"53edcbb0228e136a","name":"debug 2509","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1070,"y":3660,"wires":[]}]

```

![0and1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/1/11abb29fdb235147de3703064643ef90a582df4b.gif)

assuming the payload is equal to 0 or 1

If it contains 0 and 1 , then @cymplecy solution should work.

---

<div class="post-metadata">

**Author:** ![Stefan8485](https://avatars.discourse-cdn.com/v4/letter/s/838e76/32.png) [@Stefan8485](https://discourse.nodered.org/u/Stefan8485)\
**Post date:** [9 February 2024 08:33 UTC](https://discourse.nodered.org/t/change-payload-value-in-text/85347/6 "2024-02-09T08:33:13Z")

</div>

unfortunately this doesn't work:  
v3/doorsens@ttn/devices/chicken-out/up : msg.payload : number 1  
is the payload result.  
and if I change that to open door

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

it will still be passed as 1

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

---

<div class="post-metadata">

**Author:** ![Stefan8485](https://avatars.discourse-cdn.com/v4/letter/s/838e76/32.png) [@Stefan8485](https://discourse.nodered.org/u/Stefan8485)\
**Post date:** [9 February 2024 08:40 UTC](https://discourse.nodered.org/t/change-payload-value-in-text/85347/7 "2024-02-09T08:40:07Z")

</div>

> [@smanjunath211](#):
>
> `[{"id":"8a510de3a49fa2b4","type":"inject","z":"53edcbb0228e136a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"str","x":510,"y":3640,"wires":[["a2bdf0700c85f27a"]]},{"id":"a2bdf0700c85f27a","type":"switch","z":"53edcbb0228e136a","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":650,"y":3660,"wires":[["30f5ea8ca1724766"],["519a67a4268810d1"]]},{"id":"63eed357b8ebfdc5","type":"inject","z":"53edcbb0228e136a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"str","x":510,"y":3690,"wires":[["a2bdf0700c85f27a"]]},{"id":"30f5ea8ca1724766","type":"change","z":"53edcbb0228e136a","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"The Door is Closed","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":3630,"wires":[["5cb68d24453f2a05"]]},{"id":"519a67a4268810d1","type":"change","z":"53edcbb0228e136a","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"The Door is Open","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":3680,"wires":[["5cb68d24453f2a05"]]},{"id":"5cb68d24453f2a05","type":"debug","z":"53edcbb0228e136a","name":"debug 2509","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1070,"y":3660,"wires":[]}]`

thanks i will check with a switch befor

---

<div class="post-metadata">

**Author:** ![Stefan8485](https://avatars.discourse-cdn.com/v4/letter/s/838e76/32.png) [@Stefan8485](https://discourse.nodered.org/u/Stefan8485)\
**Post date:** [9 February 2024 08:47 UTC](https://discourse.nodered.org/t/change-payload-value-in-text/85347/8 "2024-02-09T08:47:39Z")

</div>

perfect, it works, thank you.

I had two mistakes.  
The payload was queried once not as a payload but again as a payload status.  
and then didn't use the switch.  
Both combinations work together and the text is transmitted.

Many thanks

---

<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:** [9 May 2024 08:48 UTC](https://discourse.nodered.org/t/change-payload-value-in-text/85347/9 "2024-05-09T08:48:30Z")

</div>

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