I have a custom DTH that worked perfect under the old app but now needs updated for the new app. I’m a hobbyist, not a developer so I haven’t been able to figure this out on my own doing research. I’m hoping someone can help fix this existing DTH.
metadata {
definition (name: "Centralite Dimmer", namespace: "", author: "") {
capability "Button"
capability "Switch"
capability "Switch Level"
fingerprint profileId: "0104", deviceId: "0101", inClusters: "0000, 0003, 0004, 0005, 0006, 0008", manufacturer: "CentraLite Systems", model: "Dimmer Switch", deviceJoinName: "WorksWith Dimmer"
}
tiles(scale: 2) {
multiAttributeTile(name:"switch", type: "lighting", width: 6, height: 4, canChangeIcon: true){
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
attributeState "on", label:'${name}', action:"switch.off", icon:"st.switches.light.on", backgroundColor:"#79b821", nextState:"turningOff"
attributeState "off", label:'${name}', action:"switch.on", icon:"st.switches.light.off", backgroundColor:"#ffffff", nextState:"turningOn"
attributeState "turningOn", label:'${name}', action:"switch.off", icon:"st.switches.light.on", backgroundColor:"#79b821", nextState:"turningOff"
attributeState "turningOff", label:'${name}', action:"switch.on", icon:"st.switches.light.off", backgroundColor:"#ffffff", nextState:"turningOn"
}
tileAttribute ("device.level", key: "SLIDER_CONTROL") {
attributeState "level", action:"switch level.setLevel"
}
}
standardTile("refresh", "device.refresh", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
state "default", label:"", action:"switch.refresh", icon:"st.secondary.refresh"
}
main "switch"
details(["switch", "refresh"])
}
}
// Parse incoming device messages to generate events
def parse(String description) {
Map map = [:]
log.debug "description is $description"
def event = zigbee.getEvent(description)
if (description?.startsWith('catchall:')) {
// call parseCatchAllMessage to parse the catchall message received
map = parseCatchAllMessage(description)
if (map.value == "pushed") {
List cmds = onoffResponse()
def result = []
log.trace "Sending current state to device ${cmds}"
result = cmds?.collect { new physicalgraph.device.HubAction(it) }
return result
}
}
if (event) {
log.info event
if (event.name == "level") {
event.value = (event.value as Integer) * 100 / 39 //update level to overcome return of 39 as max from switch
sendEvent(event)
}
else {
sendEvent(event)
}
}
else {
log.warn "DID NOT PARSE MESSAGE for description : $description"
log.debug zigbee.parseDescriptionAsMap(description)
}
}
def onoffResponse() {
log.debug "Creating on/off response"
def swtch = device.currentState("switch")?.value // Get the current on off value
if (swtch == "on"){
swtch = "0"
}else{
swtch = "1"
}
[
"st cmd 0x${device.deviceNetworkId} 0x${device.endpointId} 6 ${swtch} {}" // Set On or Off
]
}
def off() {
zigbee.off()
}
def on() {
zigbee.on()
}
def setLevel(value) {
zigbee.setLevel(value*39/100)
}
def refresh() {
zigbee.onOffRefresh() + zigbee.levelRefresh() + zigbee.onOffConfig() + zigbee.levelConfig()
}
def configure() {
log.debug "Configuring Reporting and Bindings."
zigbee.onOffConfig() + zigbee.levelConfig() + zigbee.onOffRefresh() + zigbee.levelRefresh()
}
private Map parseCatchAllMessage(String description) {
// Create a map from the raw zigbee message to make parsing more intuitive
def msg = zigbee.parse(description)
Map result = [:]
switch(msg.clusterId) {
case 6:
switch(msg.command) {
case 2: // button pressed
result = [
name: 'button',
value: 'pushed',
data: [buttonNumber: 1],
descriptionText: "$device.displayName button was pressed",
isStateChange: true
]
log.debug "Parse returned ${result?.descriptionText}"
return result
break
}
}
result = [value: 'nothing']
}