Persistent data HA standards?


I’m not sure whether this has been answered before, I tried to search but couldn’t find any guidelines…

I’m writing a python module and new/custom component for a sensor and will need to store some persistent data. I’m planning to use sqlite3 for data storage.

Are there established standards that suggest or dictate whether the persistent data storage should be handled by the HA component or the Python module?

I.e. should my design look like:

Option 1 - HA component creates and owns the local cache/storage

HA component  ---> python_module ---> API 

Option 2 - Python module creates and owns the local cache/storage

HA component  ---> python_module ---> API 


1 Like

It depends on what’s your definition of persistent data is.

I’m building a module to fetch street-by-street snow removal data from the City of Montreal’s APIs.

The city’s API only takes a timestamp in the request, and returns the status of ALL the streets that have been updated since that timestamp, and it’s throttled at 1 request/5 minutes

I’m looking to keep a persistent cache that saves:

  • the snow removal state of the desired streets
  • the timestamp the data was last pulled.

The python module I wrote currently caches the data in a sqlite DB.

Note: the reason I’m looking to keep persistent data is that the API only returns the streets that were changed since the last update. If my street’s data was not updated I won’t receive any data from the API, and the old cached info would still be valid.

Caching it by your module makes definitely sense in your case. Otherwise one could not use your module in their own scripts.


Thanks! Appreciate it.