Custom integration's attributes to persist after restart/reload

Hi all,

New to Home Assistant so I might be asking the wrong question here but I’m wondering if there’s a way to create custom attributes from within my custom integration?

Context
I am building a custom integration to fetch some gas/electricity data from an external API and import it into HASS to be displayed within the Energy Dashboard. As part of my initialization of the sensors, I first fetch historic data and use the statistics API to import it (this seems to work fine) but the issue is that I need to keep track of a ‘sum’ value as my data comes in 30 minute chunks with the value of energy used in that 30 minutes (rather than the total used).

Therefore I need a way to persist the sum value as well as a Boolean value to ensure that the fetching of historic data doesn’t happen each time hass is restarted.

I tried using the RESTful api to add custom attributes to my entity but it doesn’t seem to work (the requests gets posted, but the custom attributes never show up?)

Any help would be appreciated,
Thanks in advance :slight_smile:

You would need to either store these in the integration config (bit hacky) or a file. I had a similar problem of being able to store some values and just created a json file in .storage to do it. Integration then reads and writes to this file.