Sonoff retained messages on startup alternative - Solution

I have just being working to get the optimum solution for my Sonoff setup (10 S20s and a 2 POW r2). After getting MQTT discovery working (a real life saver) I was frustrated that the stat/sonoff-example/RESULT = {“POWER1”:“OFF”} message was not retained and was what being used in discovery as the state message.

Retained messages always seemed a bit of a hack to me so was looking for an alternate method. My first reaction was to send a blank power message to each device (which would return the RESULT message) at startup. This works but was not scalable as it defeated the point of discovery. After a good nights sleep remembered the group message for the Sonoff (in my case sonoffs). So a message mqtt publish -h -t “cmnd/sonoffs/power” - m “” at startup will get a response from all sonoffs. Problem solved

  • id: ‘1540504583324’
    alias: Retrieve Sonoff state
    • event: start
      platform: homeassistant
      condition: []
    • data:
      payload: ‘’
      topic: cmnd/sonoffs/power
      service: mqtt.publish

Yep. Check the Tasmota Wiki under the Home Assistant section they have this same type of script that runs at startup and does up to the 4th relay. I also use the Powerretain feature in Tasmota to cover all the bases.