Are you confusing the state’s with the attributes?
I use state .clear() in a number of my drivers just fine.
State is just a variable in the driver and the attributes are ‘states a device is currently in’ which are available to apps to query. Not sure if I confused things more with that explanation though.
No, I don't think I'm confused. I think there is some overlap. As far as I can tell the attributes are retrieved via getCurrentStates() with a class that is called "com.hubitat.hub.domain.State" even. Iterate over device.getCurrentStates() and check device.currentStates if you don't know what I mean.
A more correct way to say a state that is covered by a device capability is just to say attribute though. So, I will refer to them as built-in attributes to hopefully lessen any confusion going forward.
Ya. I think its just some bad naming. state.clear() though works on the state object which I think is just a map or list (or a special version of one of the two) which is separate from the attributes.
That's how I understand it though. If I'm wrong I'm sure one of the devs will chime in and I'll learn something new.
Ah, yeah, I just checked again because it's been a long time since I iterated "state" and you are right. No overlap here.
Okay, so my question is slightly different but since I already @mentioned Mike to come here I'll leave my question here.
To sum up, I would like a way to clear an attribute (or a state from getCurrentStates). The attributes won't show up until the first event and are then there forever. I would like to remove one without removing the device and re-adding so that device drivers that support multiple device types can code around showing attributes that don't really apply on the dashboard for examples.
Any chance that could change? Or is it more complicated than it seems to provide? I think the reason for the ask is at least valid, right?
It would allow a device driver to handle multiple device models potentially without messing up how they are viewed on dashboard. My biggest use case is a motion sensor that can have a battery or can be plugged in or a motion sensor driver that covers many motion sensors, some of which don't support batteries.
That's OK. From my standpoint the state.variables (correct term?) is all I care about. Sometime back I switched from one driver to another. The old driver left a bunch of state.variables on the device page which annoyed me (I think it's a personality disorder ) . I was able to remove them using the above method.
Hence my original question: Is it possible to create an driver like the "Basic Z-Wave Tool" to wipe out the current state values for the reason I stated above?
Thanks for the explanation on the two "state" types.
I don't think I'm asking for fully dynamic capabilities though it would be nice. I want to remove an attribute value which I guess means I want to delete the event.
it would appear that simply calling currentState.remove() removes all current states / (attributes) and then they will repopulate as and when they are sent as new events... enjoy