# How to send a temperature data that is more than 30 celcius and save it in excel csv file

**URL:** <https://discourse.nodered.org/t/how-to-send-a-temperature-data-that-is-more-than-30-celcius-and-save-it-in-excel-csv-file/60749>\
**Category:** General\
**Tags:** database, function-node\
**Created:** [4 April 2022 04:22 UTC](https://discourse.nodered.org/t/how-to-send-a-temperature-data-that-is-more-than-30-celcius-and-save-it-in-excel-csv-file/60749 "2022-04-04T04:22:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Goldenguyz](https://avatars.discourse-cdn.com/v4/letter/g/3e96dc/32.png) [@Goldenguyz](https://discourse.nodered.org/u/Goldenguyz)\
**Post date:** [4 April 2022 04:22 UTC](https://discourse.nodered.org/t/how-to-send-a-temperature-data-that-is-more-than-30-celcius-and-save-it-in-excel-csv-file/60749/1 "2022-04-04T04:22:17Z")

</div>

Hi all, I'm trying to send some specific data of temperature in celcius that received an inputs from COMPORT3 which I connect with raspberry pi pico and when the temperature is above 30, it will Line notify to me.

Here is the node I created:

 ![node](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/1/4149f4dc62d93dd7a80856348fedbe46ec31adb9.png)

And in the function I use this code:  
 ![code function](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/a/4affb3947868760f10e0042314b62f6e6caba642.png)

So in my case, all data that it receive from the sensor raspberry pi pico, every data has saved in csv, but what I want is that for every temperature that is above 30, it willl be save in csv, and for temperature which is less than 30, it will not save in csv, so any idea on how should I fix the code in the function?

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [4 April 2022 06:05 UTC](https://discourse.nodered.org/t/how-to-send-a-temperature-data-that-is-more-than-30-celcius-and-save-it-in-excel-csv-file/60749/2 "2022-04-04T06:05:57Z")

</div>

First post the request, then there (hopefully) will be a temperature as a result, then test if it is \> 30, then write it.  
Note that the `temperature > '30'` is testing for a string not a number. If the result from the request is a string, first convert it to a number.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [4 April 2022 07:42 UTC](https://discourse.nodered.org/t/how-to-send-a-temperature-data-that-is-more-than-30-celcius-and-save-it-in-excel-csv-file/60749/3 "2022-04-04T07:42:50Z")

</div>

You need to filter the temps using a switch node, also best to create a boolean for this. You can then direct every temp over 30 to the cvs. The message would only be sent when temp raises above 30, until it drops below, then a message telling you it's below once, until it raises again  
e.g.

```auto
[{"id":"2318c14a.40be8e","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"5","payloadType":"num","x":70,"y":2100,"wires":[["7ca626ff.2e90b8"]]},{"id":"7ca626ff.2e90b8","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"pass_change","pt":"msg","to":"$$.payload > 30 ? true : false","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":2160,"wires":[["bfa66ba369fb31a2"]]},{"id":"a7306afd.cf622","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"35","payloadType":"num","x":70,"y":2180,"wires":[["7ca626ff.2e90b8"]]},{"id":"eda5a105.767418","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","x":70,"y":2140,"wires":[["7ca626ff.2e90b8"]]},{"id":"8f12cc3e.7de6f8","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"40","payloadType":"num","x":70,"y":2220,"wires":[["7ca626ff.2e90b8"]]},{"id":"bfa66ba369fb31a2","type":"switch","z":"bf9e1e33.030598","name":"","property":"pass_change","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":480,"y":2160,"wires":[["034205c1528902a8","3af70233.3a3b6e"],["3af70233.3a3b6e"]]},{"id":"034205c1528902a8","type":"debug","z":"bf9e1e33.030598","name":"csv","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":2160,"wires":[]},{"id":"3af70233.3a3b6e","type":"rbe","z":"bf9e1e33.030598","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"pass_change","x":230,"y":2260,"wires":[["2788d766.3f2aa8"]]},{"id":"2788d766.3f2aa8","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.message","tot":"msg"},{"t":"set","p":"url","pt":"msg","to":"http://websit.com","tot":"str"},{"t":"set","p":"headers","pt":"msg","to":"{\"content-type\":\"application/x-www-form-urlencoded\",\"Authorization\":\"[scheme] [auth token]\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":2260,"wires":[["92640cf9.6f2a4"]]},{"id":"92640cf9.6f2a4","type":"debug","z":"bf9e1e33.030598","name":"http","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":570,"y":2260,"wires":[]}]

```

[edit] Or if incoming payload is a string

```auto
[{"id":"2318c14a.40be8e","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"5","payloadType":"str","x":70,"y":2100,"wires":[["7ca626ff.2e90b8"]]},{"id":"7ca626ff.2e90b8","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"pass_change","pt":"msg","to":"$number($$.payload) > 30 ? true : false","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":2160,"wires":[["bfa66ba369fb31a2"]]},{"id":"a7306afd.cf622","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"35","payloadType":"str","x":70,"y":2180,"wires":[["7ca626ff.2e90b8"]]},{"id":"eda5a105.767418","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"str","x":70,"y":2140,"wires":[["7ca626ff.2e90b8"]]},{"id":"8f12cc3e.7de6f8","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"40","payloadType":"str","x":70,"y":2220,"wires":[["7ca626ff.2e90b8"]]},{"id":"bfa66ba369fb31a2","type":"switch","z":"bf9e1e33.030598","name":"","property":"pass_change","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":480,"y":2160,"wires":[["034205c1528902a8","3af70233.3a3b6e"],["3af70233.3a3b6e"]]},{"id":"034205c1528902a8","type":"debug","z":"bf9e1e33.030598","name":"csv","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":2160,"wires":[]},{"id":"3af70233.3a3b6e","type":"rbe","z":"bf9e1e33.030598","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"pass_change","x":230,"y":2260,"wires":[["2788d766.3f2aa8"]]},{"id":"2788d766.3f2aa8","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.message","tot":"msg"},{"t":"set","p":"url","pt":"msg","to":"http://websit.com","tot":"str"},{"t":"set","p":"headers","pt":"msg","to":"{\"content-type\":\"application/x-www-form-urlencoded\",\"Authorization\":\"[scheme] [auth token]\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":2260,"wires":[["92640cf9.6f2a4"]]},{"id":"92640cf9.6f2a4","type":"debug","z":"bf9e1e33.030598","name":"http","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":570,"y":2260,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Goldenguyz](https://avatars.discourse-cdn.com/v4/letter/g/3e96dc/32.png) [@Goldenguyz](https://discourse.nodered.org/u/Goldenguyz)\
**Post date:** [4 April 2022 08:31 UTC](https://discourse.nodered.org/t/how-to-send-a-temperature-data-that-is-more-than-30-celcius-and-save-it-in-excel-csv-file/60749/4 "2022-04-04T08:31:13Z")

</div>

I believe that the data that have received from the sensor is a string, but how do I convert that input {string} into a number in the function node-red? And is there like a command when the data is more than 30 celcius then it will write down in the csv?

---

<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:** [4 April 2022 09:32 UTC](https://discourse.nodered.org/t/how-to-send-a-temperature-data-that-is-more-than-30-celcius-and-save-it-in-excel-csv-file/60749/5 "2022-04-04T09:32:10Z")

</div>

> [@Goldenguyz](#):
>
> I believe that the data that have received from the sensor is a string

In a function node, use `parseInt`, `parseFloat` or `Number()` to convert string to number.

> [@Goldenguyz](#):
>
> And is there like a command when the data is more than 30 celcius then it will write down in the csv?

No there is no such "command". There are **nodes** that you can wire together to achieve this.

1. a `switch` node can determine if a value is \> 30
2. a file node can write the value to a CSV file.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [4 April 2022 09:50 UTC](https://discourse.nodered.org/t/how-to-send-a-temperature-data-that-is-more-than-30-celcius-and-save-it-in-excel-csv-file/60749/6 "2022-04-04T09:50:19Z")

</div>

Here is a little flow which

- Injects as strings "25", "30" or "35.97".
- Converts the text to a number.
- Checks if the value \>= 30 and if it is,
- Displays the value.

 ![Untitled 2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bdeb81c9e949b57c003482fabdf81dc3c366bb56.jpeg)

```auto
[{"id":"0d424c52e680beb0","type":"inject","z":"3942cc17cf38667e","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"25","payloadType":"str","x":210,"y":140,"wires":[["4a4217991302609d"]]},{"id":"c690aabd2a170679","type":"inject","z":"3942cc17cf38667e","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"30","payloadType":"str","x":210,"y":180,"wires":[["4a4217991302609d"]]},{"id":"d3d5ba1fb194f6fc","type":"inject","z":"3942cc17cf38667e","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"35.97","payloadType":"str","x":210,"y":220,"wires":[["4a4217991302609d"]]},{"id":"4a4217991302609d","type":"change","z":"3942cc17cf38667e","name":"Convert to number","rules":[{"t":"set","p":"payload","pt":"msg","to":"$number(payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":180,"wires":[["5441eea04688397c"]]},{"id":"5441eea04688397c","type":"switch","z":"3942cc17cf38667e","name":">= 30?","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"30","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":580,"y":180,"wires":[["595773fc8a966bc0"]]},{"id":"595773fc8a966bc0","type":"debug","z":"3942cc17cf38667e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":180,"wires":[]}]

```

ps I suspect that the problem with your function is that it passes on the message regardless of the temperature.

---

<div class="post-metadata">

**Author:** ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)\
**Post date:** [4 April 2022 09:50 UTC](https://discourse.nodered.org/t/how-to-send-a-temperature-data-that-is-more-than-30-celcius-and-save-it-in-excel-csv-file/60749/7 "2022-04-04T09:50:28Z")

</div>

Cross posted and answered on Stack Overflow here:  
[https://stackoverflow.com/questions/71734215/how-to-allow-node-red-to-send-only-data-temperature-that-is-more-than-30-degre/71735054#71735054](https://stackoverflow.com/questions/71734215/how-to-allow-node-red-to-send-only-data-temperature-that-is-more-than-30-degre/71735054#71735054)

P.s. You really need to change that AccessToken now you've published it to the world in multiple places on the internet.

---

<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:** [3 June 2022 09:50 UTC](https://discourse.nodered.org/t/how-to-send-a-temperature-data-that-is-more-than-30-celcius-and-save-it-in-excel-csv-file/60749/8 "2022-06-03T09:50:36Z")

</div>

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