|
| 1 | +/** |
| 2 | + * Copyright 2016 SmartThings |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| 5 | + * in compliance with the License. You may obtain a copy of the License at: |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed |
| 10 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License |
| 11 | + * for the specific language governing permissions and limitations under the License. |
| 12 | + * |
| 13 | + */ |
| 14 | +import groovy.transform.Field |
| 15 | + |
| 16 | +@Field Boolean hasConfiguredHealthCheck = false |
| 17 | + |
| 18 | +metadata { |
| 19 | + definition (name: "ZLL White Color Temperature Bulb 5000K", namespace: "smartthings", author: "SmartThings") { |
| 20 | + |
| 21 | + capability "Actuator" |
| 22 | + capability "Color Temperature" |
| 23 | + capability "Configuration" |
| 24 | + capability "Polling" |
| 25 | + capability "Refresh" |
| 26 | + capability "Switch" |
| 27 | + capability "Switch Level" |
| 28 | + capability "Health Check" |
| 29 | + |
| 30 | + attribute "colorName", "string" |
| 31 | + command "setGenericName" |
| 32 | + |
| 33 | + fingerprint profileId: "C05E", deviceId: "0220", inClusters: "0000, 0004, 0003, 0006, 0008, 0005, 0300", outClusters: "0019", manufacturer: "Eaton", model: "Halo_LT01", deviceJoinName: "Halo RL56 Wireless" |
| 34 | + } |
| 35 | + |
| 36 | + // UI tile definitions |
| 37 | + tiles(scale: 2) { |
| 38 | + multiAttributeTile(name:"switch", type: "lighting", width: 6, height: 4, canChangeIcon: true){ |
| 39 | + tileAttribute ("device.switch", key: "PRIMARY_CONTROL") { |
| 40 | + attributeState "on", label:'${name}', action:"switch.off", icon:"st.switches.light.on", backgroundColor:"#00A0DC", nextState:"turningOff" |
| 41 | + attributeState "off", label:'${name}', action:"switch.on", icon:"st.switches.light.off", backgroundColor:"#ffffff", nextState:"turningOn" |
| 42 | + attributeState "turningOn", label:'${name}', action:"switch.off", icon:"st.switches.light.on", backgroundColor:"#00A0DC", nextState:"turningOff" |
| 43 | + attributeState "turningOff", label:'${name}', action:"switch.on", icon:"st.switches.light.off", backgroundColor:"#ffffff", nextState:"turningOn" |
| 44 | + } |
| 45 | + tileAttribute ("device.level", key: "SLIDER_CONTROL") { |
| 46 | + attributeState "level", action:"switch level.setLevel" |
| 47 | + } |
| 48 | + tileAttribute ("colorName", key: "SECONDARY_CONTROL") { |
| 49 | + attributeState "colorName", label:'${currentValue}' |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + standardTile("refresh", "device.refresh", inactiveLabel: false, decoration: "flat", width: 2, height: 2) { |
| 54 | + state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh" |
| 55 | + } |
| 56 | + |
| 57 | + controlTile("colorTempSliderControl", "device.colorTemperature", "slider", width: 4, height: 2, inactiveLabel: false, range:"(2700..5000)") { |
| 58 | + state "colorTemperature", action:"color temperature.setColorTemperature" |
| 59 | + } |
| 60 | + valueTile("colorTemp", "device.colorTemperature", inactiveLabel: false, decoration: "flat", width: 2, height: 2) { |
| 61 | + state "colorTemperature", label: '${currentValue} K' |
| 62 | + } |
| 63 | + |
| 64 | + main(["switch"]) |
| 65 | + details(["switch", "colorTempSliderControl", "colorTemp", "refresh"]) |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +// Parse incoming device messages to generate events |
| 70 | +def parse(String description) { |
| 71 | + log.debug "description is $description" |
| 72 | + def event = zigbee.getEvent(description) |
| 73 | + if (event) { |
| 74 | + if (event.name == "colorTemperature") { |
| 75 | + event.unit = "K" |
| 76 | + } |
| 77 | + sendEvent(event) |
| 78 | + } |
| 79 | + else { |
| 80 | + log.warn "DID NOT PARSE MESSAGE for description : $description" |
| 81 | + log.debug zigbee.parseDescriptionAsMap(description) |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +def off() { |
| 86 | + zigbee.off() + ["delay 1500"] + zigbee.onOffRefresh() |
| 87 | +} |
| 88 | + |
| 89 | +def on() { |
| 90 | + zigbee.on() + ["delay 1500"] + zigbee.onOffRefresh() |
| 91 | +} |
| 92 | + |
| 93 | +def setLevel(value) { |
| 94 | + zigbee.setLevel(value) + zigbee.onOffRefresh() + zigbee.levelRefresh() |
| 95 | +} |
| 96 | + |
| 97 | +def refresh() { |
| 98 | + def cmds = zigbee.onOffRefresh() + zigbee.levelRefresh() + zigbee.colorTemperatureRefresh() |
| 99 | + |
| 100 | + // Do NOT config if the device is the Eaton Halo_LT01, it responds with "switch:off" to onOffConfig, and maybe other weird things with the others |
| 101 | + if (!((device.getDataValue("manufacturer") == "Eaton") && (device.getDataValue("model") == "Halo_LT01"))) { |
| 102 | + cmds = cmds + zigbee.onOffConfig() + zigbee.levelConfig() + zigbee.colorTemperatureConfig() |
| 103 | + } |
| 104 | + |
| 105 | + cmds |
| 106 | +} |
| 107 | + |
| 108 | +def poll() { |
| 109 | + zigbee.onOffRefresh() + zigbee.levelRefresh() + zigbee.colorTemperatureRefresh() |
| 110 | +} |
| 111 | + |
| 112 | +/** |
| 113 | + * PING is used by Device-Watch in attempt to reach the Device |
| 114 | + * */ |
| 115 | +def ping() { |
| 116 | + return zigbee.levelRefresh() |
| 117 | +} |
| 118 | + |
| 119 | +def healthPoll() { |
| 120 | + log.debug "healthPoll()" |
| 121 | + def cmds = zigbee.onOffRefresh() + zigbee.levelRefresh() |
| 122 | + cmds.each{ sendHubCommand(new physicalgraph.device.HubAction(it))} |
| 123 | +} |
| 124 | + |
| 125 | +def configureHealthCheck() { |
| 126 | + Integer hcIntervalMinutes = 12 |
| 127 | + if (!hasConfiguredHealthCheck) { |
| 128 | + log.debug "Configuring Health Check, Reporting" |
| 129 | + unschedule("healthPoll") |
| 130 | + runEvery5Minutes("healthPoll") |
| 131 | + // Device-Watch allows 2 check-in misses from device |
| 132 | + sendEvent(name: "checkInterval", value: hcIntervalMinutes * 60, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID]) |
| 133 | + hasConfiguredHealthCheck = true |
| 134 | + } |
| 135 | +} |
| 136 | + |
| 137 | +def configure() { |
| 138 | + log.debug "configure()" |
| 139 | + configureHealthCheck() |
| 140 | + // Implementation note: for the Eaton Halo_LT01, it responds with "switch:off" to onOffConfig, so be sure this is before the call to onOffRefresh |
| 141 | + zigbee.onOffConfig() + zigbee.levelConfig() + zigbee.colorTemperatureConfig() + zigbee.onOffRefresh() + zigbee.levelRefresh() + zigbee.colorTemperatureRefresh() |
| 142 | +} |
| 143 | + |
| 144 | +def updated() { |
| 145 | + log.debug "updated()" |
| 146 | + configureHealthCheck() |
| 147 | +} |
| 148 | + |
| 149 | +def setColorTemperature(value) { |
| 150 | + setGenericName(value) |
| 151 | + zigbee.setColorTemperature(value) + ["delay 1500"] + zigbee.colorTemperatureRefresh() |
| 152 | +} |
| 153 | + |
| 154 | +//Naming based on the wiki article here: http://en.wikipedia.org/wiki/Color_temperature |
| 155 | +def setGenericName(value){ |
| 156 | + if (value != null) { |
| 157 | + def genericName = "" |
| 158 | + if (value < 3300) { |
| 159 | + genericName = "Soft White" |
| 160 | + } else if (value < 4150) { |
| 161 | + genericName = "Moonlight" |
| 162 | + } else if (value <= 5000) { |
| 163 | + genericName = "Cool White" |
| 164 | + } else { |
| 165 | + genericName = "Daylight" |
| 166 | + } |
| 167 | + sendEvent(name: "colorName", value: genericName, displayed: false) |
| 168 | + } |
| 169 | +} |
0 commit comments