OK let’s pick a stock device handler to play with, say Z-Wave Garage Door Opener
.
Firstly take a look at the definition()
method. That says …
definition (name: "Z-Wave Garage Door Opener", namespace: "smartthings", author: "SmartThings", runLocally: true, minHubCoreVersion: '000.017.0012', executeCommandsLocally: false, ocfDeviceType: "oic.d.garagedoor") {
You may, or may not, wish to change the name to make it easier to identify, and the namespace (usually your github username) and author so it is more obviously not stock. You do want to lose the local execution stuff though. So something like:
definition (name: "Modified Z-Wave Garage Door Opener", namespace: "whstrain", author: "whstrain", ocfDeviceType: "oic.d.garagedoor") {
To flip the attributes you need to change the values used in the events, and the particular attributes you will be interested are door
and/or contact
. You need to look for a sendEvent()
, a createEvent()
, or some map manipulation that is clearly working with name: "door"
(or name: "contact"
) and value: "open"
(or value: "closed"
).
The particular DTH I chose uses:
map.value = "closed"
result << createEvent(name: "contact", value: "closed", displayed: false)
and (in two places)
map.value = "open"
result << createEvent(name: "contact", value: "open", displayed: false)
In this handler the map.value
is being used to set the door
attribute of the Door Control capability (the createEvent
appears later in the code) with the Contact Sensor looking like a later addition, so there are two attributes you might want to consider changing (it also uses map.value = "opening"
and map.value = "closing"
).
Anyway the bottom line is that you can safely flip the values around to do what you want to do.
If you want to change a DTH from Open/Closed to Locked/Unlocked you need to add the Lock capability (capability "Lock"
) and whereever events are created with name: "contact"
(assuming the Contact Sensor capability), and value: "open"
or value: "closed"
you lose "lock"
, "locked"
and "unlocked"
instead. Alternatively you could add the capability rather than replace the old one and add additional code.