Purchased an IKEA tunable white bulb packaged with a 5 button switch. Have paired both with the ST hub. Got the bulb to work very easily, couldn’t find a DH for the button though. Figured this was my cue to wade into programming for ST. Did some reading, muddled through the documentation and community posts. “Borrowed” a4refillpad code for the Xiaomi Zigbee Button to try and view the messages sent to the hub.
Here is the code I’m using
/**
*/
metadata {
definition (name: “Tradfri Button Test”, namespace: “jamiethegoalie”, author: “jamiethegoalie”) {
capability “Battery”
capability “Button”
capability “Holdable Button”
capability “Actuator”
capability “Switch”
capability “Momentary”
capability “Configuration”
capability “Sensor”
capability “Refresh”
attribute "lastPress", "string"
attribute "batterylevel", "string"
attribute "lastCheckin", "string"
fingerprint profileId: “0104”, deviceId: “0810”, inClusters: “0000, 0001, 0003, 0009, 0B05, 1000”, outClusters: “0003, 0004, 0005, 0006, 0008, 0019, 1000”, manufacturer: “IKEA of Sweden”, model: “lumi.sensor_switch”, deviceJoinName: “”
}
tiles(scale: 2) {
multiAttributeTile(name:"switch", type: "lighting", width: 6, height: 4, canChangeIcon: true) {
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
attributeState("on", label:' push', action: "momentary.push", backgroundColor:"#53a7c0")
attributeState("off", label:' push', action: "momentary.push", backgroundColor:"#ffffff", nextState: "on")
}
tileAttribute("device.lastCheckin", key: "SECONDARY_CONTROL") {
attributeState("default", label:'Last Update: ${currentValue}',icon: "st.Health & Wellness.health9")
}
}
valueTile("battery", "device.battery", decoration: "flat", inactiveLabel: false, width: 2, height: 2) {
state "battery", label:'${currentValue}% battery', unit:""
}
standardTile("refresh", "device.refresh", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
state "default", action:"refresh.refresh", icon:"st.secondary.refresh"
}
standardTile("configure", "device.configure", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
state "configure", label:'', action:"configuration.configure", icon:"st.secondary.configure"
}
main (["switch"])
details(["switch", "battery", "refresh", "configure"])
}
}
def parse(String description) {
log.debug “Parsing ‘${description}’”
// send event for heartbeat
def now = new Date().format(“yyyy MMM dd EEE h:mm:ss a”, location.timeZone)
sendEvent(name: “lastCheckin”, value: now)
def results =
// if (description?.startsWith('on/off: '))
// results = parseCustomMessage(description)
if (description?.startsWith(‘catchall:’))
results = parseCatchAllMessage(description)
return results;
}
def configure(){
log.debug “Configuring Reporting and Bindings.”
// return zigbee.configureReporting(0x0006, 0x0000, 0x10, 0, 600, null) +
// zigbee.configureReporting(0x0008, 0x0000, 0x20, 1, 3600, 0x01) +
// zigbee.readAttribute(0x0006, 0x0000) +
// zigbee.readAttribute(0x0008, 0x0000)
zigbee.configureReporting(0x0000, 0x0000, 0x10, 0, 600, null)
//zigbee.configureReporting(0x0006, 0x0000, 0x10, 0, 600, null)
}
def refresh(){
log.debug “refreshing”
}
private Map parseCatchAllMessage(String description) {
Map resultMap = [:]
def cluster = zigbee.parse(description)
log.debug cluster
if (cluster) {
switch(cluster.clusterId) {
case 0x0000:
resultMap = getBatteryResult(cluster.data.last())
break
case 0xFC02:
log.debug 'ACCELERATION'
break
case 0x0402:
log.debug 'TEMP'
// temp is last 2 data values. reverse to swap endian
String temp = cluster.data[-2..-1].reverse().collect { cluster.hex1(it) }.join()
def value = getTemperature(temp)
resultMap = getTemperatureResult(value)
break
}
}
return resultMap
}
Here is part of the log:
3644a338-036c-4800-ab0b-064c231481d8 9:50:01 PM: debug SmartShield(clusterId: 0x8021, command: 0x00, data: [0x11, 0x00], destinationEndpoint: 0x00, direction: 0x00, isClusterSpecific: false, isManufacturerSpecific: false, manufacturerId: 0x0000, messageType: 0x00, number: null, options: 0x0040, profileId: 0x0000, senderShortId: 0x85ae, sourceEndpoint: 0x00, text: null)
3644a338-036c-4800-ab0b-064c231481d8 9:50:01 PM: debug Parsing ‘catchall: 0000 8021 00 00 0040 00 85AE 00 00 0000 00 00 1100’
3644a338-036c-4800-ab0b-064c231481d8 9:49:54 PM: debug Configuring Reporting and Bindings
Pushing the button doesn’t initially send anything to the log. After I press the configure button in the app the next time I press a button on the switch log entries show up.
I’m looking for some guidance on setting up the bindings so I can view the button press messages.
Sorry for the long post. I couldn’t figure out how the scrollable window for code worked.