Get current Sonoff switch state after HASS restart

How should I configure MQTT switch so it would get the current Sonoff state after HASS restart? Currently all switches get an off state and I have to manually turn them on one by one.

My current config is (I’ve set the PowerRetain to On in Tasmota):

- platform: mqtt
  name: "Light Kitchen"
  state_topic: "stat/light_kitchen/POWER1"
  command_topic: "cmnd/light_kitchen/POWER1"
  availability_topic: "tele/light_kitchen/LWT"
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  payload_available: "Online"
  payload_not_available: "Offline"
  retain: true

Have you run the command “PowerRetain on” on your sonoff to have the sonoff retain the power state?

@Cezex - posted this yesterday myself - having the exact same issue. Linking to my thread in case others troubleshooting might need more info etc.

https://community.home-assistant.io/t/tasmota-pow-switch-status-in-hass-front-end-powerretain/46776

Thanks @vexter0944, will probably do similar automation until this issue will be resolved.

Which broker are you using? I believe the embedded broker does not handle the retain flag.

@gpbenton
I’m using the eclipse/mosquitto docker container - latest version - good idea, hadn’t considered that