Tasmota (MQTT) switches repeatedly marked as "unavailable"

I just tried this and by changing the case from “Online” to “online” and “Offline” to “offline” broke all of my switches. They all show unavailable in HA. I’m on HA v0.85.1

I use Node Red and had an issue with some automations triggered when the Sonoff went from unavailable to off, I used this function to avoid the issue. Hope someone can use it.

var newState = msg.data.event.new_state.state;
var oldState = msg.data.event.old_state.state;
if (oldState == "on" && newState == "off") {
    msg.payload = "on";
}
if (newState == "off" && oldState == "on") {
    msg.payload = "off";
}
return msg;
1 Like

Thanks a lot @alteredcode - had this issue, tried your function within Node Red - issue solved :wink:

Hi @alteredcode

I’m brand new to HASS, a 1 week old newbie with 2 tasmota sonoff basic’s that seem to be going offline often, which then triggers something then shuts them off.

Where does this code example go? Is it before my schedex function or?