# MQTT to InfluxDB/Grafana -string value

**URL:** <https://discourse.nodered.org/t/mqtt-to-influxdb-grafana-string-value/59731>\
**Category:** General\
**Created:** [11 March 2022 19:05 UTC](https://discourse.nodered.org/t/mqtt-to-influxdb-grafana-string-value/59731 "2022-03-11T19:05:05Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anto79-ops](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/anto79-ops/32/56769_2.png) [@Anto79-ops](https://discourse.nodered.org/u/Anto79-ops)\
**Post date:** [11 March 2022 19:05 UTC](https://discourse.nodered.org/t/mqtt-to-influxdb-grafana-string-value/59731/1 "2022-03-11T19:05:05Z")

</div>

Hi.

I have a flow that connects to broker and brings in values via MQTT. All the values except 1 are numbers (parsed JSON object). One is a state (string) that says, stand-by, discharged, chargind. For some reason, InfluxDB is not liking this. Do I need to confgure the influx node in NodeRed before sending it to the influxDB node? It correct value (word) is displayed in the debug pane after the function node.

The error im getting in influxDB is " unsupported input type for mean aggregate: string"

Here are two flows: one is showing RenogyBattTemp ( **a number** ), the other is RenogyBattState ( **a word** ). Its the latter that I'm having trouble bringing into InfluxDB.

````auto
[
    {
        "id": "a2dfcb43bcf6b83c",
        "type": "mqtt in",
        "z": "51a740fcee7d2bf2",
        "name": "Renogy Battery Temperature",
        "topic": "solar/renogy_battery_1/temperature/state",
        "qos": "2",
        "datatype": "json",
        "broker": "607f4bb0a0ae6958",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 1320,
        "y": 280,
        "wires": [
            [
                "81966104e50ed507"
            ]
        ]
    },
    {
        "id": "81966104e50ed507",
        "type": "function",
        "z": "51a740fcee7d2bf2",
        "name": "",
        "func": "msg.payload = {\n RenogyBattTemp: msg.payload\n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1520,
        "y": 280,
        "wires": [
            [
                "69d1bb968ae31db3",
                "b9dabd5ea9e5b78f"
            ]
        ]
    },
    {
        "id": "69d1bb968ae31db3",
        "type": "influxdb out",
        "z": "51a740fcee7d2bf2",
        "influxdb": "8906a2bc97d7619b",
        "name": "Influx",
        "measurement": "SolarRegulator",
        "precision": "",
        "retentionPolicy": "",
        "database": "database",
        "precisionV18FluxV20": "ms",
        "retentionPolicyV18Flux": "",
        "org": "Home",
        "bucket": "AntonioBucket",
        "x": 1690,
        "y": 280,
        "wires": []
    },
    {
        "id": "faec16862dd6a6a2",
        "type": "mqtt in",
        "z": "51a740fcee7d2bf2",
        "name": "Renogy Battery State",
        "topic": "solar/renogy_battery_1/state/state",
        "qos": "2",
        "datatype": "utf8",
        "broker": "607f4bb0a0ae6958",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 1300,
        "y": 340,
        "wires": [
            [
                "6f6d139f8a0f235e"
            ]
        ]
    },
    {
        "id": "6f6d139f8a0f235e",
        "type": "function",
        "z": "51a740fcee7d2bf2",
        "name": "",
        "func": "msg.payload = {\n RenogyBattState: msg.payload\n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1500,
        "y": 340,
        "wires": [
            [
                "87f5417001aa3137",
                "b9dabd5ea9e5b78f"
            ]
        ]
    },
    {
        "id": "87f5417001aa3137",
        "type": "influxdb out",
        "z": "51a740fcee7d2bf2",
        "influxdb": "8906a2bc97d7619b",
        "name": "Influx",
        "measurement": "SolarRegulator",
        "precision": "",
        "retentionPolicy": "",
        "database": "database",
        "precisionV18FluxV20": "ms",
        "retentionPolicyV18Flux": "",
        "org": "Home",
        "bucket": "AntonioBucket",
        "x": 1690,
        "y": 340,
        "wires": []
    },
    {
        "id": "607f4bb0a0ae6958",
        "type": "mqtt-broker",
        "name": "",
        "broker": "192.168.1.139",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": ""
    },
    {
        "id": "8906a2bc97d7619b",
        "type": "influxdb",
        "hostname": "127.0.0.1",
        "port": "8086",
        "protocol": "http",
        "database": "database",
        "name": "",
        "usetls": false,
        "tls": "",
        "influxdbVersion": "2.0",
        "url": "http://192.168.1.139:8086",
        "rejectUnauthorized": true
    }
]```
````

---

<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:** [11 March 2022 20:10 UTC](https://discourse.nodered.org/t/mqtt-to-influxdb-grafana-string-value/59731/2 "2022-03-11T20:10:56Z")

</div>

Please feed the data you are passing to influx into a debug node and show us what is there.  
Where are you seeing that error? It sounds more like an error you would get when querying the database rather than writing to it. Usually it means that you have specified `mean` in a query where the thing you are trying to query is a string rather than a number. Obviously it is not possible to take the mean of string values.

---

<div class="post-metadata">

**Author:** ![Anto79-ops](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/anto79-ops/32/56769_2.png) [@Anto79-ops](https://discourse.nodered.org/u/Anto79-ops)\
**Post date:** [11 March 2022 20:40 UTC](https://discourse.nodered.org/t/mqtt-to-influxdb-grafana-string-value/59731/3 "2022-03-11T20:40:19Z")

</div>

here's the data that is going into the InfluxDB node:

```auto
{ RenogyBattState: "discharging" }

3/11/2022, 1:34:20 PM[node: b9dabd5ea9e5b78f](http://192.168.1.143:1880/#)solar/regulator/input_current/state : msg.payload : Object

```

The error is on the InfluxDB side (in the actualy program, InfluxDB). Hence I don't now if this is an InfluxDB configuration issue or a Node-Red configuration issue.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [11 March 2022 20:45 UTC](https://discourse.nodered.org/t/mqtt-to-influxdb-grafana-string-value/59731/4 "2022-03-11T20:45:16Z")

</div>

Generally InfluxDB only likes numbers as values, strings would normally be saved as a tag.

---

<div class="post-metadata">

**Author:** ![Anto79-ops](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/anto79-ops/32/56769_2.png) [@Anto79-ops](https://discourse.nodered.org/u/Anto79-ops)\
**Post date:** [11 March 2022 20:54 UTC](https://discourse.nodered.org/t/mqtt-to-influxdb-grafana-string-value/59731/5 "2022-03-11T20:54:20Z")

</div>

That's what I thought.

I'll probably just bypass influxdb and send it directly to the grafana dashboard via the Mqtt-datasource plugin ....but thats another forum!

---

<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:** [11 March 2022 20:57 UTC](https://discourse.nodered.org/t/mqtt-to-influxdb-grafana-string-value/59731/6 "2022-03-11T20:57:42Z")

</div>

> [@TotallyInformation](#):
>
> enerally InfluxDB only likes numbers as values, strings would normally be saved as a tag.

It depends on what the purpose is. There is nothing wrong with storing state as strings. It will not give that error.

---

<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:** [11 March 2022 20:59 UTC](https://discourse.nodered.org/t/mqtt-to-influxdb-grafana-string-value/59731/7 "2022-03-11T20:59:42Z")

</div>

> [@Anto79-ops](#):
>
> The error is on the InfluxDB side (in the actualy program, InfluxDB)

I am absolutely conviced that the error is coming when something tries to query the database and is attempting to take a mean. For example, are you trying to plot it on a chart in Grafana? Obviously you cannot chart strings.  
If it isn't that then exactly where and when do you see the error?

---

<div class="post-metadata">

**Author:** ![Anto79-ops](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/anto79-ops/32/56769_2.png) [@Anto79-ops](https://discourse.nodered.org/u/Anto79-ops)\
**Post date:** [11 March 2022 21:19 UTC](https://discourse.nodered.org/t/mqtt-to-influxdb-grafana-string-value/59731/8 "2022-03-11T21:19:34Z")

</div>

@Colin you're right it was because of the mean setting in InfluxDB that it gave that error, see when I change from mean to last it does report the value as zero (but no error).

 ![InfluxDB_mean](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/1/318d56668ea10b8a1fdd0fbead735040653fbd1f.jpeg)

 ![InfluxDB_last](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/a/5a7abd2b1d740a46ca43e541b05e73431794473b.jpeg)

Now, to actually send the payload value (string) state, I guess I have to figure that out in Grafana as Grafana is just showing a 0 as this value.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [11 March 2022 21:22 UTC](https://discourse.nodered.org/t/mqtt-to-influxdb-grafana-string-value/59731/9 "2022-03-11T21:22:08Z")

</div>

> [@Colin](#):
>
> There is nothing wrong with storing state as strings

You _can_, doesn't mean you _should_. 🙂

> [@Colin](#):
>
> is attempting to take a mean. For example, are you trying to plot it on a chart in Grafana? Obviously you cannot chart strings.

Which is exactly why it is best to keep values as numbers and use tags for strings.

---

<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:** [11 March 2022 21:59 UTC](https://discourse.nodered.org/t/mqtt-to-influxdb-grafana-string-value/59731/10 "2022-03-11T21:59:15Z")

</div>

> [@Anto79-ops](#):
>
> I guess I have to figure that out in Grafana as Grafana is just showing a 0 as this value.

If you want to plot the value then you will have to store a number representing the state, rather than the state itself. If you just want to show the value in a text box (I forget what they are called in grafana) then it will be fine as a string.

---

<div class="post-metadata">

**Author:** ![Anto79-ops](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/anto79-ops/32/56769_2.png) [@Anto79-ops](https://discourse.nodered.org/u/Anto79-ops)\
**Post date:** [11 March 2022 22:42 UTC](https://discourse.nodered.org/t/mqtt-to-influxdb-grafana-string-value/59731/11 "2022-03-11T22:42:27Z")

</div>

thanks, I have some homework to do!

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [11 March 2022 23:01 UTC](https://discourse.nodered.org/t/mqtt-to-influxdb-grafana-string-value/59731/12 "2022-03-11T23:01:36Z")

</div>

🙂  
You will find some guidance buried elsewhere in the forum. I know I'm not the only one who has posted recommendations about how to structure data for InfluxDB.

---

<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:** [10 May 2022 23:01 UTC](https://discourse.nodered.org/t/mqtt-to-influxdb-grafana-string-value/59731/13 "2022-05-10T23:01:58Z")

</div>

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