Yagusmart 4 button Scene Switch

Hi Marcus,

Thanks for your advice.
Yes, I cut and pasted that driver and it doesn't work. (sorry for the formatting below).
I also added a push(button) function because the documentation says a capability of PushableButton needs a push(button) function to call. So not sure how the original can work without one, but still my version below doesn't work. I am confident that if this device works with a Tuya hub it can be made to work with Hubitat.

Hubitat's Button Implementation

I wonder if I have to "subscribe" to the button presses to be able to hear them? None of the below code does a subscribe either! So really confused.

I feel like I am missing a crucial piece of "how to code and debug new zigbee device drivers". Why for example does the documentation specify both a push(button) function and a subscribe(deviceList, "pushed", buttonHandler) function are required yet none of the drivers that work implement such a function, or even a pushed() function?

/**

  • Copyright 2019 G.Brown (MorkOz)
  • Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  • in compliance with the License. You may obtain a copy of the License at:
  •  http://www.apache.org/licenses/LICENSE-2.0
    
  • Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
  • on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
  • for the specific language governing permissions and limitations under the License.
  • Adapted and modified from code written by at9, motley74, sticks18 and AnotherUser
  • Original sources:
  • https://github.com/at-9/hubitat/blob/master/Drivers/at-9-Zemismart-3-Gang-Sticker-Switch
  • SmartThingsPublic/osram-lightify-dimming-switch.groovy at master · motley74/SmartThingsPublic · GitHub
  • SmartThingsPublic-1/osram-lightify-4x-switch.groovy at master · AnotherUser17/SmartThingsPublic-1 · GitHub
  • Message Map: '[raw:catchall: 0000 8021 00 00 0040 00 5360 00 00 0000 00 00 C500, profileId:0000, clusterId:8021, clusterInt:32801, sourceEndpoint:00, destinationEndpoint:00, options:0040, messageType:00, dni:5360, isClusterSpecific:false, isManufacturerSpecific:false, manufacturerId:0000, command:00, direction:00, data:[C5, 00]]'
  • Message Map: '[raw:catchall: 0104 0001 01 01 0040 00 5360 00 00 0000 07 01 00, profileId:0104, clusterId:0001, clusterInt:1, sourceEndpoint:01, destinationEndpoint:01, options:0040, messageType:00, dni:5360, isClusterSpecific:false, isManufacturerSpecific:false, manufacturerId:0000, command:07, direction:01, data:[00]]'
  • Version Author Note
  • 0.1 G.Brown (MorkOz) Initial release

*/
import hubitat.zigbee.zcl.DataType

metadata {
definition (name: "4 Scene Switch Zigbee", namespace: "brando", author: "M.Brando") {
capability "Actuator"
capability "PushableButton"
capability "HoldableButton"
capability "DoubleTapableButton"
capability "Configuration"
capability "Refresh"
capability "Sensor"

    fingerprint inClusters: "0000,0001,0006", outClusters: "0019", manufacturer: "_TYZB02_key8kk7r", model: "TS0041"
    fingerprint inClusters: "0000,0001,0006", outClusters: "0019", manufacturer: "_TYZB02_key8kk7r", model: "TS0042"
    fingerprint inClusters: "0000,0001,0006", outClusters: "0019", manufacturer: "_TYZB02_key8kk7r", model: "TS0043"		
    fingerprint inClusters: "0000,0001,0003,0004,0006,1000", outClusters: "0019,000A,0003,0004,0005,0006,0008,1000", manufacturer: "_TZ3000_xabckq1v", model: "TS004F"
}

preferences {
    input name: "debugEnable", type: "bool", title: "Enable debug logging", defaultValue: true
}

}

private sendButtonNumber() {
log.debug("sendButtonNumber()")
def remoteModel = device.getDataValue("model")
log.debug("remoteModel '$remoteModel'")
switch(remoteModel){
case "TS0041":
sendEvent(name: "numberOfButtons", value: 1, isStateChange: true)
break
case "TS0042":
sendEvent(name: "numberOfButtons", value: 2, isStateChange: true)
break
case "TS0043":
sendEvent(name: "numberOfButtons", value: 3, isStateChange: true)
break
case "TS004F":
sendEvent(name: "numberOfButtons", value: 4, isStateChange: true)
break
}
}

def installed() {
log.debug("installed()")
sendButtonNumber
state.start = now()
}

def updated() {
log.debug("updated()")
sendButtonNumber
}

def refresh() {
log.debug("refresh()")
// read battery level attributes
return zigbee.readAttribute(0x0001, 0x0020) + zigbee.configureReporting(0x0001, 0x0020, 0x20, 3600, 21600, 0x01)
// this device doesn't support 0021
zigbee.readAttribute(0x0001, 0x0021)
}

def configure() {
log.debug("configure()")
sendButtonNumber

def configCmds = []

for (int endpoint=1; endpoint<=3; endpoint++) {
def list = ["0006", "0001", "0000"]
// the config to the switch
for (cluster in list) {
configCmds.add("zdo bind 0x${device.deviceNetworkId} 0x0${endpoint} 0x01 0x${cluster} {${device.zigbeeId}} {}")
}
}
return configCmds
}

def push(button)
{
log.debug "Button Pushed: ${button}"
}

def hold(button)
{
log.debug "Button Held: ${button}"
}

def doubleTap(button)
{
log.debug "Button Double Tapped: ${button}"
}

def parse(String description)
{
log.debug("parse(): '$description'")

if ((description?.startsWith("catchall:")) || (description?.startsWith("read attr -"))) 
{
    def parsedMap = zigbee.parseDescriptionAsMap(description)
    if (debugEnable)
    {
        log.debug("Message Map: '$parsedMap'")
    }
    switch(parsedMap.sourceEndpoint) 
    {
    case "04": 
        button = "1"
        break
    case "03": 
        button = "3"
        break
    case "02": 
        button = "4"
        break
    case "01": 
        button = "2"
        break
    }
    switch(parsedMap.data) 
    {
    case "[00]": 
        eventName = "pushed" 
        break
    case "[01]": 
        eventName = "doubleTapped" 
        break
    case "[02]": 
        eventName = "held" 
        break
    }
    sendEvent(name: eventName, value: button, descriptionText: "Button $button was $name", isStateChange:true)
}
return

}