# Converting payload output

**URL:** https://discourse.nodered.org/t/converting-payload-output/11215
**Category:** General
**Created:** [16 May 2019 14:46 UTC](https://discourse.nodered.org/t/converting-payload-output/11215 "2019-05-16T14:46:48Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Bert](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bert/32/14828_2.png) [@Bert](https://discourse.nodered.org/u/Bert)
#### Post date: [16 May 2019 14:46 UTC](https://discourse.nodered.org/t/converting-payload-output/11215/1 "2019-05-16T14:46:48Z")

</div>

Hi all,  
This is my first question on this forum. Please keep in mind that i am not a programmer...

I am using node-RED next to my openHAB home automation system instead of the rule engine of openHAB. For scheduler stuff i the use BigTimer node from Peter Scargill which is marvelous!

But i run into a problem with the output of the BigTimer node.  
When i switch my Philips Hue light simply with two input nodes, it switches on/off with the input nodes set to true/false respectively.  
But the output of the BigTime gives me "true" and "false" in stead of true and false in the debug node. The Hue Light does not accept this, so i think i need to convert "true" to true. Probably i need a function node for this. But i do not know how to configure this properly.

Could somebody please help me with this?  
Kind regards, Bert

```auto
[{"id":"f2f60fe6.23aad","type":"inject","z":"a84bf6a1.ed57b8","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":280,"wires":[["f21f3a3c.e804a8","f258f7e5.712be8"]]},{"id":"f21f3a3c.e804a8","type":"hue-light","z":"a84bf6a1.ed57b8","name":"Hue color lamp 1","bridge":"f526bb6c.340c08","lightid":"1","colornamer":true,"x":330,"y":200,"wires":[[]]},{"id":"f258f7e5.712be8","type":"debug","z":"a84bf6a1.ed57b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":310,"y":280,"wires":[]},{"id":"84e4b109.c214e","type":"function","z":"a84bf6a1.ed57b8","name":"Return status","func":"return { payload: msg.payload.on };","outputs":1,"noerr":0,"x":670,"y":80,"wires":[["d4f918eb.ef26a8"]]},{"id":"97f4b1c2.f9a3f","type":"inject","z":"a84bf6a1.ed57b8","name":"","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":320,"wires":[["f21f3a3c.e804a8","1e7c6d97.2f59a2"]]},{"id":"36eff64c.c90e5a","type":"inject","z":"a84bf6a1.ed57b8","name":"","topic":"","payload":"AUTO","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":360,"wires":[["f21f3a3c.e804a8"]]},{"id":"d4f918eb.ef26a8","type":"ui_switch","z":"a84bf6a1.ed57b8","name":"","label":"Staande schemerlamp","tooltip":"","group":"e631aff1.17e18","order":0,"width":0,"height":0,"passthru":false,"decouple":"true","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":160,"y":80,"wires":[[]]},{"id":"39c96ca7.504144","type":"inject","z":"a84bf6a1.ed57b8","name":"","topic":"","payload":"AUTO","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":520,"wires":[["bcb985c5.7b2878"]]},{"id":"bcb985c5.7b2878","type":"bigtimer","z":"a84bf6a1.ed57b8","outtopic":"mytimer1","outpayload1":"true","outpayload2":"false","name":"1 - Elke dag Sunset+45 --- 23:30+","comment":"","lat":"51.955","lon":"5.22778","starttime":"5004","endtime":"1410","startoff":"45","endoff":"0","startoff2":"","endoff2":"","offs":0,"outtext1":"Staande Lamp Aan","outtext2":"Staande Lamp Uit","timeout":1440,"sun":true,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"jan":true,"feb":true,"mar":true,"apr":true,"may":true,"jun":true,"jul":true,"aug":true,"sep":true,"oct":true,"nov":true,"dec":true,"day1":0,"month1":0,"day2":0,"month2":0,"day3":0,"month3":0,"day4":0,"month4":0,"day5":0,"month5":0,"day6":"","month6":"","d1":0,"w1":0,"d2":0,"w2":0,"d3":0,"w3":0,"d4":0,"w4":0,"d5":0,"w5":0,"d6":"","w6":"","xday1":"","xmonth1":"","xday2":"","xmonth2":"","xday3":"","xmonth3":"","xday4":"","xmonth4":"","xday5":"","xmonth5":"","xday6":"","xmonth6":"","xd1":"","xw1":"","xd2":"","xw2":"","xd3":"","xw3":"","xd4":"","xw4":"","xd5":"","xw5":"","xd6":"","xw6":"","suspend":false,"random":true,"repeat":false,"atstart":true,"odd":false,"even":false,"x":400,"y":480,"wires":[["2e47657e.d403da","bac75528.08b5d8"],[],[]]},{"id":"96279227.184c1","type":"inject","z":"a84bf6a1.ed57b8","name":"","topic":"","payload":"ON","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":440,"wires":[["bcb985c5.7b2878"]]},{"id":"7619a5c.f7d005c","type":"inject","z":"a84bf6a1.ed57b8","name":"","topic":"","payload":"OFF","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":480,"wires":[["bcb985c5.7b2878"]]},{"id":"2e47657e.d403da","type":"function","z":"a84bf6a1.ed57b8","name":"","func":"if (msg.payload === \"true\" ) { msg.payload = true; }\nelse { msg.payload = '/n'; }\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":660,"wires":[["a95d067c.119b88"]]},{"id":"bac75528.08b5d8","type":"debug","z":"a84bf6a1.ed57b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":730,"y":480,"wires":[]},{"id":"a95d067c.119b88","type":"debug","z":"a84bf6a1.ed57b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":791.0115356445312,"y":660.138916015625,"wires":[]},{"id":"1e7c6d97.2f59a2","type":"debug","z":"a84bf6a1.ed57b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":310,"y":320,"wires":[]},{"id":"f526bb6c.340c08","type":"hue-bridge","z":"","name":"Philips hue","bridge":"192.168.178.233","key":"HEroXcdUipJWSKR46BGNnXfnUsM0KhSPavce5Y-Y","interval":"3000"},{"id":"e631aff1.17e18","type":"ui_group","z":"","name":"4 Woning Bg","tab":"d63e865e.716478","disp":true,"width":"6","collapse":false},{"id":"d63e865e.716478","type":"ui_tab","z":"","name":"4 Woning Bg","icon":"dashboard","order":4,"disabled":false,"hidden":false}]

```

EDIT.  
I found a solution for my issue, using a Function node with a conversion from String to Boolean:  
if(msg.payload === "true"){  
msg.payload = true;  
}  
if(msg.payload === "false"){  
msg.payload = false;  
}  
return msg;

Perhaps there are other ways of solving this, but for now i'l stick to this.  
Grtz, Bert

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [16 May 2019 21:16 UTC](https://discourse.nodered.org/t/converting-payload-output/11215/2 "2019-05-16T21:16:20Z")

</div>

It will work fine. Slight suggestion...

```auto
msg.payload = msg.payload == "true";
return msg;

```

This will catch instances where payload is neither "true" nor "false" and default it to `false`

---

<div class="post-metadata">

### Author: ![DiegoTelles](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/diegotelles/32/5236_2.png) [@DiegoTelles](https://discourse.nodered.org/u/DiegoTelles)
#### Post date: [16 May 2019 23:32 UTC](https://discourse.nodered.org/t/converting-payload-output/11215/3 "2019-05-16T23:32:31Z")

</div>

You can use the node change for validate this response or an function node with if()
