From within a Smart App, you can store persistent data as “state.xxx”, and reuse it from one activation of the Smart App to the next.
I would like to do the same from within a custom Handler, recalling stored values from one activation of the Handler to the next.
But all my attempts using either state.xxx or settings.yyy have failed, each new activation of the Handller restarting from a null value.
Am I doing something wrong, or is it just plain impossible ?
You can declare a custom attribute and store arbitrary data there. You may have to convert your data to string (e.g. json) if you want to store structured data.
metadata {
definition (name: ..... ) {
attribute "myState", "string"
}
}
// Save state
sendEvent(name:"myState", value:"My persistent state", displayed:false)
// Read state
def state = device.currentValue("myState")
Now that I have found the persistent data, I have kind of the opposite problem : is there a way to detect from within a Handler that the Handler for the Device (the one owning state.xxx attributes) has just been updated ?
Something like a time stamp of the last Device’s handler update.
EDIT : found the solution !
the updated() function does also work from within Handlers, as well as in Smart Apps !