I have seen some discussions regarding using the batch node for influxdb but have not got my head around it yet.
I have an array of data in msg.payload that I want to use the batch node to write an entry to a table but replacing the time value with a value in one of the array fields:
A short array of my data is below:
[{"time":"2023-01-20T00:20:03.271Z","domain":"sensor","elec_cons":7.138,"elec_cost_pounds":2.85,"elec_standing_charge_pence":49.54,"elec_tariff_pence":33.029,"entity_id":"utilities","friendly_name_str":"Utilities","gas_cons":28.756069,"gas_cost_pounds":3.23,"gas_standing_charge_pence":28.48,"gas_tariff_pence":10.244,"readings_date":20230119,"readings_date_str":"2023-01-19","value":6.08},
{"time":"2023-01-23T00:20:02.849Z","domain":"sensor","elec_cons":7.041,"elec_cost_pounds":2.82,"elec_standing_charge_pence":49.54,"elec_tariff_pence":33.029,"entity_id":"utilities","friendly_name_str":"Utilities","gas_cons":33.678944,"gas_cost_pounds":3.73,"gas_standing_charge_pence":28.48,"gas_tariff_pence":10.244,"readings_date":20230122,"readings_date_str":"2023-01-22","value":6.55},
{"time":"2023-01-24T00:20:02.673Z","domain":"sensor","elec_cons":7.419,"elec_cost_pounds":2.94,"elec_standing_charge_pence":49.54,"elec_tariff_pence":33.029,"entity_id":"utilities","friendly_name_str":"Utilities","gas_cons":21.903017,"gas_cost_pounds":2.53,"gas_standing_charge_pence":28.48,"gas_tariff_pence":10.244,"readings_date":20230123,"readings_date_str":"2023-01-23","value":5.47}
]
There can be a variable number of array entries.
for each of these, I would like to write a new influxdb sensor entry with the following fields:
time: this set to "readings_date_str" value, I guess at 00:00:00 time on that day
elec_cons: same as array input
elec_cost_pounds: same as array input
elec_standing_charge_pence: same as array input
elec_tariff_pence: same as array input
gas_cons: same as array input
gas_cost_pounds: same as array input
gas_standing_charge_pence: same as array input
gas_tariff_pence: same as array input
total_cost: set to "value"
I don't know how an array can be read and each processed by the batch node (although I assume this is built as a payload in a function node?) plus I am also unsure about measurement and tag fields. What do these really mean? Are the expected values in some standard list of values?
There are mentions of iterating through arrays in discussions but not many good examples of how that is actually coded.