I’m using an “Edit Function” node to test for various weather conditions. Information input to the node is not case (upper/lower) consistent so I’m using the toLowerCase() function to convert the incoming payload to lower case before testing it. The node outputs what I expect when an Inject nodes is used to inject a weather condition. Let me explain further. If “Snowy” or “snowy” is injected, the node outputs the payload that code within the node selects. If I allow the flow to work on it’s own, when the state node passes on current weather conditions, I sometimes see an error;
“TypeError: msg.payload.toLowerCase is not a function”
The code in the “Edit Function” node is as follows;
const globalHomeAssistant = global.get('homeassistant');
var weather_condition = msg.payload.toLowerCase();
if (weather_condition == "snowy" || weather_condition == "snow" || weather_condition == "heavy snow" || weather_condition == "heavy flurries" || weather_condition == "blowing snow" || weather_condition == "drifting snow" ) {
msg.payload = "turn_on";
return [msg,null];
}else{
if (weather_condition == "clear") {
msg.payload = "STOP";
return [null,msg];
}
}
return [null,null]
What is causing the error to occur?