How do I save persistent values between runs of a python_script?

I’ve got a python script which would really benefit from knowing some info from previous runs of the script, so I would like to be able to save/restore state values somewhere.

My guess is that this is done in one of three ways:

  1. Define entities (which aren’t associated with any device) and manipulate them with hass.states, maybe? I’ve seen an integration which adds support for variables, but is there nothing like this already built into HA?
  2. Maybe there’s some API for each script to have it’s own persistent key-value store associated with it’s script name?
  3. As a last option, maybe we can save values (via pickle?) to a local file, but I’m loathe to start saving things into a common file-system location.

What’s the accepted way of preserving state across python_script executions?

1 Like

Did you ever got an answer to this?