This is what i’ve got and it works.
From what i understand, MQTT broker is a middle man, states are just passed from one end to another - no config as such for retaining power state on the broker.
My sonoffs were flashed with the below power retain flag, if you missed this…it can also be entered via sonoff console by entering the below command
PowerRetain 1
Switches.yaml or switch: is setup as below.
- platform: mqtt
name: "Switch"
command_topic: "cmnd/sonoff1/power"
state_topic: "stat/sonoff1/POWER"
availability_topic: "tele/sonoff1/LWT"
qos: 1
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
retain: true
FYI Im on hassio with a MQTT broker addon. Hope this helps…