I would like to make a variable persistent. AppDaemon has the ability but it is unclear (to me) how to use it. I have add a namespace to appdaemon.yaml and restarted, according to this.
But now how do I use it? self.set_namespace("bplus_ns") self.somevar = 'value to persist' self.set_namespace("default")
does not work… Does somebody have a working example?
class HelloWorld(hass.Hass):
def initialize(self):
self.log("Hello from AppDaemon")
# set namespace
self.set_namespace("bplus_ns")
try:
# try to retrieve the variable from the namespace
self.test = self.get_state("text.test")
self.log("retrieved:")
self.log(self.test)
except:
self.test = int(1)
self.set_state("text.test", state=self.test)
self.log("created:")
self.log(self.test)
# multiply the saved value
state = self.test*2
# Save to namespace
self.set_state("text.test", state=state)
self.log(self.test)