Def installed() is not being executed, not sure why

I'm trying to put together a driver of a Zigbee device that has two outputs. It will also have an BME280 sensor as an input which is disabled for ease in getting the outputs controlled.

My current issue is the "def installed()" function does not run. At least the debug statement isn't the logs.

I assumed installed would be triggered by changing the device to the built in "device" then changing it back. Perhaps this is not the case.

FWIW this device works with the built in "Generic Zigbee Multi endpoint switch" driver.

I thought is would be pretty cut and dry but apparently not, at least not in my case.

I'm sure there are many errors in my code but unless I can get the child devices created I think I'm stuck.

Any suggestions?
Thanks
John

/*
 *  2020-02-04 Close, ON/OFF control LED#2, cannot control LED#0  (using board reference numbers)
 *
 */

metadata {
  definition(name: "ZigBee Multi Switch", namespace: "smartthings", author: "SmartThings", ocfDeviceType: "oic.d.switch", mnmn: "SmartThings", vid: "generic-switch") {
    capability "Actuator"
    capability "Configuration"
    capability "Refresh"
    //capability "Health Check"
    capability "Switch"

    command "childOn", ["string"]
    command "childOff", ["string"]

    fingerprint profileId: "0104", inClusters: "0006", outClusters: "0006", model: "pvtoGPIO2", deviceJoinName: "GPIOLED"
  }
}// --- metadata ---



def parse(String description) {
  Map eventMap = zigbee.getEvent(description)
  Map eventDescMap = zigbee.parseDescriptionAsMap(description)

  if (eventMap) {
    if (eventDescMap && eventDescMap?.attrId == "0000") {//0x0000 : OnOff attributeId
      if (eventDescMap?.sourceEndpoint == "01" || eventDescMap?.endpoint == "01") {
        sendEvent(eventMap)
      } else {
        def childDevice = childDevices.find {
          it.deviceNetworkId == "$device.deviceNetworkId:${eventDescMap.sourceEndpoint}" || it.deviceNetworkId == "$device.deviceNetworkId:${eventDescMap.endpoint}"
        }
        if (childDevice) {
          childDevice.sendEvent(eventMap)
        } else {S
          log.debug "Child device: $device.deviceNetworkId:${eventDescMap.sourceEndpoint} was not found"
        }
      }
    }
  }
}  // --- pares ---


def installed() {
  log.debug " 48 about to create childDevices"
  createChildDevices()
  updateDataValue("onOff", "catchall")
  refresh()
}


def updated() {
  log.debug "updated()"
  updateDataValue("onOff", "catchall")
  for (child in childDevices) {
    if (!child.deviceNetworkId.startsWith(device.deviceNetworkId) || //parent DNI has changed after rejoin
        !child.deviceNetworkId.split(':')[-1].startsWith('0')) {
      child.setDeviceNetworkId("${device.deviceNetworkId}:0${getChildEndpoint(child.deviceNetworkId)}")
    }
  }
  refresh()
}


private void createChildDevices() {
  if (!childDevices) {
    def x = getChildCount()
    log.debug " 65 x=4{x}"
    for (i in 2..x) {
      addChildDevice("Child Switch Health", "${device.deviceNetworkId}:0${i}", device.hubId,
        [completedSetup: true, label: "${device.displayName[0..-2]}${i}", isComponent: false])
    }
  }
}

private getChildEndpoint(String dni) {
  dni.split(":")[-1] as Integer
}

def on() {
  log.debug("on")
  zigbee.on()
}

def off() {
  log.debug("off")
  zigbee.off()
}

def childOn(String dni) {
  log.debug(" child on ${dni}")
  def childEndpoint = getChildEndpoint(dni)
  zigbee.command(zigbee.ON_OFF_CLUSTER, 0x01, "", [destEndpoint: childEndpoint])
}

def childOff(String dni) {
  log.debug(" child off ${dni}")
  def childEndpoint = getChildEndpoint(dni)
  zigbee.command(zigbee.ON_OFF_CLUSTER, 0x00, "", [destEndpoint: childEndpoint])
}

/**
 * PING is used by Device-Watch in attempt to reach the Device
 * */
def ping() {
  return refresh()
}

def refresh() {
/*  if (isOrvibo()) {
    zigbee.readAttribute(zigbee.ONOFF_CLUSTER, 0x0000, [destEndpoint: 0xFF])
  } else {  */
    def cmds = zigbee.onOffRefresh()
    def x = getChildCount()
    for (i in 2..x) {
      cmds += zigbee.readAttribute(zigbee.ON_OFF_CLUSTER, 0x0000, [destEndpoint: i])
    }
    return cmds
  }


def poll() {
  refresh()
}

def healthPoll() {
  log.debug "healthPoll()"
  def cmds = refresh()
  cmds.each { sendHubCommand(new hubitat.device.HubAction(it)) }
}

def configureHealthCheck() {
  Integer hcIntervalMinutes = 12
  if (!state.hasConfiguredHealthCheck) {
    log.debug "Configuring Health Check, Reporting"
    unschedule("healthPoll")
    runEvery5Minutes("healthPoll")
    def healthEvent = [name: "checkInterval", value: hcIntervalMinutes * 60, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID]]
    // Device-Watch allows 2 check-in misses from device
    sendEvent(healthEvent)
    childDevices.each {
      it.sendEvent(healthEvent)
    }
    state.hasConfiguredHealthCheck = true
  }
}

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

 /* if (isOrvibo()) {

       //the orvibo switch will send out device announce message at every 2 mins as heart beat,setting 0x0099 to 1 will disable it.
    def cmds = zigbee.writeAttribute(zigbee.BASIC_CLUSTER, 0x0099, 0x20, 0x01, [mfgCode: 0x0000])
    cmds += refresh()
    return cmds
  } else {  */
    //other devices supported by this DTH in the future
    def cmds = zigbee.onOffConfig(0, 120)
    def x = getChildCount()
    for (i in 2..x) {
      cmds += zigbee.configureReporting(zigbee.ON_OFF_CLUSTER, 0x0000, 0x10, 0, 120, null, [destEndpoint: i])
    }
    cmds += refresh()
    return cmds
  }


//private Boolean isOrvibo() { device.getDataValue("manufacturer") == "ORVIBO" }

private getChildCount() {
    return 2
  }

Installed only once when the device is initially created, it does not run when drivers are changed, there is no event for that.

For testing you can obviously add to the driver as a custom command then run it from the ui.

1 Like