Node-red influxdb invalid boolean

Hello guys, I'm new to node-red and influxdb and mqtt so bear with me. So I'm trying to send a Json object to an influxdb database I created but when I try to send the object to influxdb I get the following error:

Error: A 400 Bad Request error occurred: {"error":"unable to parse 'sonoff ENERGY=[object Object],Time=\"2019-02-16T19:51:25\"': invalid boolean"}

The json string I get from the sensor is this:

"{"Time":"2019-02-16T19:51:25","ENERGY":{"TotalStartTime":"2019-02-11T17:34:56","Total":1.507,"Yesterday":0.348,"Today":1.159,"Period":6,"Power":66,"ApparentPower":67,"ReactivePower":0,"Factor":0.99,"Voltage":126,"Current":0.532}}"

Finally, the flow I am using is the following flow:

[{"id":"6ce293e0.d07ab4","type":"mqtt in","z":"31324429.f7d1ac","name":"","topic":"stat/sonoff/POWER","qos":"2","broker":"b219fa03.3781f8","x":279,"y":129,"wires":[["c6f3034f.ebd078"]]},{"id":"c6f3034f.ebd078","type":"debug","z":"31324429.f7d1ac","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":714,"y":102,"wires":[]},{"id":"b35ffdb9.9eb05","type":"mqtt in","z":"31324429.f7d1ac","name":"","topic":"tele/sonoff/SENSOR","qos":"2","broker":"b219fa03.3781f8","x":282,"y":215,"wires":[["ea18aa60.babca"]]},{"id":"ea18aa60.babca","type":"json","z":"31324429.f7d1ac","name":"","property":"payload","action":"","pretty":true,"x":531.5,"y":213,"wires":[["c6f3034f.ebd078","de651a0c.c782f"]]},{"id":"de651a0c.c782f","type":"influxdb out","z":"31324429.f7d1ac","influxdb":"de82086b.a7424","name":"measurements","measurement":"sonoff","precision":"","retentionPolicy":"","x":792.5,"y":218,"wires":[]},{"id":"b219fa03.3781f8","type":"mqtt-broker","z":"","name":"TESIS","broker":"192.168.2.3","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"de82086b.a7424","type":"influxdb","z":"","hostname":"192.168.2.3","port":"8086","protocol":"http","database":"Tesis","name":"TESIS","usetls":false,"tls":""}]

Everything together along with the error message looks something like this

I copied the flow from a video I saw on youtube and it works for his sensor, unfortunately it doesn't work for mine even tho we have the same sensor. I don't know if I'm doing something wrong and I can't seem to find the problem.

Firstly, your flow is not importable, please see the link below for how to format it correctly. You can edit your previous post to fix it.
However it seems from the image that the data you are sending to the influx node is not in the right format. If you look at the Info tab for that node it tells you the expected formats. What tags/fields are you wanting to write the data to? As you have it, it is trying to write the whole ENERGY object to one field.

I've edited the post as you mentioned, I'm not trying to write the whole ENERGY object to one field. I want everything in the ENERGY object to be written in the database and have each measurement (TotalStartTime, Total, Yesterday, etc) in different tags.

Look at the info tab for the influx node and it tells you how to format the data. You have to split them out of the ENERGY object.

1 Like

Thank for the advice, I've managed to edit the payload and successfully store it in influxdb.

Hi. I have the same problem, could you tell me how?

How to do what?

Can you help with how to edit the payload to make this work?

This section of the docs has information on messages and how to manipulate the contents.
https://nodered.org/docs/user-guide/messages

Thanks, that was helpful

Hi,

I'm new to node-red and influxdb, I have a zigbee sensor storing info in an influxdb and displaying in a grafana chart. Everything is working as expected but I'm getting the following error for each component that I storing in the influxDB:

Error: A 400 Bad Request error occurred: {"error":"unable to parse 'HumDespacho value=undefined': invalid boolean"}

I'm sending the data as a number and it's stored as float.

Could you help me?

This is the flow I'm using:

[{"id":"5f9c6c16.8ff774","type":"ui_gauge","z":"320a2d6e.4e6b22","name":"Temperatura Despacho Dashboard","group":"4a8a673d.b424a8","order":2,"width":4,"height":4,"gtype":"compass","title":"Temperatura","label":"º C","format":"{{value}} ","min":"16","max":"40","colors":["#00b500","#e6e600","#ca3838"],"seg1":"24","seg2":"27","x":800,"y":160,"wires":[]},{"id":"139f2101.baa01f","type":"ui_gauge","z":"320a2d6e.4e6b22","name":"Humedad Despacho Dashboard","group":"4a8a673d.b424a8","order":3,"width":4,"height":4,"gtype":"compass","title":"Humedad","label":"%","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"55","seg2":"70","x":790,"y":232,"wires":[]},{"id":"f1921d7b.315ab","type":"ui_text","z":"320a2d6e.4e6b22","group":"4a8a673d.b424a8","order":4,"width":0,"height":0,"name":"Presión Atmosférica Dashboard","label":"Presión Atmosférica","format":"{{msg.payload}}","layout":"col-center","x":790,"y":306,"wires":[]},{"id":"ebd5330d.fa2db","type":"zigbee-converter","z":"320a2d6e.4e6b22","shepherd":"16638dd0.3a1df2","name":"Despacho","topic":"zigbee/${name}","settopic":"zigbee/${name}/set","gettopic":"zigbee/${name}/get","device":"0x00158d00034d1564","attribute":"","payload":"json","x":250,"y":220,"wires":[["9c6e97a8.aeaaf8"]]},{"id":"3d566369.80c01c","type":"debug","z":"320a2d6e.4e6b22","name":"Link Quality","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":730,"y":340,"wires":[]},{"id":"9c6e97a8.aeaaf8","type":"function","z":"320a2d6e.4e6b22","name":"Función","func":"var msg1 = { payload:msg.payload.battery };\nvar msg2 = { payload:msg.payload.voltage };\nvar msg3 = { payload:msg.payload.temperature };\nvar msg4 = { payload:msg.payload.humidity};\nvar msg5 = { payload:msg.payload.pressure};\nvar msg6 = { payload:msg.payload.linkquality};\n\n\nreturn [ msg1, msg2, msg3, msg4, msg5, msg6 ];","outputs":6,"noerr":0,"x":420,"y":220,"wires":[["59d7df81.23d47"],["7e48d54b.3a2ebc"],["5f9c6c16.8ff774","81f94e3b.fc6788"],["139f2101.baa01f","1640bd24.00247b"],["f1921d7b.315ab"],["3d566369.80c01c"]],"outputLabels":["% Batería","V Batería","Temperatura","Humedad","Presión Atmosférica",""]},{"id":"7e48d54b.3a2ebc","type":"ui_text","z":"320a2d6e.4e6b22","group":"4a8a673d.b424a8","order":6,"width":0,"height":0,"name":"Voltaje Batería Sensor Dashboard","label":"Voltaje Batería ","format":"{{value | number:0}} V","layout":"row-spread","x":800,"y":120,"wires":[]},{"id":"ea0ff1e7.43d8e","type":"comment","z":"320a2d6e.4e6b22","name":"Sensor Aqara Despacho","info":"","x":470,"y":100,"wires":[]},{"id":"81f94e3b.fc6788","type":"influxdb out","z":"320a2d6e.4e6b22","influxdb":"911d5296.4c4c08","name":"TempDespacho","measurement":"TempDespacho","precision":"","retentionPolicy":"","x":740,"y":196,"wires":[]},{"id":"1640bd24.00247b","type":"influxdb out","z":"320a2d6e.4e6b22","influxdb":"6427c6ae.c3c0d8","name":"HumDespacho","measurement":"HumDespacho","precision":"","retentionPolicy":"","x":740,"y":269,"wires":[]},{"id":"59d7df81.23d47","type":"influxdb out","z":"320a2d6e.4e6b22","influxdb":"972ba4d3.b96c38","name":"BatLevelDespacho","measurement":"BatLevelDespacho","precision":"","retentionPolicy":"","x":750,"y":80,"wires":[]},{"id":"4a8a673d.b424a8","type":"ui_group","z":"","name":"Sensores","tab":"67818b5d.842374","order":1,"disp":true,"width":"8","collapse":false},{"id":"16638dd0.3a1df2","type":"zigbee-shepherd","z":"","name":"zigbee herdsman","path":"/dev/ttyACM0","baudRate":"115200","rtscts":true,"channelList":[11],"led":"disabled"},{"id":"911d5296.4c4c08","type":"influxdb","z":"","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"temperature","name":"","usetls":false,"tls":""},{"id":"6427c6ae.c3c0d8","type":"influxdb","z":"","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"humidity","name":"","usetls":false,"tls":""},{"id":"972ba4d3.b96c38","type":"influxdb","z":"","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"batteryLevel","name":"","usetls":false,"tls":""},{"id":"67818b5d.842374","type":"ui_tab","z":"","name":"Despacho","icon":"airline_seat_recline_normal","order":2,"disabled":false,"hidden":false}]

Start off by putting a catch node connected to a debug node (set to display "Complete msg object' to isolate where the error is occurring.

Also when you find a thread is a year old, it is better to start a new thread.

I can open a new thread if it's better, just let me know.I've just thought it was better to continue with this because the error seems similar.

Thanks for the hint. This is what I get, it seems to be relate to the "influxdb out" node.

As you can see the data is logging to influxdb and at some point start throwing this error in node-red. Looking at influxdb it seems to be OK

influxdb1

influxdb2

So if you look at the error yhrn look sat the debug msg three above it, you will see the same _msgid

notice that there is no payload? It would seem to me that the msg from your zigbee device doesn't always have all the data in it.

You should connect a debug node (set to display the 'Complete msg object') to the outout of the zigbee node to see what the data is.

You're right, following your indications I can see 4 messages and 2 errors.

Those errors are because there is no "humitidy" information I guess, so that make sense. Payload is different.

Correct Payload

Incorrect Payload

influxdb_error4_bad

What I don't understand is why I'm getting this error if in the function I'm routing only the "humidity" information. This is what the flow looks like:

And the function contains:

image

You are unconditionally sending ALL 6 messages.

Consider this

  • a msg arrives at function & msg.payload.humitity is undefined
  • you WILL send {payload: undefined} out of pin 4. Every time!

You should check before making the msg an actual object...

var msg1, msg2, msg3, msg4, msg5, msg6 //these will be empty/uninitialised variables
if(msg.payload.battery){
  msg1 = {payload: msg.payload.battery}
}
//..others...
if(msg.payload.humitity){
  msg4 = {payload: msg.payload.humitity}
}
//..etc...
return [msg1, msg2, msg3, msg4, msg5, msg6];

... the reason this will work is if humitity is null, you WONT turn msg4 into an object (it will be null) - node-red doesnt fire an output if the item is null/undefined.

PS: Please post code instead of screen shots - it is annoying to have to retype something to show you a solution

And please put code between thre back ticks
```
like this
```

Two things right off. First, put a name in each of your debug nodes to make it easy to identify what messages in the log are from which debug node. Second, get rid of one of the catch nodes and connect the other to a stand alone debug node - you don't need two of them.

So it looks like the data coming in is sometimes is missing the battery, voltage, humidity and pressure data. That is something you will have to take up with the make of the device.

You could add a switch after each of the function nodes outputs and check if the data is defined and only pass it on if it is.

@Steve-Mcl, @zenofmud Following your indications finally I've managed to get it solve. :smiley: Also I take some tips to debug and to post in the right way. Many thanks