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:
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 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)
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).
In practice it shouldn’t matter a lot if you use a sane interval for writing to flash.
Also reports of (massively) dying flash chips on esp82xx’s are still not a thing… actually I didn’t yet heard of one case