Custom Attributes

(Kelvin) #1

Does anyone have an example of the use of custom attributes in a DeviceHandler. I tried adding an attribute:
attribute “debugme”, “string” into the metadata which seems ok. But then later when I try to access this as:
device.debugme, I get an exception. Am I just fundamentally misunderstanding how / what an attribute is?
I was able to add it to “state” without an issue but that seems incorrect to me.

(Brian Steere) #2

Custom attributes are data bits the device provides. Examples: temperature, humidity. You would add custom attributes for any data bits that aren’t handled by any capabilities you may be using.

To access the attribute, you can use device.currentValue(‘attributeName’).

(Kelvin) #3

Thank you. Is there an example of setting the value of the attribute programmatically?

(swanny) #4

I’ve just done it by sending an event:

def newValue = "test"
sendEvent(name: “attributeName”, value: newValue)

I’m not sure if there is another way.