I have another slightly complex question that I’m currently struggling with.
I’m currently working on the control system for my 3-chamber sewage treatment plant, as the old control system has seen better days.
I’m faced with the problem that I have to write setpoints to the FLASH memory after changing them, as well as several timers.
For the setpoints, I use → preferences: flash_write_interval: 1 min
so that they are applied 10 seconds after the change.
However, to conserve memory, I would like to write the timers to the FLASH only every 24 hours, but as it stands, this is not possible because ESPHome does not allow you to set different intervals for writing to the FLASH.
Have you ever solved something like this or can you help me?
It’s likely not worth to spend too much effort to this, the system is quite sophisticated and I don’t remember any case here on this forum where someone destroyed the flash with default 1min interval.
If you have fwi one minute, esphome writes states to flash every one min (not after 10s) only if they have changed.
The timers are counted in minutes and must also be available in minutes. If these values are lost for one day, it is not a big deal, so I would like to write these values only every 24 hours and store them in RAM beforehand.
The setpoints values are already being saved, as I am working with → preferences: flash_write_interval: 10 sec.
However, I can’t get it to work so that when a timer expires after 1440 minutes (24 hours), the timer values are also written to the FLASH.
I could post my code, but I don’t think you want to read 1200 lines ^^
If you want, I can copy out the lines that I currently have and use.
Since the ESP can only handle about 100,000 FLASH write cycles and is usually done after that, I want to keep the write accesses as low as possible.
The setpoints are actually only changed a maximum of twice a year, so I’m not interested in these accesses, as there are only 10 variables.
When it expires, write your timer values to global variable which has
restore_value: yes .
This way It’s saved to flash every 1440minutes (if value has changed).
Cycles, not flash writes. One cycle is in range of 1000 component state changes …
Phew, that’s hard to describe, because if I knew the “outcome,” I might be able to fix the error
I can only describe what is not being done
The counters that store the operating time of the individual relays and save them in RAM are working (not included in my code snippet).
As long as the ESP is supplied with power, they count up.
To ensure that these values are stored, they should be written to the FLASH once a day so that in the event of a power failure, a maximum of 1 day’s worth of values is missing.
However, I don’t have any log output or anything else that would indicate an error, so I suspect that the code snippet is not being executed properly and/or that I have forgotten an essential part of the storage process or overlooked it in the ESP Home documentation.
100,000 cycles divided by 1440 minutes is how many years?
Best put battery backup on your counting device or write to a database over a network to conserve those counts. Oh wait, doesn’t HomeAssistant do that?