# Sensors to function. function to switch

**URL:** <https://discourse.nodered.org/t/sensors-to-function-function-to-switch/13351>\
**Category:** General\
**Created:** [16 July 2019 11:20 UTC](https://discourse.nodered.org/t/sensors-to-function-function-to-switch/13351 "2019-07-16T11:20:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![alijahangir](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@alijahangir](https://discourse.nodered.org/u/alijahangir)\
**Post date:** [16 July 2019 11:20 UTC](https://discourse.nodered.org/t/sensors-to-function-function-to-switch/13351/1 "2019-07-16T11:20:49Z")

</div>

i m retrieving temperature value from dht22 to a function node in msg.payload. how to turn something On or Off based on temperature value? help would be much appriciated.

---

<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:** [16 July 2019 11:29 UTC](https://discourse.nodered.org/t/sensors-to-function-function-to-switch/13351/2 "2019-07-16T11:29:11Z")

</div>

Use a debug node to understand your data, this page in the docs is a key doc to read [https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

Then investigate the `switch` node to separate messages.

How to turn something on /off well that will depend on what the something is, but I'm sure looking at [flows.nodered.org](http://flows.nodered.org) the [cookbook.nodered.org](http://cookbook.nodered.org) and [http://noderedguide.com](http://noderedguide.com) you should be able to get started.

PS, this should really be asked in #general as you aren't developing the Node-RED code...

---

<div class="post-metadata">

**Author:** ![alijahangir](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@alijahangir](https://discourse.nodered.org/u/alijahangir)\
**Post date:** [16 July 2019 11:46 UTC](https://discourse.nodered.org/t/sensors-to-function-function-to-switch/13351/3 "2019-07-16T11:46:46Z")

</div>

temperature value is in payload when attached debug node. something connected to raspberry gpio pin. what should be the code in function node. i tried if else but it wont return Boolean.

---

<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:** [16 July 2019 11:50 UTC](https://discourse.nodered.org/t/sensors-to-function-function-to-switch/13351/4 "2019-07-16T11:50:21Z")

</div>

You don't need a function node.

If your data is msg.payload you could use a switch to only allow through the values you want and then a change node.

Alternatively post your code and what the data see in the debug...

---

<div class="post-metadata">

**Author:** ![alijahangir](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@alijahangir](https://discourse.nodered.org/u/alijahangir)\
**Post date:** [16 July 2019 12:05 UTC](https://discourse.nodered.org/t/sensors-to-function-function-to-switch/13351/5 "2019-07-16T12:05:40Z")

</div>

![2019-07-16-123637_1280x1024_scrot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/4baecb242541d48311bf0ba6189310bdfc21aa39.png)

thats what i have done so far. in function node its just msg.payload=msg.payload; return msg;

debug shows: 16/07/2019, 13:04:20[node: ff5af76a.59b928](http://127.0.0.1:1880/#)rpi-dht22 : msg.payload : string[5]

"30.10"

16/07/2019, 13:04:20[node: 4c3eb789.797c58](http://127.0.0.1:1880/#)rpi-dht22 : msg.payload : string[5]

"78.90"

---

<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:** [16 July 2019 12:19 UTC](https://discourse.nodered.org/t/sensors-to-function-function-to-switch/13351/6 "2019-07-16T12:19:56Z")

</div>

So you didn't post the contents of your function node which does make it more difficult

But I'm guessing it's because you're msg.payload is a string not a number.  
Try searching this internet for "javascript convert string to number" or you could use a switch node...
