I am writing an app.
The device is accessible from the app code and I can execute device commands.
I've also been able to subscribe to events from the device.
What I cannot figure out how to do is access the "states" of a device as displayed in the device page.
currentValue() method on your device object, passing the name of the attribute you want:
Device Object | Hubitat Documentation
Regards attributes: I was looking at another persons device code and near the start of the file was this;
attribute "lastCommand", "string"
attribute "hoursRemaining", "number"
attribute "minutesRemaining", "number"
What is the purpose of these statements?
Presumably these are custom attributes made use of in the code for that driver. If you could post a link, we’d have a better idea of how they’re used in that driver.
I used the Hubitat Package Manager and found this: LGK SmartUPS Status
That is where the lines of code I posted came from.
LGK SmartUPS Status
I’m at work and don’t have access to my hubs, but those are obviously custom attributes used in that driver to keep track of how long an APC SmartUPS can power devices while powered by its battery.
These custom attributes are useful in that specific instance. Also, it is emphasized that they are custom, meaning that such attributes have to be defined within the driver, unlike standard attributes.
So the device code can set the value of each of these attributes and the app (or whatever) that is using the device can access the values with the currentValue method?