I want to check my lap-top's battery using one NR-node (node-red-contrib-battery), acpi and upower (using exec-node) and get the data as graphs.
So far so good. But I also wanted to have different colour on the line depending on state (charging/discharging). Here I found some good help in how to Change line colour dependent on value
And no problem when calling acpi, but in the two others, basically the same function just give "TypeError: Cannot convert undefined or null to object"
Here are the functions, except differnt names on constants etc, due to differnt names from function it's basically the same, and can't understand the problem. Changing msg.payload to any other value than null results in no error, but why will it accept payload: null in one instance but not the others?
Here are the code as is now, I have tried so many things so hope someone have better eyes than I have now.
result from acpi, works like a charm
msg.payload = Number(msg.payload);
const charging = flow.get("charging");
let msg2 = null;
if (charging == "Charging"){
msg.topic = "Charging";
msg2 = {payload: null, topic: "Discharging"};
}else{
msg.topic = "Discharging";
msg2 = {payload: null, topic: "Charging"};
}
return [[msg2, msg]];
from the Battery node:
const charging = flow.get("isCharging");
let msg2 = null;
if (charging == true){
msg.topic = "Charging";
msg2 = { payload: null, topic: "Discharging"};
}else{
msg.topic = "Discharging";
msg2 = {payload: null, topic: "Charging"};
}
return [[msg2, msg]];
and from upower:
msg.payload = Number(msg.payload);
const charging = flow.get("state");
let msg2 = null;
if (charging == "charging"){
msg.topic = "Charging";
msg2 = { payload: null, topic: 'Discharging' };
}else{
msg.topic = "Discharging";
msg2 = {payload: null, topic: 'Charging'};
}
return [[msg2, msg]];