Disable save state on flash
Disable save power state
SetOption0 0
Save flash write count. since state save on MQTT server, we not need write to flash.
SetOption0
Save power state and use after restart (=SaveState)
0 = disable (see note below)
1 = enable (default)
https://tasmota.github.io/docs/Commands/#setoptions
Set power on state
PowerOnState 0
Default power on state, since state is not save on flash.
PowerOnState
Control relay state after powering up the device.
0 / OFF = keep relay(s) OFF after power up
1 / ON = turn relay(s) ON after power up
2 / TOGGLE = toggle relay(s) from last saved state
3 = switch relay(s) to their last saved state (default)
4 = turn relay(s) ON and disable further relay control
5 = after a PulseTime period turn relay(s) ON (acts as inverted PulseTime mode)
https://tasmota.github.io/docs/PowerOnState/
Tasmota rule for save state on MQTT
State Rule
Rule1
ON Power1#state=0 DO publish2 cmnd/%topic%/POWER1 OFF ENDON
ON Power1#state=1 DO publish2 cmnd/%topic%/POWER1 ON ENDON
ON Power2#state=0 DO publish2 cmnd/%topic%/POWER2 OFF ENDON
ON Power2#state=1 DO publish2 cmnd/%topic%/POWER2 ON ENDON
ON Power3#state=0 DO publish2 cmnd/%topic%/POWER3 OFF ENDON
ON Power3#state=1 DO publish2 cmnd/%topic%/POWER3 ON ENDON
Rule1 1
Echo current power state to MQTT with lastwill(save last message).
Use publish2 to publish MQTT command with lastwill.
Disable/Enable rule on system start up
Rule2
ON System#Init DO Rule1 0 ENDON
ON System#Boot DO Rule1 1 ENDON
Rule2 1
Disable rule1 on system init. so when system still start up, it will not send MQTT command with incorrect state.
Enable rule1 after system done start and already received MQTT command back.
System#Init
occurs once after restart before Wi-Fi and MQTT are initialized
System#Boot
occurs once after Tasmota is fully initialized, triggers after Wi-Fi and MQTT (if enabled) are connected.
https://tasmota.github.io/docs/Rules/#examples-of-available-triggers