# How to save multiple objects to Influx?

**URL:** <https://discourse.nodered.org/t/how-to-save-multiple-objects-to-influx/73659>\
**Category:** General\
**Created:** [14 January 2023 10:26 UTC](https://discourse.nodered.org/t/how-to-save-multiple-objects-to-influx/73659 "2023-01-14T10:26:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![DublinBayPrawn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dublinbayprawn/32/74333_2.png) [@DublinBayPrawn](https://discourse.nodered.org/u/DublinBayPrawn)\
**Post date:** [14 January 2023 10:26 UTC](https://discourse.nodered.org/t/how-to-save-multiple-objects-to-influx/73659/1 "2023-01-14T10:26:12Z")

</div>

I am trying to send multiple items of sensor data, from multiple rooms, to InfluxDB. Trying to do this in a tidy, logical way, I attempted to create a "bucket" of rooms, and within each room, a "bucket" of sensor's data.  
ie

 ![Flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/5/95927b8441761fd3cd20dcdf9d4cdc42bd92b4f2.png)

The debug shows the result

 ![Debug](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/a/da2ecf5c26f97d7bfe9d0db18a12c8c22f84a65c.png)

```auto
[
    {
        "id": "a241d72b79d8b1b7",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "3d23ccf9e7a89445",
        "type": "poll-state",
        "z": "a241d72b79d8b1b7",
        "name": "sensor.wiser_lts_temperature_lounge",
        "server": "3cade157397fc070",
        "version": 2,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "updateinterval": "60",
        "updateIntervalType": "num",
        "updateIntervalUnits": "seconds",
        "outputinitially": true,
        "outputonchanged": false,
        "entity_id": "sensor.wiser_lts_temperature_lounge",
        "state_type": "num",
        "halt_if": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "x": 270,
        "y": 180,
        "wires": [
            [
                "d44ca4c463fcb953"
            ]
        ]
    },
    {
        "id": "50298066e0c76c73",
        "type": "poll-state",
        "z": "a241d72b79d8b1b7",
        "name": "sensor.wiser_lts_heating_demand_lounge",
        "server": "3cade157397fc070",
        "version": 2,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "updateinterval": "60",
        "updateIntervalType": "num",
        "updateIntervalUnits": "seconds",
        "outputinitially": true,
        "outputonchanged": false,
        "entity_id": "sensor.wiser_lts_heating_demand_lounge",
        "state_type": "num",
        "halt_if": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "x": 280,
        "y": 220,
        "wires": [
            [
                "073920eea5a7aa87"
            ]
        ]
    },
    {
        "id": "ab0e97db45fb632c",
        "type": "poll-state",
        "z": "a241d72b79d8b1b7",
        "name": "sensor.wiser_lts_target_temperature_lounge",
        "server": "3cade157397fc070",
        "version": 2,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "updateinterval": "60",
        "updateIntervalType": "num",
        "updateIntervalUnits": "seconds",
        "outputinitially": true,
        "outputonchanged": false,
        "entity_id": "sensor.wiser_lts_target_temperature_lounge",
        "state_type": "num",
        "halt_if": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "x": 290,
        "y": 260,
        "wires": [
            [
                "90f45e0b4b22311f"
            ]
        ]
    },
    {
        "id": "32cc53d6853a8b93",
        "type": "poll-state",
        "z": "a241d72b79d8b1b7",
        "name": "sensor.wiser_lts_humidity_lounge",
        "server": "3cade157397fc070",
        "version": 2,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "updateinterval": "60",
        "updateIntervalType": "num",
        "updateIntervalUnits": "seconds",
        "outputinitially": true,
        "outputonchanged": false,
        "entity_id": "sensor.wiser_lts_humidity_lounge",
        "state_type": "num",
        "halt_if": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "x": 250,
        "y": 300,
        "wires": [
            [
                "78136dc09bdd906b"
            ]
        ]
    },
    {
        "id": "e0a942bd7c5674d4",
        "type": "join",
        "z": "a241d72b79d8b1b7",
        "name": "",
        "mode": "custom",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "4",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 750,
        "y": 240,
        "wires": [
            [
                "70718fa6484cd6db"
            ]
        ]
    },
    {
        "id": "91f9c89b347a44a1",
        "type": "debug",
        "z": "a241d72b79d8b1b7",
        "name": "debug 14",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1140,
        "y": 240,
        "wires": []
    },
    {
        "id": "70718fa6484cd6db",
        "type": "function",
        "z": "a241d72b79d8b1b7",
        "name": "Add Topic Room",
        "func": "//msg.payload = Number(msg.payload);\nmsg.topic = \"Lounge\"\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 920,
        "y": 240,
        "wires": [
            [
                "91f9c89b347a44a1",
                "5be14f9fd7f02627"
            ]
        ]
    },
    {
        "id": "dbdc5c953f6df284",
        "type": "poll-state",
        "z": "a241d72b79d8b1b7",
        "name": "sensor.wiser_lts_temperature_kitchen",
        "server": "3cade157397fc070",
        "version": 2,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "updateinterval": "60",
        "updateIntervalType": "num",
        "updateIntervalUnits": "seconds",
        "outputinitially": true,
        "outputonchanged": false,
        "entity_id": "sensor.wiser_lts_temperature_kitchen",
        "state_type": "num",
        "halt_if": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "x": 270,
        "y": 380,
        "wires": [
            [
                "c0b0a5047e59e3b8"
            ]
        ]
    },
    {
        "id": "80cc80b8050b68a1",
        "type": "poll-state",
        "z": "a241d72b79d8b1b7",
        "name": "sensor.wiser_lts_heating_demand_kitchen",
        "server": "3cade157397fc070",
        "version": 2,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "updateinterval": "60",
        "updateIntervalType": "num",
        "updateIntervalUnits": "seconds",
        "outputinitially": true,
        "outputonchanged": false,
        "entity_id": "sensor.wiser_lts_heating_demand_kitchen",
        "state_type": "num",
        "halt_if": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "x": 280,
        "y": 420,
        "wires": [
            [
                "3cc93ae90c0546f7"
            ]
        ]
    },
    {
        "id": "2540feb3a4300e9f",
        "type": "poll-state",
        "z": "a241d72b79d8b1b7",
        "name": "sensor.wiser_lts_target_temperature_kitchen",
        "server": "3cade157397fc070",
        "version": 2,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "updateinterval": "60",
        "updateIntervalType": "num",
        "updateIntervalUnits": "seconds",
        "outputinitially": true,
        "outputonchanged": false,
        "entity_id": "sensor.wiser_lts_target_temperature_kitchen",
        "state_type": "num",
        "halt_if": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "x": 290,
        "y": 460,
        "wires": [
            [
                "11fd30de50f02e56"
            ]
        ]
    },
    {
        "id": "a993a62a3973e455",
        "type": "join",
        "z": "a241d72b79d8b1b7",
        "name": "",
        "mode": "custom",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "3",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 750,
        "y": 420,
        "wires": [
            [
                "bbd24069c74caaed"
            ]
        ]
    },
    {
        "id": "fa88c017403615b0",
        "type": "debug",
        "z": "a241d72b79d8b1b7",
        "name": "debug 15",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1140,
        "y": 420,
        "wires": []
    },
    {
        "id": "bbd24069c74caaed",
        "type": "function",
        "z": "a241d72b79d8b1b7",
        "name": "Add Topic Room",
        "func": "//msg.payload = Number(msg.payload);\nmsg.topic = \"kitchen\"\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 920,
        "y": 420,
        "wires": [
            [
                "fa88c017403615b0",
                "5be14f9fd7f02627"
            ]
        ]
    },
    {
        "id": "5be14f9fd7f02627",
        "type": "join",
        "z": "a241d72b79d8b1b7",
        "name": "",
        "mode": "custom",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "2",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 1110,
        "y": 340,
        "wires": [
            [
                "d811d377a8fe043d"
            ]
        ]
    },
    {
        "id": "1c4fd26064bb7111",
        "type": "debug",
        "z": "a241d72b79d8b1b7",
        "name": "debug 16",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1500,
        "y": 320,
        "wires": []
    },
    {
        "id": "f5300633df3022af",
        "type": "influxdb out",
        "z": "a241d72b79d8b1b7",
        "influxdb": "54904c9be351d74d",
        "name": "Heating",
        "measurement": "HeatingTest",
        "precision": "",
        "retentionPolicy": "",
        "database": "home_assistant",
        "precisionV18FluxV20": "ms",
        "retentionPolicyV18Flux": "",
        "org": "organisation",
        "bucket": "bucket",
        "x": 1500,
        "y": 360,
        "wires": []
    },
    {
        "id": "d811d377a8fe043d",
        "type": "function",
        "z": "a241d72b79d8b1b7",
        "name": "Add Topic Heating",
        "func": "//msg.payload = Number(msg.payload);\nmsg.topic = \"Heating\"\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1290,
        "y": 340,
        "wires": [
            [
                "1c4fd26064bb7111",
                "f5300633df3022af"
            ]
        ]
    },
    {
        "id": "d44ca4c463fcb953",
        "type": "function",
        "z": "a241d72b79d8b1b7",
        "name": "Change Topic",
        "func": "//msg.payload = Number(msg.payload);\nmsg.topic = \"Temperature\"\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 560,
        "y": 180,
        "wires": [
            [
                "e0a942bd7c5674d4"
            ]
        ]
    },
    {
        "id": "c0b0a5047e59e3b8",
        "type": "function",
        "z": "a241d72b79d8b1b7",
        "name": "Change Topic",
        "func": "//msg.payload = Number(msg.payload);\nmsg.topic = \"Temperature\"\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 560,
        "y": 380,
        "wires": [
            [
                "a993a62a3973e455"
            ]
        ]
    },
    {
        "id": "073920eea5a7aa87",
        "type": "function",
        "z": "a241d72b79d8b1b7",
        "name": "Change Topic",
        "func": "//msg.payload = Number(msg.payload);\nmsg.topic = \"Demand\"\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 560,
        "y": 220,
        "wires": [
            [
                "e0a942bd7c5674d4"
            ]
        ]
    },
    {
        "id": "78136dc09bdd906b",
        "type": "function",
        "z": "a241d72b79d8b1b7",
        "name": "Change Topic",
        "func": "//msg.payload = Number(msg.payload);\nmsg.topic = \"Humidity\"\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 560,
        "y": 300,
        "wires": [
            [
                "e0a942bd7c5674d4"
            ]
        ]
    },
    {
        "id": "90f45e0b4b22311f",
        "type": "function",
        "z": "a241d72b79d8b1b7",
        "name": "Change Topic",
        "func": "//msg.payload = Number(msg.payload);\nmsg.topic = \"Target\"\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 560,
        "y": 260,
        "wires": [
            [
                "e0a942bd7c5674d4"
            ]
        ]
    },
    {
        "id": "3cc93ae90c0546f7",
        "type": "function",
        "z": "a241d72b79d8b1b7",
        "name": "Change Topic",
        "func": "//msg.payload = Number(msg.payload);\nmsg.topic = \"Demand\"\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 560,
        "y": 420,
        "wires": [
            [
                "a993a62a3973e455"
            ]
        ]
    },
    {
        "id": "11fd30de50f02e56",
        "type": "function",
        "z": "a241d72b79d8b1b7",
        "name": "Change Topic",
        "func": "//msg.payload = Number(msg.payload);\nmsg.topic = \"Target\"\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 560,
        "y": 460,
        "wires": [
            [
                "a993a62a3973e455"
            ]
        ]
    },
    {
        "id": "3cade157397fc070",
        "type": "server",
        "name": "Home Assistant",
        "version": 5,
        "addon": false,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true,
        "heartbeat": false,
        "heartbeatInterval": "30",
        "areaSelector": "friendlyName",
        "deviceSelector": "friendlyName",
        "entitySelector": "friendlyName",
        "statusSeparator": ": ",
        "statusYear": "hidden",
        "statusMonth": "short",
        "statusDay": "numeric",
        "statusHourCycle": "default",
        "statusTimeFormat": "h:m",
        "enableGlobalContextStore": false
    },
    {
        "id": "54904c9be351d74d",
        "type": "influxdb",
        "hostname": "127.0.0.1",
        "port": "8086",
        "protocol": "http",
        "database": "testdatabase",
        "name": "Test Temperature",
        "usetls": false,
        "tls": "",
        "influxdbVersion": "1.8-flux",
        "url": "http://localhost:8086",
        "rejectUnauthorized": true
    }
]

```

Why will this not work?

But thinking about it, assuming that "multi level" works, what are the pro's and con's of that approach vs just putting all of the sensor data in one big "bucket"?

ie  
Lounge-Temp  
Lounge\_Humidity  
Kitchen\_Temp  
Kitchen\_Humidity  
etc

---

<div class="post-metadata">

**Author:** ![mudwalker](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mudwalker](https://discourse.nodered.org/u/mudwalker)\
**Post date:** [14 January 2023 11:46 UTC](https://discourse.nodered.org/t/how-to-save-multiple-objects-to-influx/73659/2 "2023-01-14T11:46:52Z")

</div>

If you post your flow, it would help people see what you are trying to do by running the same code.

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

You can edit and correct your post by clicking the pencil ✏ icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![DublinBayPrawn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dublinbayprawn/32/74333_2.png) [@DublinBayPrawn](https://discourse.nodered.org/u/DublinBayPrawn)\
**Post date:** [14 January 2023 12:20 UTC](https://discourse.nodered.org/t/how-to-save-multiple-objects-to-influx/73659/3 "2023-01-14T12:20:09Z")

</div>

Original post edited mudwalker.

Thanks for realising it was my first post!

---

<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 January 2023 21:48 UTC](https://discourse.nodered.org/t/how-to-save-multiple-objects-to-influx/73659/4 "2023-01-14T21:48:06Z")

</div>

If you check the help text for the influx node you will see that it does not support structured data like that. In fact Influxdb does not support data like that.

Generally where you have similar data for multiple locations then you should put the location as a tag in the record, and send all the data to the same measurement. Then you can query for the data, using a WHERE clause to select the room of interest (or whatever the equivalent is in Influx2, I have not used that recently). So there is no need to join the data from the rooms.

In fact, if the values for a room do not come in from the sensors at the same time then I would not bother joining those either. Send, for example, the temperatures to a measurement called temperature, containing the value and the room (as a tag), send the Demand to a demand measurement, and so on. That will vastly simplify your flow.

---

<div class="post-metadata">

**Author:** ![DublinBayPrawn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dublinbayprawn/32/74333_2.png) [@DublinBayPrawn](https://discourse.nodered.org/u/DublinBayPrawn)\
**Post date:** [15 January 2023 09:55 UTC](https://discourse.nodered.org/t/how-to-save-multiple-objects-to-influx/73659/5 "2023-01-15T09:55:10Z")

</div>

Thanks Colin, I thought I'd seen that structure in a Node Red example.........must have been mistaken.

I shall revert back to the KISS principle until I know better!

Thanks again.

---

<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:** [16 March 2023 09:55 UTC](https://discourse.nodered.org/t/how-to-save-multiple-objects-to-influx/73659/6 "2023-03-16T09:55:56Z")

</div>

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