@e1miran thanks for your brilliant solution. After i‘ve cleared out the saved mqtt command with an empty payload, the sonoff stays on if the previous state was ON and vice versa. As long as i‘m using MQTT or home assistant to toggle the sonoff it‘s working perfectly. But if i‘m pressing the button the value seems not to be saved and after a reconnection it toggles to the wrong state.
My workaround:
Set the buttontopic to a specific value (in my case ‚button5‘) and with a simple automation you could let home assistant toggle the sonoff.
Now it seems to work perfect. Thanks for your helpful answers! Love that community! <3