ES8266, howto restore a value from HA

How can i restore a value from home assistant after a reboot or reprogramming.

i would like to build a counter, but after a reboot the last know value should be reloaded from HA.
I could store it in flash, but there are a lot writes, so the flash would wear out fast.

You can feed home assistant sensors into esphome with the respecting platforms available, for example:

Question is who is counting? Sounds like the counter is in HA and esphome just increments it? Or not, because then you wouldn’t need to “import” a value from ha… Maybe you just show us your yaml?

You don’t need to write every increase of the counter to flash. The amount of writes written to flash can be limited - the docs explain how it works:

Counting is done in the esp, the total valur is sended tot ha.

So easier than trying to get the last value back from ha for further processing in esphome is for sure just save it to flash then… you have all links :point_up_2: It should also make the whole setup more robust (no need for a network connection to get the last value for example).

The other way I could think of would just to have the counter directly in HA and only send the call from the esphome node to increase the counter (esphome then isn’t aware what state the counter have but that shouldn’t be of any importance) :bulb:

1 Like

Imho, that is asking for troubles…what if HA ain’t available when tour esp reboots??

I think it is better to use ESPHome’s


so it will retrieve the value from its own memory on reboot….

But in that case i beter could use an esp32 to prefent a defect flash memory

In theory a esp32 can last longer than a esp8266 saving things to flash (esp32 has “write to flash” on by default the esp8266 needs the setting esp8266_restore_from_flash set to true). :writing_hand:

In practice it shouldn’t matter a lot if you use a sane interval for writing to flash. :raised_hands:

Also reports of (massively) dying flash chips on esp82xx’s are still not a thing… actually I didn’t yet heard of one case :thinking: