Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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