Can you tell me how you got it working without the startup script. Tasmota doesnt allow retain for state so that’s why you have to send the command with an empty payload. It then sends the current state.
I have not looked at persistence, can it be set on the built in broker?
I have been doing some testing, the sonoffs running tasmota are sending stat messages with the retain flag (powerretain 1) set but they are not being retained over a restart of home assistant so when the automation fires at startup, there is no stat message in the broker and if the sonoff hasn’t connected in time it doesn’t get the command.
Update: fixed by adding
qos: 1
to the end of the automation action, this ensures that the command is delivered when the sonoff connects.
If you are using the embedded broker, the retain flag has no effect as it does not support it. To use the retain flag, you need to use an external broker, such as mosquitto.
Retain does have an effect, if I connect to the built in broker with an mqtt client, I can confirm I see retained messages. They are not there after a restart of the broker though, maybe they are with the external broker. I believe this is called persistence though, it’s not to do with retain.
I don’t use retain in home assistant as I just want it to to follow what my switches are doing.
I suspect my original issue occured as my sonoffs are taking longer to connect with the new 0.80 version and are connecting after home assistant has started and the automation to check switch status has already run.
I resolved it by adding QoS to the automation to ensure they get the command even if they connect later. It has been running without it without issue until now. I hadn’t realised it was in the wiki.