Json to influxdb - How to populate fields

Hello

I'm trying to send data from MQTT to influxdb using json.
So far I managed to send the data over to influx, but not in the intended way.

I can import a single object from the json or all of them, but not 2/3/4... while defining the field "field". It always appears as value, even if contains the right content.

Any suggestion? I've read multiple official docs, but I can't sort it out!

Thanks

01

03

Welcome to the forum @stayorso

Are you using node-red-contrib-influxdb to write to the database?

Initially the important thing is what you are sending to the influx node, not how you generate that message. Feed the message you are sending to influx into a debug node and show us what it looks like. Set the debug node to Output Complete Message.

1 Like

Thanks @Colin !

Yes, I'm using node-red-contrib-influx to write to the db!

{"Operation Mode":"Fan Only","Thermostat ON/OFF":"OFF","Defrost Operation":"OFF","Demand Signal":"OFF","Outdoor air temp.":9,"O/U Heat Exch. Temp.":0,"O/U Heat Exch. Mid-temp.":7,"INV fin temp.":14.5,"Pressure(T)":"Conv 405 not avail.","INV primary current (A)":0.5,"Voltage (V)":"-28160","Brine Flow Switch":"OFF","Fan 1 (10 rpm)":0,"Freeze Protection":"OFF","Silent Mode":"OFF","Freeze Protection for water piping":"OFF","DHW setpoint":44,"LW setpoint (main)":15,"Water flow switch":"OFF","Thermal protector (Q1L) BUH":"OFF","Thermal protector BSH":"ON","Benefit kWh rate power supply":"OFF","2way valve(On:Heat_Off:Cool)":"ON","3way valve(On:DHW_Off:Space)":"OFF","BSH":"OFF","BUH Step1":"OFF","BUH Step2":"OFF","BPH":"OFF","Water pump operation":"OFF","Outlet Water Heat Exch. Temp. (R1T)":22.2,"Outlet Water BUH Temp. (R2T)":31.5,"Refrig. Temp. liquid side (R3T)":18.8,"Inlet water temp.(R4T)":20,"DHW tank temp. (R5T)":39.5,"RT Temp.":0,"Outdoor Ambient or Ext Sensor":16.4,"M5VIN":"0V","M5AmpIn":"0mA","M5BatV":"4.13V","M5BatCur":"0mA","M5BatPwr":"0mW","WifiRSSI":"-39dBm","FreeMem":"221568"}

Unformatted looks like this:

espaltherma/ATTR : msg.payload : Object
object
Operation Mode: "Fan Only"
Thermostat ON/OFF: "OFF"
Defrost Operation: "OFF"
Demand Signal: "OFF"
Outdoor air temp.: 9

As far as I understood I can pick a specific value by appending the path of the payload, such as:

msg.payload["Outdoor air temp."]

I can send a single item to the db with a change node, but I cannot create a measurement that contains some (not all) fields with their respective names.

If you look in the help text for the node you will see that it says:

If msg.payload is an object containing multiple properties, the fields will be written to the measurement.

So all you need to do is to remove the fields you don't want from msg.payload, leaving just the ones you want in the database. The Change node has a Delete option in the dropdown. For a field name without special characters in you would use Delete msg.payload.fieldname, but since the names have spaces, if you didn't want Operation Mode in the db you can use Delete msg.payload["Operation Mode"].

If you have control of those field names then change then and take out the spaces, you are just making life difficult for yourself.

Sorry, I read the node docs, but I missed that part. My fault :confused:
Unfortunately I cannot get rid of the spaces in the field names.

Can I change the file name using a change node? It won't help me in this specific case, but it would be worth knowing.

001
002

It's hard to grasp the logic behind it as none of things that I try works lol

The payload name property (not the value itself) should be a string and therefore I should look for it inside msg.payload["Operation Mode"] and then change it.

I'm following this:
Working with messages : Node-RED (nodered.org)

The Search For option searches in the field contents for the value. You want to change the name. For that use Move msg.payload["Operation Mode"] To msg.payload.Operation_Mode. You don't need the square brackets syntax in the second one because it hasn't got spaces in.

Thanks Colin, managed (almost) everything.
Do you why "value" is used as a field name if there's only one field for each measurement?
It doesn't seem to be possible to change the field name if there is only one value.

What message are you sending to the influx out node when you write the data?

Oh, I see what you have done, I think. You have decided to send each value to its own measurement, instead of sending it to different fields in one measurement, which is what I thought you were going to do, and would be much more efficient in the database.

So if I am right you have just sent a payload with a single value, so, as specified in the help text,
" If msg.payload is a string, number, or boolean, it will be written as a single value to the specified measurement (called value )."
So value is the name of the field in the measurement. If instead you had sent the whole object (after removing keys you did not want) to a single measurement then you would be able to select which one you wanted by name.

Correct!
I agree that it would be much more efficient database wise, but I was just trying to learn and explore every aspect of the writing flow. I thought I was doing something wrong and that's why asked, basically I thought I wasn't transferring that specific value to the db.

Thank you for the clear answers!

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