How to save the state of a thermostat or pid controller in non-volatile memory esp8266?

To restore the temperature settings and the “on or off” state after power loss.

Temperature settings or value?

You really should not do this if it is something that changes often (like the temperature value) as you will quickly exceed the flash memory write endurance causing failure. If this is the case you should use an ESP32.

Anyway, here’s how to do it:

1 Like

if the main goal is to be able to restore data while the method must not be by storing into esp memory, then you can use NodeRed which is able to materialize selected viariables to storage

Components like  `light` ,  `switch` ,  `fan`  and  `globals`  can restore their state upon boot.

Or thermostat and pid controller can do it too?
I didn’t find any references in the documentation. And, to be honest, I don’t quite understand what exactly will be saved when using esp8266_restore_from_flash: true. (global parameter) And what can and should be disabled with the restore_mode option.
Oh! no, of course, not the current temperature value, but the setpoint

This seems to be the solution.Thanks!
But the question is about " what other components save state in flash?" relevant. For example, template_switch? I would not like to write unnecessary parameters in flash.

Thank You. No. The main goal is to make the thermostat or pid controller on esp 8266 as autonomous as possible, to be able to work without external interference, but not to reset to “default settings” after power loss"

Got it.
I have no any trv yet, but I would expect they return to last known settings after outage. I would be disappointed otherwise.

edit: do I understand correctly that those trvs loosing target temperature after power loss?
it’s not about HA itself?

Yes. Without using settings
esp8266_restore_from_flash: true
after power loss, the pid controller was turned on and the temperature setpoint was taken from the default_target_temperature
I couldn’t understand why trv settings can’t be stored in non-volatile memory. But it turned out that this is just a lack of documentation. The only thing that I would not like to write unnecessary parameters in flash, which you will not know about. But I hope this is resolved correctly.

So the global parameter enables this functionality but you still have to set some items you want to be restored. e.g. see the restore_mode for the gpio switch: GPIO Switch — ESPHome

For the climate component there is nothing to set. So I assume it saves all settings.

Yes. I understood. Thank you again.
I just thought that the description of the esp8266_restore_from_flash option lists all the components that work with it.
I also read about gpio switch. But the question remains relevant for other components. In the description of the option, there is a warning that you should not save, for example, temperature readings, but in the description of, for example, sensors, nothing is written about the modes of saving readings.
And climate components, of course, use sensors. And for pid auto-tuning, template switch is also used, and nothing is written about saving the States of this switch either. So it is not clear what states (and suddenly the temperature from the sensors, and the frequently changing calculated parameters of the pid are written in flash? I hope not, because obviously it would be superfluous). In General, the description is a bit ambiguous, so questions arise.