Esphome template switch restore state not working

I have two template switches with the following configuration.

 - platform: template
   name: "Activate Click"
   id: activateclick
   restore_state: true
   optimistic: yes
 - platform: template
   name: "Full Screen"
   optimistic: yes
   id: fullscreen
   restore_state: yes   

I want them to restore the state after restarting. It was working fine till yesterday but now it is not restoring its state. What could be the problem. I am using Esp01s modules with this.

I have the same problem - did you find a solution? I’ll do a working around defining a number where the last switch state is stored, if no solutiom is possible

I couldn’t find a solution so i shifted to tasmota where the option to restore state worked.

You don’t have a turn_on or turn_off action defined. Therefore the state can not be restored.

I found the solution: Restore_state doesn’t work, even with turn_off /turn_on action. Waht works is “restore_mode: RESTORE_DEFAULT_OFF” - which is same with the GPIO-switches

Thanks for reporting back. I was wondering that, and even checked the template switch documentation before replying. I’ll submit a documentation edit.

perfect, thank you! That will help others a lot

Did you use restore_state: at all?

I’m wondering if it needs both, restore_state and restore_mode.

yes it needs both. without restore_state: true it doesn’t work, I just tested it

Ah damn. I had better remove my edit then.

I’m running in to this issue also.

Now restore_state is removed from template switch so all I can use is restore_mode and that does not do the job.

switch:
  - platform: template
    name: "Person sensor on/off"
    id: person_on_off
    optimistic: true
    restore_mode: RESTORE_DEFAULT_ON 

I need a boolean toggle that keeps the value past a reboot.
Switch Component — ESPHome
RESTORE_DEFAULT_ON - Attempt to restore state and default to ON.

I get that it might not be able to restore, but in that case it should be on, but after unplugging the ESP and plugging it back in the switch is off.