Possible to display flash write count with web component?

I started out with Tasmota, but esphome is quickly growing on me for a number of reasons.

With Tasmota - if I ask for “information” on the default web ui I get information that includes

Program Version	10.0.0(tasmota)
Build Date & Time	2021-10-19T08:23:49
Core/SDK Version	2_7_4_9/2.2.2-dev(38a443e)
Uptime	7T00:30:31
Flash write Count	2757 at 0xF7000
Boot Count	75
Restart Reason	Power On

The flash write count is of particular interest to me.

I can see that you can set some parameters to control the frequency of flash writes, there doesn’t seem to be a way to expose the number of writes?

Ideally - I would be able to use the web_server and text_sensor to display the current “Flash Write Count”

For my curiosity, what’s the reason for that count and what is it actually counting?

Flash memory has a write count limit.

I’ve seen various bits of lore that says these consumer flash devices can support 10,000 writes - other numbers I’ve seen are higher (and lower). The lack of true science around this may be why esphome isn’t exposing the value because it isn’t linear.

I believe the reason is that it really depends on how you are managing the storage. Each individual ‘block’ of flash can only be written so many times, but if some sort of wear leveling is used you can spread the wear around and thus achieve more total writes.

I’ve certainly noted when I’ve taken a brand new device and flashed some firmware, that I can see that my write count is in the single digits. With my ‘in production’ tasmota devices - after serveral years, I was a little surprised to see the flash count as high as it was (2757 as per my data capture above). Of course, the firmware is remember the ‘state’ of the lightswitch - so that if the power goes off - it will resume the state. Useful maybe - but worth two writes per day? (my lights go on/off once a night)

Of course - if you have a slow enough update frequency - and the flash memory supports enough writes (and wear leveling happens) – you might be good for more than a lifetime persistence - How far is it safe to regularly write to the ESP32 flash, considering the flash MTBF? - Stack Overflow

It’s still interesting to be able to see the value … even if I’ll never run out.

First it should be clear what that value represents.
While it’s common estimation that flash life is something between 10K-100K+ cycles, it means entire flash writes. How it’s implemented, while you update one variable or few, has to be understood.
AFAIK esphome doesn’t have component for counting flash writes, but they do output on logs…

Hmm… maybe I can just watch logs for this - less satisfying.

I think the core request I have here is to be able to replicate some of what Tasmota provide by default, in esphome. It feels like a gap - but we can claim that flash writes are a meaningless measure.

To count flash writes you would have to store the count in flash, otherwise it won’t survive a reboot. So you could potentially double the number of writes by trying to count it. And you would still have to decide if you wanted to count value writes, page writes, page erases or whatever.

How does Tasmota do this?

I should take a device that has esphome on it, and flip it back to tasmota and see if it show me the (updated) write count…

Oh… and look at that the tasmota code does appear to do exactly that?

The logic for managing this is here Tasmota/tasmota/tasmota_support/settings.ino at ab9ad562cb9a6cb7476cd9fa349e68492906bd91 · arendst/Tasmota · GitHub

So yeah - it sort of looks like an artificial count? Odd – I thought that when flashing over serial to the SP devices you got a flash count… there is probably more to unwind here, but I think my curiosity is sufficiently satisfied at this point.

1 Like