Generically, I have an appdaemon App with a single state variable.
Specifically, it’s “app.vacuum” and can be either “dirty” or “clean”. When the vacuum starts, it’s changed to “dirty” and when the vacuum is empty, “clean”.
My initialize(self): method calls self.get_state("app.vacuum") and if it returns None, sets the state to clean. I observe that on restart of HA, the state always reads as None even if there was a state set before. Thus, restarts cause the state to flip from “dirty” to “clean”.
Is there a better way to persist data in an app between restarts?
If anyone else stumbles upon this, there were two other things I didn’t realize at first that may save someone some trouble
The namespaces: bit in appdaemon.yaml needs to be indented under the appdaemon: bit, otherwise there will be errors that indicate the namespace doesn’t exist.
You need to restart appdaemon to pick up the namespace (this was actually obvious, but maybe not to everyone).
Just calling .set_namespace('userspace') means that you end up no longer being able to read and set states from home assistant, so you really need to flip back and forth.
One thing I still don’t know is if there is a dashboard or other place where I can see the current user namespace states, like I can by looking at home assistant’s “states” tab.
Hey @Gregable, you can use HADashboard’s Admin UI to view the different entities in any namespace (include default which is usually Home Assistant). The UI runs on port 5050 by default if you have it enabled in the config.
Additionally, if you use what is called “the new way” of developing AD apps, which means doing an import adbase and creating a class that inherits adbase.ADBase then you can work with entities across all namespaces in one place without having to constantly switch between namespaces.
You can also use the self.get_entity() method, specify a namespace once for that entity and work with it throughout your app without having to constantly specify the namespace.
Feel free to join our discord group and we’d be happy to help you work through any of this. Take care!