# Payload format error

**URL:** <https://discourse.nodered.org/t/payload-format-error/45238>\
**Category:** General\
**Created:** [5 May 2021 22:38 UTC](https://discourse.nodered.org/t/payload-format-error/45238 "2021-05-05T22:38:20Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ives25](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ives25/32/39877_2.png) [@Ives25](https://discourse.nodered.org/u/Ives25)\
**Post date:** [5 May 2021 22:38 UTC](https://discourse.nodered.org/t/payload-format-error/45238/1 "2021-05-05T22:38:20Z")

</div>

Hi,  
I have a flow which allows to send the value of an electric meter in Influxdb (Wh).

The value is sent (it appears in the debug node) but in Influxdb I have an error message: "unsupported mean iterator type: \* query.stringInterruptIterator".

I don't know how to format the payload?

```auto
[{"id":"cafc5040.ba65f","type":"debug","z":"5f869aea.270dd4","name":"Energie","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":960,"y":80,"wires":[]},{"id":"c92c7602.90e1b8","type":"inject","z":"5f869aea.270dd4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"","payloadType":"date","x":380,"y":80,"wires":[["d5a4a67d.00c818"]]},{"id":"d5a4a67d.00c818","type":"api-current-state","z":"5f869aea.270dd4","name":"","server":"6dbc60a4.9907","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.compteur_elec","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":680,"y":80,"wires":[["cafc5040.ba65f","bdcdb7c5.a69ff8"]]},{"id":"bdcdb7c5.a69ff8","type":"influxdb out","z":"5f869aea.270dd4","influxdb":"468eb0a8.3cc35","name":"influxdb out NR","measurement":"Wh","precision":"","retentionPolicy":"","database":"database","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":1000,"y":160,"wires":[]},{"id":"6dbc60a4.9907","type":"server","name":"Home Assistant","addon":true},{"id":"468eb0a8.3cc35","type":"influxdb","hostname":"a0d7b954-influxdb","port":"8086","protocol":"http","database":"nodereddb","name":"influx db addon","usetls":false,"tls":"","influxdbVersion":"1.x","url":"http://localhost:8086","rejectUnauthorized":true}]

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [6 May 2021 00:01 UTC](https://discourse.nodered.org/t/payload-format-error/45238/2 "2021-05-06T00:01:36Z")

</div>

One of your nodes (api-current-state) is not a core node. What is the full name of the node - i.e. node-red-contrib-?????

Also, are you using home assistant?

Put a `debug` node (set to output the 'Complete msg object) on the current-state node and run a test. Then open all the levels in the debug log and copy and paste them to a reply.

Are you sure you are formating the input to the `influx-out` node properly - have you read the ReadMe for the node so you know how to format the data?

---

<div class="post-metadata">

**Author:** ![Ives25](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ives25/32/39877_2.png) [@Ives25](https://discourse.nodered.org/u/Ives25)\
**Post date:** [6 May 2021 06:43 UTC](https://discourse.nodered.org/t/payload-format-error/45238/3 "2021-05-06T06:43:57Z")

</div>

Yes I am using Home Assistant.  
The central node is "node-red-control-home-assistant-websoket: api-current-state"

**influxdb out**  
A simple influxdb output node to write values and tags to an influxdb measurement.  
The fields and tags to write are in **msg.payload**. If **msg.payload** is a string, number, or boolean, it will be written as a single value to the specified measurement (called _value_ ).

```auto
06/05/2021, 08:38:40node: Energie
msg : Object
object
_msgid: "33856207.a7d97e"
payload: "36343200"
topic: ""
data: object
entity_id: "sensor.compteur_elec"
state: "36343200"
attributes: object
unit_of_measurement: "Wh"
friendly_name: "compteur_elec"
device_class: "energy"
last_changed: "2021-05-06T06:37:50.742754+00:00"
last_updated: "2021-05-06T06:37:50.742754+00:00"
context: object
id: "5f8dc7d686bf0416c8e3480609e3d5c6"
parent_id: null
user_id: null
timeSinceChangedMs: 48178
original_state: "36343200"

```

---

<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:** [6 May 2021 08:11 UTC](https://discourse.nodered.org/t/payload-format-error/45238/4 "2021-05-06T08:11:59Z")

</div>

> [@Ives25](#):
>
> unsupported mean iterator type: \* query.stringInterruptIterator".

That is not an error I would expect from writing to the database, that is an error you might get when querying the database. Are you sure it is the Influxdb Out node that is showing that error?

---

<div class="post-metadata">

**Author:** ![Ives25](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ives25/32/39877_2.png) [@Ives25](https://discourse.nodered.org/u/Ives25)\
**Post date:** [6 May 2021 08:36 UTC](https://discourse.nodered.org/t/payload-format-error/45238/5 "2021-05-06T08:36:28Z")

</div>

To test the exchanges with the database I used a similar node which sends a value (number) with the Tag (° C).  
From influxdb I can display this value but when that selects the "Wh" Tag and I click on "value" here is the message:

 ![Influxdb](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/1/f1289c32b210bb5660586e7bf3059ca8b837f320.jpeg)

---

<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:** [6 May 2021 08:56 UTC](https://discourse.nodered.org/t/payload-format-error/45238/6 "2021-05-06T08:56:20Z")

</div>

You gave the impression in the first post that the error was seen in node-red, not Grafana (which you had not mentioned).

If you look in the debug outpu you posted showing what you are writing to the db you will see

> [@Ives25](#):
>
> `payload: "36343200"`

As you can see that is a string not a number. Then in Grafana you are asking to take the mean of those values, but you can't take the mean of string values (which is what the error means). You need to write numbers not strings. One way to do that is to feed it through a function node containing this before passing it to Influx

```auto
msg.payload = Number(msg.payload)
return msg

```

You will need to Drop the measurement in Influx as there is no way of changing the field type after you have created a field.

---

<div class="post-metadata">

**Author:** ![Ives25](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ives25/32/39877_2.png) [@Ives25](https://discourse.nodered.org/u/Ives25)\
**Post date:** [6 May 2021 09:50 UTC](https://discourse.nodered.org/t/payload-format-error/45238/7 "2021-05-06T09:50:36Z")

</div>

Thank you so much ! I now have the value in the database.  
There is still a long way to go to have day, month and year consumption available!

---

<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:** [6 May 2021 10:08 UTC](https://discourse.nodered.org/t/payload-format-error/45238/8 "2021-05-06T10:08:56Z")

</div>

> [@Ives25](#):
>
> There is still a long way to go to have day, month and year consumption available!

If those figures are Watt hours then you can get the usage over a period by using SUM in the query.

---

<div class="post-metadata">

**Author:** ![Ives25](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ives25/32/39877_2.png) [@Ives25](https://discourse.nodered.org/u/Ives25)\
**Post date:** [6 May 2021 11:26 UTC](https://discourse.nodered.org/t/payload-format-error/45238/9 "2021-05-06T11:26:09Z")

</div>

Thanks, I'll give it a try and will most likely come back to ask questions!

---

<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:** [20 May 2021 11:26 UTC](https://discourse.nodered.org/t/payload-format-error/45238/10 "2021-05-20T11:26:11Z")

</div>

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