Payload format error

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?

[{"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}]

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?

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 ).

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"

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?

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:

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

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

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.

2 Likes

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!

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

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

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