# Node-RED Function for MQTT --\> Influxdb

**URL:** <https://discourse.nodered.org/t/node-red-function-for-mqtt-influxdb/79191>\
**Category:** General\
**Tags:** database, function-node, mqtt\
**Created:** [14 June 2023 08:54 UTC](https://discourse.nodered.org/t/node-red-function-for-mqtt-influxdb/79191 "2023-06-14T08:54:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xienter](https://avatars.discourse-cdn.com/v4/letter/x/db5fbb/32.png) [@Xienter](https://discourse.nodered.org/u/Xienter)\
**Post date:** [14 June 2023 08:54 UTC](https://discourse.nodered.org/t/node-red-function-for-mqtt-influxdb/79191/1 "2023-06-14T08:54:02Z")

</div>

Hi all,

I have setup my MQTT and Influxdb connection already and it is working quite good for a while now.  
Now i want to add some let's call it "advanced functionallity". So a little backround information: I have multiple sensors (temperature, humidity etc.) in my home installed and all are sending their values in the data base, but every sensor is sendy by change so i have different time stamps for each single sensor/value. Is it possible with a node-RED function to get all sensor values from one type e.g. all temperatures and store them into an array and if one value changes the complete array of values will get pushed into the database? So e.g. 15 sensors are connected with this node and one value changes than all 14 values (previous values) would be send again and the new one value will be sended with the updated value?

I'm thankfull for every hint to get it working 🙂

BR Xienter

---

<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:** [14 June 2023 09:47 UTC](https://discourse.nodered.org/t/node-red-function-for-mqtt-influxdb/79191/2 "2023-06-14T09:47:50Z")

</div>

It should be possible using a join node to combine all of your temperature readings into an array and send the array to your database when any single new reading arrives. That's not quite the same as when any value changes.  
Probably adding in a filter node would prevent duplicates but I've not tried it with an array.

However, it's bad database design to store compound values and duplicates.  
It must be possible to extract the data you want with the dB query.  
I discarded Influx though because it's understanding of SQL differs from mine.

---

<div class="post-metadata">

**Author:** ![rrabbit454](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rrabbit454/32/74694_2.png) [@rrabbit454](https://discourse.nodered.org/u/rrabbit454)\
**Post date:** [17 July 2023 00:58 UTC](https://discourse.nodered.org/t/node-red-function-for-mqtt-influxdb/79191/3 "2023-07-17T00:58:35Z")

</div>

I will say use join node with message resend node:

> **[node-red-contrib-msg-resend](https://flows.nodered.org/node/node-red-contrib-msg-resend)**
>
> A Node Red node to resend flow messages

---

<div class="post-metadata">

**Author:** ![xx\_Nexus\_xx](https://avatars.discourse-cdn.com/v4/letter/x/54ee81/32.png) [@xx\_Nexus\_xx](https://discourse.nodered.org/u/xx_Nexus_xx)\
**Post date:** [17 July 2023 01:49 UTC](https://discourse.nodered.org/t/node-red-function-for-mqtt-influxdb/79191/4 "2023-07-17T01:49:39Z")

</div>

1. create local or global array for all your temperatures (I use local flow variable)
2. write the new sensor temperature into the array
3. write the entire temperature array into influxdb

---

<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:** [17 July 2023 07:35 UTC](https://discourse.nodered.org/t/node-red-function-for-mqtt-influxdb/79191/5 "2023-07-17T07:35:12Z")

</div>

> [@Xienter](#):
>
> so i have different time stamps for each single sensor/value

Why is that a problem? That is the efficient way to store the data.

---

<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:** [15 September 2023 07:36 UTC](https://discourse.nodered.org/t/node-red-function-for-mqtt-influxdb/79191/6 "2023-09-15T07:36:02Z")

</div>

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