I am trying to get the state of a home assistant binary sensor inside of a function node so I can do some basic if else comparison but not getting getting a value:
msg.BMS = msg.payload.result.deviceWapper.realTimeDataBMS;
if(msg.BMS == null || msg.BMS == 'undefined') {
node.error("Could not get BMS details")
}
msg.pv = {};
msg.pv['bms_voltage'] = msg.BMS[0].value;
msg.pv['bms_current'] = msg.BMS[1].value;
msg.pv['bms_charge_current'] = msg.BMS[2].value;
msg.pv['bms_discharge_current'] = msg.BMS[3].value;
var bms_voltage = {
payload: msg.pv.bms_voltage,
topic: "home/solar/bms/voltage"
};
var bms_current = {
payload: msg.pv.bms_current,
topic: "home/solar/bms/current"
};
var bms_charge_current = {
payload: msg.pv.bms_charge_current,
topic: "home/solar/bms/charge_current"
};
var bms_discharge_current = {
payload: msg.pv.bms_discharge_current,
topic: "home/solar/bms/discharge_current"
};
var pizero2State = global.get("homeassistant.homeAssistant.states['binary_sensor.pi_zero_2'].state");
var piz = {
payload: pizero2State,
topic: "home/solar/bms/pizerotest"
};
return [[bms_voltage, bms_current, bms_charge_current, bms_discharge_current, piz],msg];
Basically that global.get is always undefined, not sure why