# Function to write Netatmo measurement in Influx DB

**URL:** <https://discourse.nodered.org/t/function-to-write-netatmo-measurement-in-influx-db/13265>\
**Category:** General\
**Created:** [14 July 2019 13:58 UTC](https://discourse.nodered.org/t/function-to-write-netatmo-measurement-in-influx-db/13265 "2019-07-14T13:58:49Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![HaVi](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@HaVi](https://discourse.nodered.org/u/HaVi)\
**Post date:** [14 July 2019 13:58 UTC](https://discourse.nodered.org/t/function-to-write-netatmo-measurement-in-influx-db/13265/1 "2019-07-14T13:58:49Z")

</div>

Hi,

The Netatmo "Get Measurements" node reads the days minimum termperature from my Netatmo outdoor module and when I fill in

msg.payload.devices[0].modules[2].dashboard\_data.min\_temp

in the debugger the correct measurement (degrees minimum temperature value like 15.3) is shown in the debug frame. Now I intend to save this value in an Influx DB and I suppose I need a function before saving the value in the database. After reading many instructions I did not succeed, can someone help me writing this function?

Regards, Hans.

---

<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:** [14 July 2019 14:36 UTC](https://discourse.nodered.org/t/function-to-write-netatmo-measurement-in-influx-db/13265/2 "2019-07-14T14:36:02Z")

</div>

You can use a change node to setup the message for influx.

---

<div class="post-metadata">

**Author:** ![HaVi](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@HaVi](https://discourse.nodered.org/u/HaVi)\
**Post date:** [14 July 2019 14:53 UTC](https://discourse.nodered.org/t/function-to-write-netatmo-measurement-in-influx-db/13265/3 "2019-07-14T14:53:20Z")

</div>

Thanks Colin, just tried the Change node but no succes. Not even after reading the node help, can you be more specific how to use it in my flow?

---

<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:** [14 July 2019 19:10 UTC](https://discourse.nodered.org/t/function-to-write-netatmo-measurement-in-influx-db/13265/4 "2019-07-14T19:10:59Z")

</div>

Post what you see in a debug node before the change node and another after and show us the change node config. Tell us what you want to see on the output.

---

<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:** [14 July 2019 19:13 UTC](https://discourse.nodered.org/t/function-to-write-netatmo-measurement-in-influx-db/13265/5 "2019-07-14T19:13:09Z")

</div>

Also check that you have configured the influxdb node with the correct details of your database.

---

<div class="post-metadata">

**Author:** ![HaVi](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@HaVi](https://discourse.nodered.org/u/HaVi)\
**Post date:** [15 July 2019 10:04 UTC](https://discourse.nodered.org/t/function-to-write-netatmo-measurement-in-influx-db/13265/6 "2019-07-15T10:04:45Z")

</div>

When this:

_payload.devices[0].modules[2].dashboard\_data.min\_temp_

is in my debug node then output in the debugger shows the correct min-temp:

_15-7-2019 11:50:04[node: 42184b89.07c674](http://192.168.2.160:1880/#)msg.payload.devices[0].modules[2].dashboard\_data.min\_temp : number_  
_15_

So I think I need a function or change to save the min-temp (15) in the database.

The relevant part from the complete message object coming from the Netatmo "get stations data" node is shown in the graphic below.

 ![NR](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/d044067329da96bfb7d946cf8dde795220de731a.png)

---

<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:** [15 July 2019 10:14 UTC](https://discourse.nodered.org/t/function-to-write-netatmo-measurement-in-influx-db/13265/7 "2019-07-15T10:14:47Z")

</div>

I am using an influxdb-batch node (with telegraf) and send all netatmo data to it like this:

```auto
m = msg.payload.devices[0].dashboard_data

msg.payload = [
    {
        measurement:"netatmo",
        fields: m,
        tags:{
            weather:"internal"
        },
        timestamp: new Date()
    }];

return msg

```

---

<div class="post-metadata">

**Author:** ![HaVi](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@HaVi](https://discourse.nodered.org/u/HaVi)\
**Post date:** [15 July 2019 11:09 UTC](https://discourse.nodered.org/t/function-to-write-netatmo-measurement-in-influx-db/13265/8 "2019-07-15T11:09:01Z")

</div>

Thanks Bakman2, works like a charm and the data is saved in the DB. Now struggling how to save only the min\_temp from the outdoor module, any help would be appreciated.

---

<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:** [15 July 2019 11:17 UTC](https://discourse.nodered.org/t/function-to-write-netatmo-measurement-in-influx-db/13265/9 "2019-07-15T11:17:02Z")

</div>

But if you have it in the database, it is already saved no ?

---

<div class="post-metadata">

**Author:** ![HaVi](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@HaVi](https://discourse.nodered.org/u/HaVi)\
**Post date:** [15 July 2019 11:23 UTC](https://discourse.nodered.org/t/function-to-write-netatmo-measurement-in-influx-db/13265/10 "2019-07-15T11:23:35Z")

</div>

The indoor module data is saved, not the outdoor module data. I think msg.payload.devices[0].dashboard\_data refers to the indoor module.

 ![influx](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/9e3c6f083050314f12f3ccb23e93957b22c39df7.jpeg)

---

<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:** [15 July 2019 11:25 UTC](https://discourse.nodered.org/t/function-to-write-netatmo-measurement-in-influx-db/13265/11 "2019-07-15T11:25:50Z")

</div>

Sorry, you can use:

```auto
m = msg.payload.devices[0].modules[0].dashboard_data

```

and for min-temp only:

```auto
m = msg.payload.devices[0].modules[0].dashboard_data.min_temp

```

---

<div class="post-metadata">

**Author:** ![HaVi](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@HaVi](https://discourse.nodered.org/u/HaVi)\
**Post date:** [15 July 2019 12:52 UTC](https://discourse.nodered.org/t/function-to-write-netatmo-measurement-in-influx-db/13265/12 "2019-07-15T12:52:45Z")

</div>

Thanks again for helping! Although the line _m = msg.payload.devices[0].modules[0].dashboard\_data_ writes to the DB but unfortunattely only the values for _Rain, sum\_rain\_1, sum\_rain\_24 and time\_utc_

And the line _m = msg.payload.devices[0].modules[0].dashboard\_data.min\_temp_ generates an error:

_Error: A 400 Bad Request error occurred: {"error":"unable to parse 'tuin': missing fields"}_

---

<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:** [15 July 2019 13:32 UTC](https://discourse.nodered.org/t/function-to-write-netatmo-measurement-in-influx-db/13265/13 "2019-07-15T13:32:09Z")

</div>

You have multiple modules.

Connect the netatmo node to a debug node and determine in which module the min\_temp is located.

---

<div class="post-metadata">

**Author:** ![HaVi](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@HaVi](https://discourse.nodered.org/u/HaVi)\
**Post date:** [15 July 2019 14:18 UTC](https://discourse.nodered.org/t/function-to-write-netatmo-measurement-in-influx-db/13265/14 "2019-07-15T14:18:46Z")

</div>

Solved, thanks for helping!

---

<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:** [15 July 2019 14:47 UTC](https://discourse.nodered.org/t/function-to-write-netatmo-measurement-in-influx-db/13265/15 "2019-07-15T14:47:45Z")

</div>

> [@bakman2](#):
>
> timestamp: new Date()

Just wondered why you were adding a timestamp. I thought Influx added it automatically anyway....

---

<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:** [15 July 2019 15:44 UTC](https://discourse.nodered.org/t/function-to-write-netatmo-measurement-in-influx-db/13265/16 "2019-07-15T15:44:31Z")

</div>

You are correct, it is a historical leftover, good moment to clean it up!
