I am trying to node-red to poll the webserver in my Daikin heat pump to get inside and outside temeperatures so I can log them against the schedule I've also configured the unit with.
When polling it for the values, it returns this string of text
"ret=OK,htemp=21.5,hhum=-,otemp=18.0,err=0,cmpfreq=0"
I use this code in a node-red function to split them at the commas
msg.payload = msg.payload.split(",");
return msg;
It returns an array with 6 fields like this:
array[6]
0: "ret=OK"
1: "htemp=21.5"
2: "hhum=-"
3: "otemp=18.0"
4: "err=0"
5: "cmpfreq=0"
This is then put into influxdb by node-red with the numeric fields of the array being the fields created.
I'm unable to analyse this data because it has the text in the fields that end up in the influxdb. I can't work out how to remove the text to the left of and including the = sign without creating errors in node-red.
As a minimum, I'd like the data to be like this:
array[6]
0: "OK"
1: "21.5"
2: "-"
3: "18.0"
4: "0"
5: "0"
Even better would be to use the text to the left of the = sign as the field values in the array so they populate in influxdb. This would make analyics easier.
It would then look like this(extra spaces to line up colons for readability):
array[6]
ret: "OK"
htemp: "21.5"
hhum: "-"
otemp: "18.0"
err: "0"
cmpfreq: "0"
I know the syntax is javascript based, but I'm not strong enough in the area to figure this one out. I've been at it for a day and have had no luck.
Thanks!
P.S. for anyone who owns a Daikin US7 with Wifi and wants to control it over IP, I've been using this repo to get the values I need to send to the webserver.
Updates with requested info
InfluxDB is v0.10.0, webui says go1.6rc1 Node-RED is v.0.16.2 Node-RED is using node-red-contrib-influxdb v0.1.1
When I used this code in the function:
msg.payload = msg.payload.split(",").split("=")[0];
return msg;
I got this error when putting a debug tag on the output of the function:
function : (error)
"TypeError: msg.payload.split(...).split is not a function"
According to the doc, the output node expects an Object payload with the properties/values you want to push to InfluxDB.
So you need to split up that input string, and for that your first call to .split(',')
is correct. But this returns an Array of Strings, which cannot be split again with .split('=')
(hence the error you get).
Here is how you split the second level of key=value
pairs and put those in an object:
var o = {}; // new empty Object that will be used for next payload
msg.payload.split(',').forEach(function(kv) { // loop on 'key=value' entries in array
var pair = kv.split('='); // split entry to isolate key and value
var key = pair[0];
var value = pair[1];
o[key] = value; // save that as new property for our Object
});
msg.payload = o; // Make that object the new payload
(edited with comments)