If it fails then it will restore off.
So the reason is that it’s not saved.
Do you get the saved to flash message in the log when you flip the switch?
According to the first post it’s a ESP32.
As far as I know you don’t need any extra configurations for ESP32.
But if the time is too high or the fingers are to itchy to reboot then it might not have been saved.
thats the switch that we use to indicate we are sleeping. It turn off all the lights and makes sure that the bathroom lights are minimum brightness so that if you to the loo in the middle of the night the light doesn’t wake you up.
I realize this is not an answer to the question but a workaround.
But whatever logic is toggling the switch could be coded in ESP-Home as a binary sensor.
Could you try an input text or input number and see of it saves the values?
Maybe there is something wrong with the switch