Skip to content

Instantly share code, notes, and snippets.

@nayelyzarazua-bluetrail
Created December 14, 2020 21:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nayelyzarazua-bluetrail/5570a0782c7b349c5921c725a81ce23b to your computer and use it in GitHub Desktop.
iconAlternativesChange
//definition
{
"id": "xxxx.customlock",
"version": 1,
"status": "proposed",
"name": "customlock",
"attributes": {
"lockstate": {
"schema": {
"type": "object",
"properties": {
"value": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"value"
]
},
"setter": "setLockstate",
"enumCommands": []
}
},
"commands": {
"setLockstate": {
"name": "setLockstate",
"arguments": [
{
"name": "value",
"optional": false,
"schema": {
"type": "string"
}
}
]
}
}
}
//presentation
{
"dashboard": {
"states": [
{
"label": "{{lockstate.value}}",
"alternatives": [
{
"key": "disarmed",
"value": "Disarmed",
"type": "active"
},
{
"key": "armed",
"value": "Armed",
"type": "inactive"
}
]
}
],
"actions": [],
"basicPlus": []
},
"detailView": [
{
"label": "Security State",
"displayType": "state",
"state": {
"label": "{{lockstate.value}}",
"alternatives": [
{
"key": "disarmed",
"value": "Disarmed",
"type": "active"
},
{
"key": "armed",
"value": "Armed",
"type": "inactive"
}
]
}
}
],
"id": "xxxx.customlock",
"version": 1
}
/**
* DTH to show the icon change according to the alternatives
*/
metadata {
definition (name: "iconAlternativeChange", author:"nayely",ocfDeviceType:"oic.d.smartlock", deviceTypeId: "SmartLock", vid:"bc7b9b6c-1a3c-3408-87e1-fddf61ce8d01", mnmn: "SmartThingsCommunity") {
capability "xxxx.customlock"
capability "lock"
}
simulator {}
tiles {}
}
def installed() {
log.trace "Executing 'installed'"
initialize()
}
def updated() {
log.trace "Executing 'updated'"
}
def lock(){
sendEvent(name: "lock", value: "locked")
sendEvent(name: "lockstate", value: "armed")
}
def unlock(){
sendEvent(name: "lock", value: "unlocked")
sendEvent(name: "lockstate", value: "disarmed")
}
private initialize() {
log.trace "Executing 'initialize'"
sendEvent(name: "lock", value: "unlocked")
sendEvent(name: "lockstate", value: "disarmed")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment