2022.3 - MQTT lights in unknown state on startup

Edit: Solved for Tasmota devices by @toml in post 2. Will monitor devices to see if any side effects but so far is good.

After upgrading to version 2022.3 my MQTT lights are showing unknown state on reboot.

I am unsure if this was the case before upgrade - my issue is with the display of unknown state on. reboot in Lovelace:

Screen Shot 2022-03-03 at 12.26.10

The lightning bolts are what is normally displayed if your device does not have a state topic, or optimistic mode is set to true.

Clicking on either of the symbols reverts the switch to the toggle control, as per the Pergola Light Switch in the image.

A typical definition is:

  - platform: mqtt
    name: "Side Verandah Lights"
    command_topic: "cmnd/sonoff3/power"
    state_topic: "stat/sonoff3/POWER"
    payload_on: "ON"
    payload_off: "OFF"
    retain: true

As you can see I have a state topic - which works correctly as confirmed with MQTT explorer.

Is this a configuration issue in the new version that I need to adjust? Or a bug with MQTT in the new version? Or like the binary state sensor in the previous upgrade just something we have to live with?

If they have tasmota on them try setting power retain on:

PowerRetain MQTT power retain state
0 / off = disable MQTT power retain on status update (default)
1 / on = enable MQTT power retain on status update

This way home assistant gets the last known state from the broker on startup.

There may be issues with doing this (“ghost switching”), but try it just for a test.

1 Like

I have the same problem and it is not a problem of retain. They are properly configured. https://github.com/home-assistant/core/issues/67545
Reverting back to 2022.2.9 fixed the problem and upgrading again ended up with the same problem

So you did the test I asked for then?

  1. if I revert back to 2022.2.9 the problem is fixed, so it is not about retain;
  2. I have already the retain correctly activated; my tasmota devices have the same exact configuration, including the retain (so those 3 have retain activated);
  3. mqtt explorer shows the payload is retained;
  4. I have a couple of light that are not “mqtt”, but rely on xiaomi gateway integration and they have not retain (they don’t use mqtt)

Yes this works for Tasmota - however the issue raised on Github is for the Xiaomi Gateway MQTT lights.

I’ll mark this solved with a note that it works for Tasmota lights.

I’m experiencing this problem with my TreatLife SS01 3-way lights (set up using digiblur’s instructions). I set ‘PowerRetain 1’ and the light seemed to remember its setting if the setting was “on”. But if it’s “off” when Home Assistant restarts, Home Assistant sees it as “unknown”.

My testing has shown it works if the state is off - with the exception of one device. As my Tasmota devices are a bunch of different version, I am not sure if that has something to do with it.

I’ll mark this solved with a note that it works for Tasmota lights.

My tasmota lights are still not working, as I said the retain was properly configured, in fact reverting back to 2022.2 fixes the problem. Upgrading to 2022.3 recreates the problem. Anyway good you fixed the problem, maybe eventually mine will be solved too if I get a reply in my issue :slight_smile:

I did see it’s gone to the developer - which is a good sign.

I wrote this bug report (before I saw the discussion here) Light on/off icon changes to switch on restart ¡ Issue #11943 ¡ home-assistant/frontend ¡ GitHub

I think there were some changes in Tasmota and/or HA.

The solution that worked for me was to replace
state_topic: "stat/tasmota/POWER"
with

    state_topic: "tele/tasmota/STATE"  
    state_value_template: "{{ value_json.POWER }}"

Hi,
I fixed the problem with this command sequence in the console of each affected device:

SwitchRetain off
ButtonRetain on
ButtonRetain off
PowerRetain on
PowerOnState 3

Finally,
If you use the device as a door sensor:
SwitchRetain on

In all other cases
SwitchRetain off

You can also watch the following video:
Fix Random Switching in Tasmota by Adjusting Retain Settings

In addition, you have to set retain: false in configuration yaml file