Compare commits

...

1 Commits

Author SHA1 Message Date
재희
5ca4419f54 MSA-986: 버튼/이온 LED 전구 2016-03-23 02:38:51 -05:00
2 changed files with 259 additions and 259 deletions

View File

@@ -1,254 +1,254 @@
/** /**
* Copyright 2015 SmartThings * Copyright 2015 SmartThings
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * 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: * in compliance with the License. You may obtain a copy of the License at:
* *
* http://www.apache.org/licenses/LICENSE-2.0 * 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 * 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 * 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. * for the specific language governing permissions and limitations under the License.
* *
* Aeon RGBW LED Bulb * Aeon RGBW LED Bulb
* *
* Author: SmartThings * Author: SmartThings
* Date: 2015-7-12 * Date: 2015-7-12
*/ */
metadata { metadata {
definition (name: "Aeon LED Bulb", namespace: "smartthings", author: "SmartThings") { definition (name: "Aeon LED Bulb", namespace: "smartthings", author: "SmartThings") {
capability "Switch Level" capability "Switch Level"
capability "Color Control" capability "Color Control"
capability "Color Temperature" capability "Color Temperature"
capability "Switch" capability "Switch"
capability "Refresh" capability "Refresh"
capability "Actuator" capability "Actuator"
capability "Sensor" capability "Sensor"
command "reset" command "reset"
fingerprint inClusters: "0x26,0x33,0x98" fingerprint inClusters: "0x26,0x33,0x98"
fingerprint deviceId: "0x11", inClusters: "0x98,0x33" fingerprint deviceId: "0x11", inClusters: "0x98,0x33"
fingerprint deviceId: "0x1102", inClusters: "0x98" fingerprint deviceId: "0x1102", inClusters: "0x98"
} }
simulator { simulator {
} }
standardTile("switch", "device.switch", width: 1, height: 1, canChangeIcon: true) { standardTile("switch", "device.switch", width: 1, height: 1, canChangeIcon: true) {
state "on", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff" state "on", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff"
state "off", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn" state "off", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn"
state "turningOn", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff" state "turningOn", label:'${name}', action:"switch.off", icon:"st.lights.philips.hue-single", backgroundColor:"#79b821", nextState:"turningOff"
state "turningOff", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn" state "turningOff", label:'${name}', action:"switch.on", icon:"st.lights.philips.hue-single", backgroundColor:"#ffffff", nextState:"turningOn"
} }
standardTile("reset", "device.reset", inactiveLabel: false, decoration: "flat") { standardTile("reset", "device.reset", inactiveLabel: false, decoration: "flat") {
state "default", label:"Reset Color", action:"reset", icon:"st.lights.philips.hue-single" state "default", label:"Reset Color", action:"reset", icon:"st.lights.philips.hue-single"
} }
standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat") { standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat") {
state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh" state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh"
} }
controlTile("levelSliderControl", "device.level", "slider", height: 1, width: 2, inactiveLabel: false, range:"(0..100)") { controlTile("levelSliderControl", "device.level", "slider", height: 1, width: 2, inactiveLabel: false, range:"(0..100)") {
state "level", action:"switch level.setLevel" state "level", action:"switch level.setLevel"
} }
controlTile("rgbSelector", "device.color", "color", height: 3, width: 3, inactiveLabel: false) { controlTile("rgbSelector", "device.color", "color", height: 3, width: 3, inactiveLabel: false) {
state "color", action:"setColor" state "color", action:"setColor"
} }
valueTile("level", "device.level", inactiveLabel: false, decoration: "flat") { valueTile("level", "device.level", inactiveLabel: false, decoration: "flat") {
state "level", label: 'Level ${currentValue}%' state "level", label: 'Level ${currentValue}%'
} }
controlTile("colorTempControl", "device.colorTemperature", "slider", height: 1, width: 2, inactiveLabel: false) { controlTile("colorTempControl", "device.colorTemperature", "slider", height: 1, width: 2, inactiveLabel: false) {
state "colorTemperature", action:"setColorTemperature" state "colorTemperature", action:"setColorTemperature"
} }
valueTile("hue", "device.hue", inactiveLabel: false, decoration: "flat") { valueTile("hue", "device.hue", inactiveLabel: false, decoration: "flat") {
state "hue", label: 'Hue ${currentValue} ' state "hue", label: 'Hue ${currentValue} '
} }
main(["switch"]) main(["switch"])
details(["switch", "levelSliderControl", "rgbSelector", "reset", "colorTempControl", "refresh"]) details(["switch", "levelSliderControl", "rgbSelector", "reset", "colorTempControl", "refresh"])
} }
def updated() { def updated() {
response(refresh()) response(refresh())
} }
def parse(description) { def parse(description) {
def result = null def result = null
if (description.startsWith("Err 106")) { if (description.startsWith("Err 106")) {
state.sec = 0 state.sec = 0
} else if (description != "updated") { } else if (description != "updated") {
def cmd = zwave.parse(description, [0x20: 1, 0x26: 3, 0x70: 1, 0x33:3]) def cmd = zwave.parse(description, [0x20: 1, 0x26: 3, 0x70: 1, 0x33:3])
if (cmd) { if (cmd) {
result = zwaveEvent(cmd) result = zwaveEvent(cmd)
log.debug("'$description' parsed to $result") log.debug("'$description' parsed to $result")
} else { } else {
log.debug("Couldn't zwave.parse '$description'") log.debug("Couldn't zwave.parse '$description'")
} }
} }
result result
} }
def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd) { def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd) {
dimmerEvents(cmd) dimmerEvents(cmd)
} }
def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd) { def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd) {
dimmerEvents(cmd) dimmerEvents(cmd)
} }
def zwaveEvent(physicalgraph.zwave.commands.switchmultilevelv3.SwitchMultilevelReport cmd) { def zwaveEvent(physicalgraph.zwave.commands.switchmultilevelv3.SwitchMultilevelReport cmd) {
dimmerEvents(cmd) dimmerEvents(cmd)
} }
private dimmerEvents(physicalgraph.zwave.Command cmd) { private dimmerEvents(physicalgraph.zwave.Command cmd) {
def value = (cmd.value ? "on" : "off") def value = (cmd.value ? "on" : "off")
def result = [createEvent(name: "switch", value: value, descriptionText: "$device.displayName was turned $value")] def result = [createEvent(name: "switch", value: value, descriptionText: "$device.displayName was turned $value")]
if (cmd.value) { if (cmd.value) {
result << createEvent(name: "level", value: cmd.value, unit: "%") result << createEvent(name: "level", value: cmd.value, unit: "%")
} }
return result return result
} }
def zwaveEvent(physicalgraph.zwave.commands.hailv1.Hail cmd) { def zwaveEvent(physicalgraph.zwave.commands.hailv1.Hail cmd) {
response(command(zwave.switchMultilevelV1.switchMultilevelGet())) response(command(zwave.switchMultilevelV1.switchMultilevelGet()))
} }
def zwaveEvent(physicalgraph.zwave.commands.securityv1.SecurityMessageEncapsulation cmd) { def zwaveEvent(physicalgraph.zwave.commands.securityv1.SecurityMessageEncapsulation cmd) {
def encapsulatedCommand = cmd.encapsulatedCommand([0x20: 1, 0x84: 1]) def encapsulatedCommand = cmd.encapsulatedCommand([0x20: 1, 0x84: 1])
if (encapsulatedCommand) { if (encapsulatedCommand) {
state.sec = 1 state.sec = 1
def result = zwaveEvent(encapsulatedCommand) def result = zwaveEvent(encapsulatedCommand)
result = result.collect { result = result.collect {
if (it instanceof physicalgraph.device.HubAction && !it.toString().startsWith("9881")) { if (it instanceof physicalgraph.device.HubAction && !it.toString().startsWith("9881")) {
response(cmd.CMD + "00" + it.toString()) response(cmd.CMD + "00" + it.toString())
} else { } else {
it it
} }
} }
result result
} }
} }
def zwaveEvent(physicalgraph.zwave.Command cmd) { def zwaveEvent(physicalgraph.zwave.Command cmd) {
def linkText = device.label ?: device.name def linkText = device.label ?: device.name
[linkText: linkText, descriptionText: "$linkText: $cmd", displayed: false] [linkText: linkText, descriptionText: "$linkText: $cmd", displayed: false]
} }
def on() { def on() {
command(zwave.basicV1.basicSet(value: 0xFF)) command(zwave.basicV1.basicSet(value: 0xFF))
} }
def off() { def off() {
command(zwave.basicV1.basicSet(value: 0x00)) command(zwave.basicV1.basicSet(value: 0x00))
} }
def setLevel(level) { def setLevel(level) {
setLevel(level, 1) setLevel(level, 1)
} }
def setLevel(level, duration) { def setLevel(level, duration) {
if(level > 99) level = 99 if(level > 99) level = 99
command(zwave.switchMultilevelV3.switchMultilevelSet(value: level, dimmingDuration: duration)) command(zwave.switchMultilevelV3.switchMultilevelSet(value: level, dimmingDuration: duration))
} }
def refresh() { def refresh() {
commands([ commands([
zwave.switchMultilevelV1.switchMultilevelGet(), zwave.switchMultilevelV1.switchMultilevelGet(),
], 1000) ], 1000)
} }
def setSaturation(percent) { def setSaturation(percent) {
log.debug "setSaturation($percent)" log.debug "setSaturation($percent)"
setColor(saturation: percent) setColor(saturation: percent)
} }
def setHue(value) { def setHue(value) {
log.debug "setHue($value)" log.debug "setHue($value)"
setColor(hue: value) setColor(hue: value)
} }
def setColor(value) { def setColor(value) {
def result = [] def result = []
log.debug "setColor: ${value}" log.debug "setColor: ${value}"
if (value.hex) { if (value.hex) {
def c = value.hex.findAll(/[0-9a-fA-F]{2}/).collect { Integer.parseInt(it, 16) } def c = value.hex.findAll(/[0-9a-fA-F]{2}/).collect { Integer.parseInt(it, 16) }
result << zwave.switchColorV3.switchColorSet(red:c[0], green:c[1], blue:c[2], warmWhite:0, coldWhite:0) result << zwave.switchColorV3.switchColorSet(red:c[0], green:c[1], blue:c[2], warmWhite:0, coldWhite:0)
} else { } else {
def hue = value.hue ?: device.currentValue("hue") def hue = value.hue ?: device.currentValue("hue")
def saturation = value.saturation ?: device.currentValue("saturation") def saturation = value.saturation ?: device.currentValue("saturation")
if(hue == null) hue = 13 if(hue == null) hue = 13
if(saturation == null) saturation = 13 if(saturation == null) saturation = 13
def rgb = huesatToRGB(hue, saturation) def rgb = huesatToRGB(hue, saturation)
result << zwave.switchColorV3.switchColorSet(red: rgb[0], green: rgb[1], blue: rgb[2], warmWhite:0, coldWhite:0) result << zwave.switchColorV3.switchColorSet(red: rgb[0], green: rgb[1], blue: rgb[2], warmWhite:0, coldWhite:0)
} }
if(value.hue) sendEvent(name: "hue", value: value.hue) if(value.hue) sendEvent(name: "hue", value: value.hue)
if(value.hex) sendEvent(name: "color", value: value.hex) if(value.hex) sendEvent(name: "color", value: value.hex)
if(value.switch) sendEvent(name: "switch", value: value.switch) if(value.switch) sendEvent(name: "switch", value: value.switch)
if(value.saturation) sendEvent(name: "saturation", value: value.saturation) if(value.saturation) sendEvent(name: "saturation", value: value.saturation)
commands(result) commands(result)
} }
def setColorTemperature(percent) { def setColorTemperature(percent) {
if(percent > 99) percent = 99 if(percent > 99) percent = 99
int warmValue = percent * 255 / 99 int warmValue = percent * 255 / 99
command(zwave.switchColorV3.switchColorSet(red:0, green:0, blue:0, warmWhite:warmValue, coldWhite:(255 - warmValue))) command(zwave.switchColorV3.switchColorSet(red:0, green:0, blue:0, warmWhite:warmValue, coldWhite:(255 - warmValue)))
} }
def reset() { def reset() {
log.debug "reset()" log.debug "reset()"
sendEvent(name: "color", value: "#ffffff") sendEvent(name: "color", value: "#ffffff")
setColorTemperature(99) setColorTemperature(99)
} }
private command(physicalgraph.zwave.Command cmd) { private command(physicalgraph.zwave.Command cmd) {
if (state.sec != 0) { if (state.sec != 0) {
zwave.securityV1.securityMessageEncapsulation().encapsulate(cmd).format() zwave.securityV1.securityMessageEncapsulation().encapsulate(cmd).format()
} else { } else {
cmd.format() cmd.format()
} }
} }
private commands(commands, delay=200) { private commands(commands, delay=200) {
delayBetween(commands.collect{ command(it) }, delay) delayBetween(commands.collect{ command(it) }, delay)
} }
def rgbToHSV(red, green, blue) { def rgbToHSV(red, green, blue) {
float r = red / 255f float r = red / 255f
float g = green / 255f float g = green / 255f
float b = blue / 255f float b = blue / 255f
float max = [r, g, b].max() float max = [r, g, b].max()
float delta = max - [r, g, b].min() float delta = max - [r, g, b].min()
def hue = 13 def hue = 13
def saturation = 0 def saturation = 0
if (max && delta) { if (max && delta) {
saturation = 100 * delta / max saturation = 100 * delta / max
if (r == max) { if (r == max) {
hue = ((g - b) / delta) * 100 / 6 hue = ((g - b) / delta) * 100 / 6
} else if (g == max) { } else if (g == max) {
hue = (2 + (b - r) / delta) * 100 / 6 hue = (2 + (b - r) / delta) * 100 / 6
} else { } else {
hue = (4 + (r - g) / delta) * 100 / 6 hue = (4 + (r - g) / delta) * 100 / 6
} }
} }
[hue: hue, saturation: saturation, value: max * 100] [hue: hue, saturation: saturation, value: max * 100]
} }
def huesatToRGB(float hue, float sat) { def huesatToRGB(float hue, float sat) {
while(hue >= 100) hue -= 100 while(hue >= 100) hue -= 100
int h = (int)(hue / 100 * 6) int h = (int)(hue / 100 * 6)
float f = hue / 100 * 6 - h float f = hue / 100 * 6 - h
int p = Math.round(255 * (1 - (sat / 100))) int p = Math.round(255 * (1 - (sat / 100)))
int q = Math.round(255 * (1 - (sat / 100) * f)) int q = Math.round(255 * (1 - (sat / 100) * f))
int t = Math.round(255 * (1 - (sat / 100) * (1 - f))) int t = Math.round(255 * (1 - (sat / 100) * (1 - f)))
switch (h) { switch (h) {
case 0: return [255, t, p] case 0: return [255, t, p]
case 1: return [q, 255, p] case 1: return [q, 255, p]
case 2: return [p, 255, t] case 2: return [p, 255, t]
case 3: return [p, q, 255] case 3: return [p, q, 255]
case 4: return [t, p, 255] case 4: return [t, p, 255]
case 5: return [255, p, q] case 5: return [255, p, q]
} }
} }

View File

@@ -1,4 +1,6 @@
/** private hideOptionsSection() {
(starting || ending || days || modes) ? false : true
}/**
* Copyright 2015 SmartThings * Copyright 2015 SmartThings
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
@@ -313,10 +315,8 @@ private hhmm(time, fmt = "h:mm a")
f.format(t) f.format(t)
} }
private hideOptionsSection() {
(starting || ending || days || modes) ? false : true
}
private timeIntervalLabel() { private timeIntervalLabel() {
(starting && ending) ? hhmm(starting) + "-" + hhmm(ending, "h:mm a z") : "" (starting && ending) ? hhmm(starting) + "-" + hhmm(ending, "h:mm a z") : ""
} }