This addition was missed in the docs but has been added now. That being said, it is rare that you would need to do this in a real driver. Any attribute required by a capability the driver implements should always have a valid value, otherwise apps that depend on these values may behave unexpectedly. (Probably a good idea for custom attributes, too, but at least there are less likely to be conventions for those.)
For the other questions:
No, if you want to "set" or "update" the value of an attribute (i.e, something under "Current States" on the device detail page), you want to generate an event. The sendEvent()
method is a common way to do this.
To read the value of an attribute, you can use currentValue("attributeName")
(or equivalently the rarely-used currentState
method), or the automatically generated currentAttributeName
(where that is actually the name, e.g., currentSwitch
) property.
Valid values depend on the particular attribute, either as defined by the capability or your custom attribute if that is what you're using.
Note that all the methods discussed so far refer to attributes/events, not the state
object. I think this is what you mean, but some people do get confused with the similar names in the UI.
These are documented: Device Object | Hubitat Documentation. Specifically, look at the events()
method.
But note that the user can set a number-based event limit on a device (you cannot as a developer), and by default I think you'll have something like 10 or 11 of the most recent stored. If you care about a specific event, you may want to have your app track it itself.
There is probably a theoretical limit, though I don't think I've ever seen anything come up in practical terms. If you're concerned, however, a file is probably better. It's just a bit more work to use since state
is built-in and easy. The biggest issue with state
is that it is loaded/de-seralized and re-seralized every time the app (or driver) code wakes and sleeps, so it will take longer as it gets larger.
Dashboard attribute tiles are limited to 1024 characters, though they might work for simple data. If you have a way to generate the image in your app, you could serve it via an OAuth endpoint. You might want to see how previous attempts at this, including Hubigraphs, did this; or how webCoRE does it now (either webCoRE Dashboard or the parts of Hubigraphs I think it absorbed).
Alternatively, lots of people will use an external system do to this kind of thing instead, e.g., feeding data to a database via Maker API and something running on another device/server and using a graph/chart solution with that data instead. (Search for Grafana here as one example.) While it can work, I'm not sure Hubitat Dashboard with an on-hub app or device is the best way to do this, personally.