Restore from mqtt on boot

i tried to search for this but failed

basicly i’m building a rain gauge and i want to recover the total rain count and monthly rain count on boot so that it does not start over after a reboot

ideal i wanted to use some form of flash to store it, and i think that would last many years as flash write would only be needed when it rains, during dry time nothing would change so a write would not be needed

my code so far: esphome: name: vejrstation platform: ESP8266 board: nodemcuv2 esp826 - Pastebin.com

any ideas?

here
Description of how it works.

yeah, but i’m not sure if that would include the rain gauge part of my code

and its only the rain gauge part that has to survive powercycle(powerloss)

Would it be an option to just send a signal whenever a specific amount water passed and leave the interpretation to homeassistant?

at the house and winter/fall has begun with the big storms

but yeah, letting HA keep score with the rain could also be an option, its a no rush project as i also need to figure a way to provide power to the weather station outside

and since its 500 meters from the coast i also need to consider salt in the air and what nasty stuff that can do to electronics