mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-09 13:21:53 +00:00
Compare commits
20 Commits
MSA-2022-1
...
MSA-2033-2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
30eafb604d | ||
|
|
0b81793b0f | ||
|
|
16f41bddae | ||
|
|
117adea586 | ||
|
|
783538e36d | ||
|
|
320c8918f8 | ||
|
|
0f3656cd12 | ||
|
|
6110aaa0fa | ||
|
|
c391ce4b43 | ||
|
|
073bac8dac | ||
|
|
3c83bfb53b | ||
|
|
6325101f52 | ||
|
|
945a972082 | ||
|
|
b65acdb91f | ||
|
|
4067e6e7e2 | ||
|
|
4c6d1eddb2 | ||
|
|
10d2097ebe | ||
|
|
d3728d95b2 | ||
|
|
b645872d8f | ||
|
|
74a35eeddb |
@@ -26,7 +26,9 @@ metadata {
|
||||
capability "Polling"
|
||||
capability "Refresh"
|
||||
capability "Health Check"
|
||||
fingerprint manufacturer: "015D", prod: "0221", model: "251C"
|
||||
|
||||
fingerprint manufacturer: "015D", prod: "0221", model: "251C", deviceJoinName: "Show Home 2-Channel Smart Plug"
|
||||
fingerprint manufacturer: "0312", prod: "B221", model: "251C", deviceJoinName: "Inovelli 2-Channel Smart Plug"
|
||||
}
|
||||
simulator {}
|
||||
preferences {}
|
||||
|
||||
@@ -22,8 +22,6 @@ metadata {
|
||||
capability "Battery"
|
||||
capability "Health Check"
|
||||
|
||||
command "configureAfterSecure"
|
||||
|
||||
fingerprint deviceId: "0x0701", inClusters: "0x5E,0x86,0x72,0x59,0x85,0x73,0x71,0x84,0x80,0x30,0x31,0x70,0x98,0x7A", outClusters:"0x5A"
|
||||
fingerprint mfr:"0086", prod:"0102", model:"004A", deviceJoinName: "Aeon Labs MultiSensor (Gen 5)"
|
||||
}
|
||||
@@ -91,12 +89,12 @@ metadata {
|
||||
valueTile("battery", "device.battery", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
|
||||
state "battery", label:'${currentValue}% battery', unit:""
|
||||
}
|
||||
standardTile("configureAfterSecure", "device.configure", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
|
||||
state "configure", label:'', action:"configureAfterSecure", icon:"st.secondary.configure"
|
||||
standardTile("configure", "device.configure", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
|
||||
state "configure", label:'', action:"configure", icon:"st.secondary.configure"
|
||||
}
|
||||
|
||||
main(["motion", "temperature", "humidity", "illuminance"])
|
||||
details(["motion", "temperature", "humidity", "illuminance", "battery", "configureAfterSecure"])
|
||||
details(["motion", "temperature", "humidity", "illuminance", "battery", "configure"])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,8 +129,8 @@ def zwaveEvent(physicalgraph.zwave.commands.wakeupv1.WakeUpNotification cmd)
|
||||
|
||||
if (!isConfigured()) {
|
||||
// we're still in the process of configuring a newly joined device
|
||||
log.debug("not sending wakeUpNoMoreInformation yet")
|
||||
result += response(configureAfterSecure())
|
||||
log.debug("not sending wakeUpNoMoreInformation yet: late configure")
|
||||
result += response(configure())
|
||||
} else {
|
||||
result += response(zwave.wakeUpV1.wakeUpNoMoreInformation())
|
||||
}
|
||||
@@ -150,11 +148,6 @@ def zwaveEvent(physicalgraph.zwave.commands.securityv1.SecurityMessageEncapsulat
|
||||
}
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.securityv1.SecurityCommandsSupportedReport cmd) {
|
||||
// log.debug "Received SecurityCommandsSupportedReport"
|
||||
response(configureAfterSecure())
|
||||
}
|
||||
|
||||
def zwaveEvent(physicalgraph.zwave.commands.batteryv1.BatteryReport cmd) {
|
||||
def map = [ name: "battery", unit: "%" ]
|
||||
if (cmd.batteryLevel == 0xFF) {
|
||||
@@ -226,36 +219,6 @@ def zwaveEvent(physicalgraph.zwave.Command cmd) {
|
||||
createEvent(descriptionText: cmd.toString(), isStateChange: false)
|
||||
}
|
||||
|
||||
def configureAfterSecure() {
|
||||
// log.debug "configureAfterSecure()"
|
||||
|
||||
def request = [
|
||||
// send temperature, humidity, and illuminance every 8 minutes
|
||||
zwave.configurationV1.configurationSet(parameterNumber: 101, size: 4, scaledConfigurationValue: 128|64|32),
|
||||
zwave.configurationV1.configurationSet(parameterNumber: 111, size: 4, scaledConfigurationValue: 8*60),
|
||||
|
||||
// send battery every 20 hours
|
||||
zwave.configurationV1.configurationSet(parameterNumber: 102, size: 4, scaledConfigurationValue: 1),
|
||||
zwave.configurationV1.configurationSet(parameterNumber: 112, size: 4, scaledConfigurationValue: 20*60*60),
|
||||
|
||||
// send no-motion report 60 seconds after motion stops
|
||||
zwave.configurationV1.configurationSet(parameterNumber: 3, size: 2, scaledConfigurationValue: 60),
|
||||
|
||||
// send binary sensor report instead of basic set for motion
|
||||
zwave.configurationV1.configurationSet(parameterNumber: 5, size: 1, scaledConfigurationValue: 2),
|
||||
|
||||
// disable notification-style motion events
|
||||
zwave.notificationV3.notificationSet(notificationType: 7, notificationStatus: 0),
|
||||
|
||||
zwave.batteryV1.batteryGet(),
|
||||
zwave.sensorBinaryV2.sensorBinaryGet(sensorType:0x0C)
|
||||
]
|
||||
|
||||
setConfigured()
|
||||
|
||||
secureSequence(request) + ["delay 20000", zwave.wakeUpV1.wakeUpNoMoreInformation().format()]
|
||||
}
|
||||
|
||||
/**
|
||||
* PING is used by Device-Watch in attempt to reach the Device
|
||||
* */
|
||||
@@ -265,7 +228,36 @@ def ping() {
|
||||
|
||||
def configure() {
|
||||
// log.debug "configure()"
|
||||
//["delay 30000"] + secure(zwave.securityV1.securityCommandsSupportedGet())
|
||||
def request = []
|
||||
// send temperature, humidity, and illuminance every 8 minutes
|
||||
request << zwave.configurationV1.configurationSet(parameterNumber: 101, size: 4, scaledConfigurationValue: 128|64|32)
|
||||
request << zwave.configurationV1.configurationSet(parameterNumber: 111, size: 4, scaledConfigurationValue: 8*60)
|
||||
|
||||
// send battery every 20 hours
|
||||
request << zwave.configurationV1.configurationSet(parameterNumber: 102, size: 4, scaledConfigurationValue: 1)
|
||||
request << zwave.configurationV1.configurationSet(parameterNumber: 112, size: 4, scaledConfigurationValue: 20*60*60)
|
||||
|
||||
// send no-motion report 60 seconds after motion stops
|
||||
request << zwave.configurationV1.configurationSet(parameterNumber: 3, size: 2, scaledConfigurationValue: 60)
|
||||
|
||||
// send binary sensor report instead of basic set for motion
|
||||
request << zwave.configurationV1.configurationSet(parameterNumber: 5, size: 1, scaledConfigurationValue: 2)
|
||||
|
||||
// Turn on the Multisensor Gen5 PIR sensor
|
||||
request << zwave.configurationV1.configurationSet(parameterNumber: 4, size: 1, scaledConfigurationValue: 1)
|
||||
|
||||
// disable notification-style motion events
|
||||
request << zwave.notificationV3.notificationSet(notificationType: 7, notificationStatus: 0)
|
||||
|
||||
request << zwave.batteryV1.batteryGet()
|
||||
request << zwave.sensorBinaryV2.sensorBinaryGet(sensorType: 0x0C) //motion
|
||||
request << zwave.sensorMultilevelV5.sensorMultilevelGet(sensorType: 0x01) //temperature
|
||||
request << zwave.sensorMultilevelV5.sensorMultilevelGet(sensorType: 0x03) //illuminance
|
||||
request << zwave.sensorMultilevelV5.sensorMultilevelGet(sensorType: 0x05) //humidity
|
||||
|
||||
setConfigured()
|
||||
|
||||
secureSequence(request) + ["delay 20000", zwave.wakeUpV1.wakeUpNoMoreInformation().format()]
|
||||
}
|
||||
|
||||
private setConfigured() {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//DEPRECATED. INTEGRATION MOVED TO SUPER LAN CONNECT
|
||||
|
||||
/**
|
||||
* Bose SoundTouch
|
||||
*
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//DEPRECATED. INTEGRATION MOVED TO SUPER LAN CONNECT
|
||||
|
||||
/**
|
||||
* Hue Bloom
|
||||
*
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//DEPRECATED. INTEGRATION MOVED TO SUPER LAN CONNECT
|
||||
|
||||
/**
|
||||
* Hue Bridge
|
||||
*
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//DEPRECATED. INTEGRATION MOVED TO SUPER LAN CONNECT
|
||||
|
||||
/**
|
||||
* Hue Bulb
|
||||
*
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//DEPRECATED. INTEGRATION MOVED TO SUPER LAN CONNECT
|
||||
|
||||
/**
|
||||
* Hue Lux Bulb
|
||||
*
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//DEPRECATED. INTEGRATION MOVED TO SUPER LAN CONNECT
|
||||
|
||||
/**
|
||||
* Hue White Ambiance Bulb
|
||||
*
|
||||
|
||||
@@ -49,6 +49,6 @@ def arrived() {
|
||||
|
||||
|
||||
def departed() {
|
||||
log.trace "Executing 'arrived'"
|
||||
log.trace "Executing 'departed'"
|
||||
sendEvent(name: "presence", value: "not present")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//DEPRECATED. INTEGRATION MOVED TO SUPER LAN CONNECT
|
||||
|
||||
/**
|
||||
* Copyright 2015 SmartThings
|
||||
*
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//DEPRECATED. INTEGRATION MOVED TO SUPER LAN CONNECT
|
||||
|
||||
/**
|
||||
* Copyright 2015 SmartThings
|
||||
*
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//DEPRECATED. INTEGRATION MOVED TO SUPER LAN CONNECT
|
||||
|
||||
/**
|
||||
* Copyright 2015 SmartThings
|
||||
*
|
||||
|
||||
@@ -66,22 +66,29 @@ def parse(String description) {
|
||||
else {
|
||||
sendEvent(event)
|
||||
}
|
||||
}
|
||||
else {
|
||||
def cluster = zigbee.parse(description)
|
||||
|
||||
if (cluster && cluster.clusterId == 0x0006 && cluster.command == 0x07) {
|
||||
if (cluster.data[0] == 0x00) {
|
||||
} else {
|
||||
def descMap = zigbee.parseDescriptionAsMap(description)
|
||||
if (descMap && descMap.clusterInt == 0x0006 && descMap.commandInt == 0x07) {
|
||||
if (descMap.data[0] == "00") {
|
||||
log.debug "ON/OFF REPORTING CONFIG RESPONSE: " + cluster
|
||||
sendEvent(name: "checkInterval", value: 60 * 12, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID])
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
log.warn "ON/OFF REPORTING CONFIG FAILED- error code:${cluster.data[0]}"
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else if (device.getDataValue("manufacturer") == "sengled" && descMap && descMap.clusterInt == 0x0008 && descMap.attrInt == 0x0000) {
|
||||
// This is being done because the sengled element touch/classic incorrectly uses the value 0xFF for the max level.
|
||||
// Per the ZCL spec for the UINT8 data type 0xFF is an invalid value, and 0xFE should be the max. Here we
|
||||
// manually handle the invalid attribute value since it will be ignored by getEvent as an invalid value.
|
||||
// We also set the level of the bulb to 0xFE so future level reports will be 0xFE until it is changed by
|
||||
// something else.
|
||||
if (descMap.value.toUpperCase() == "FF") {
|
||||
descMap.value = "FE"
|
||||
}
|
||||
sendHubCommand(zigbee.command(zigbee.LEVEL_CONTROL_CLUSTER, 0x00, "FE0000").collect { new physicalgraph.device.HubAction(it) }, 0)
|
||||
sendEvent(zigbee.getEventFromAttrData(descMap.clusterInt, descMap.attrInt, descMap.encoding, descMap.value))
|
||||
} else {
|
||||
log.warn "DID NOT PARSE MESSAGE for description : $description"
|
||||
log.debug "${cluster}"
|
||||
log.debug "${descMap}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,12 +103,12 @@ def parse(String description) {
|
||||
|
||||
if (zigbeeMap?.clusterInt == COLOR_CONTROL_CLUSTER) {
|
||||
if(zigbeeMap.attrInt == ATTRIBUTE_HUE){ //Hue Attribute
|
||||
def hueValue = Math.round(zigbee.convertHexToInt(zigbeeMap.value) / 0xfe * 100)
|
||||
sendEvent(name: "hue", value: hueValue, descriptionText: "Color has changed")
|
||||
state.hueValue = Math.round(zigbee.convertHexToInt(zigbeeMap.value) / 0xfe * 100)
|
||||
runIn(5, updateColor, [overwrite: true])
|
||||
}
|
||||
else if(zigbeeMap.attrInt == ATTRIBUTE_SATURATION){ //Saturation Attribute
|
||||
def saturationValue = Math.round(zigbee.convertHexToInt(zigbeeMap.value) / 0xfe * 100)
|
||||
sendEvent(name: "saturation", value: saturationValue, descriptionText: "Color has changed", displayed: false)
|
||||
state.saturationValue = Math.round(zigbee.convertHexToInt(zigbeeMap.value) / 0xfe * 100)
|
||||
runIn(5, updateColor, [overwrite: true])
|
||||
}
|
||||
}
|
||||
else if (cluster && cluster.clusterId == 0x0006 && cluster.command == 0x07) {
|
||||
@@ -127,6 +127,11 @@ def parse(String description) {
|
||||
}
|
||||
}
|
||||
|
||||
def updateColor() {
|
||||
sendEvent(name: "hue", value: state.hueValue, descriptionText: "Color has changed")
|
||||
sendEvent(name: "saturation", value: state.saturationValue, descriptionText: "Color has changed", displayed: false)
|
||||
}
|
||||
|
||||
def on() {
|
||||
zigbee.on()
|
||||
}
|
||||
@@ -204,9 +209,9 @@ def setColor(value){
|
||||
log.trace "setColor($value)"
|
||||
zigbee.on() +
|
||||
zigbee.command(COLOR_CONTROL_CLUSTER, MOVE_TO_HUE_AND_SATURATION_COMMAND,
|
||||
getScaledHue(value.hue), getScaledSaturation(value.saturation), "0000") +
|
||||
zigbee.readAttribute(COLOR_CONTROL_CLUSTER, ATTRIBUTE_HUE) +
|
||||
zigbee.readAttribute(COLOR_CONTROL_CLUSTER, ATTRIBUTE_SATURATION)
|
||||
getScaledHue(value.hue), getScaledSaturation(value.saturation), "0000") +
|
||||
zigbee.readAttribute(COLOR_CONTROL_CLUSTER, ATTRIBUTE_SATURATION) +
|
||||
zigbee.readAttribute(COLOR_CONTROL_CLUSTER, ATTRIBUTE_HUE)
|
||||
}
|
||||
|
||||
def setHue(value) {
|
||||
|
||||
412
smartapps/mujica/tcp-bulbs-connect.src/tcp-bulbs-connect.groovy
Normal file
412
smartapps/mujica/tcp-bulbs-connect.src/tcp-bulbs-connect.groovy
Normal file
@@ -0,0 +1,412 @@
|
||||
/**
|
||||
* Copyright 2015 SmartThings
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
definition(
|
||||
name: "Tcp Bulbs (Connect)",
|
||||
namespace: "mujica",
|
||||
author: "SmartThings-Ule",
|
||||
description: "Connect your TCP bulbs to SmartThings using local integration. You must have a geteway with firmware ver 2",
|
||||
category: "SmartThings Labs",
|
||||
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Partner/tcp.png",
|
||||
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Partner/tcp@2x.png",
|
||||
singleInstance: true
|
||||
)
|
||||
|
||||
|
||||
preferences {
|
||||
page(name: "iniSettings", title: "Connect Your TCP Lights to SmartThings", content: "iniSettings")
|
||||
page(name: "chooseBulbs", title: "Choose Bulbs to Control With SmartThings", content: "bulbDiscovery")
|
||||
}
|
||||
|
||||
def iniSettings(){
|
||||
state.loadStatus = "Inactive"
|
||||
log.trace "state.loadStatus ${state.loadStatus}"
|
||||
return dynamicPage(name:"iniSettings", title:"Connect Your TCP Lights to SmartThings", nextPage:"chooseBulbs", install:false, uninstall: true) {
|
||||
section("TCP Connected Remote Credentials") {
|
||||
input "ipGateway", "text", title: "Enter TCP Gateway IP", required: true
|
||||
paragraph "Tap 'Next' after you have entered the ip of your TCP Connected Gateway.\r\n\r\nOnce your ip are accepted, SmartThings will scan your TCP installation for Bulbs."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def bulbDiscovery() {
|
||||
debugOut "bulbDiscovery()"
|
||||
//getToken()
|
||||
state.token = "1234567890"
|
||||
|
||||
if (state.loadStatus == "Inactive"){
|
||||
state.count = 0
|
||||
state.loadStatus = "Loading"
|
||||
log.trace "state.loadStatus ${state.loadStatus}"
|
||||
deviceDiscovery()
|
||||
}
|
||||
log.trace "state.count ${state.count}"
|
||||
state.count = state.count + 1
|
||||
log.trace "state.count ${state.count}"
|
||||
if(state.loadStatus == "Loaded" ){
|
||||
def options = devicesDiscovered() ?: []
|
||||
log.trace "state.loadStatus ${state.loadStatus}"
|
||||
return dynamicPage(name:"chooseBulbs", title:"", nextPage:"", install:true, uninstall: true) {
|
||||
section("Tap Below to View Device List") {
|
||||
input "selectedBulbs", "enum", required:false, title:"Select Bulb", multiple:true, options:options
|
||||
paragraph """Tap 'Done' after you have selected the desired devices."""
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if (state.count)
|
||||
|
||||
log.trace "state.loadStatus ${state.loadStatus}"
|
||||
def msg = state.count >= 3 ? "The TCP Gateway is not responding, please verify the ip address" : "Please wait while we discover your devices. Discovery can take some minutes or more, so sit back and relax! Select your device below once discovered."
|
||||
return dynamicPage(name:"chooseBulbs", title:"", nextPage:"", refreshInterval:5) {
|
||||
section(msg) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def installed() {
|
||||
debugOut "Installed with settings: ${settings}"
|
||||
|
||||
unschedule()
|
||||
unsubscribe()
|
||||
|
||||
setupBulbs()
|
||||
|
||||
def cron = "0 0/1 * * * ?"
|
||||
log.debug "schedule('$cron', syncronizeDevices)"
|
||||
schedule(cron, syncronizeDevices)
|
||||
}
|
||||
|
||||
def updated() {
|
||||
debugOut "Updated with settings: ${settings}"
|
||||
unschedule()
|
||||
setupBulbs()
|
||||
def cron = "0 0/1 * * * ?"
|
||||
log.debug "schedule('$cron', syncronizeDevices)"
|
||||
schedule(cron, syncronizeDevices)
|
||||
}
|
||||
|
||||
def uninstalled()
|
||||
{
|
||||
unschedule() //in case we have hanging runIn()'s
|
||||
}
|
||||
|
||||
private removeChildDevices(delete)
|
||||
{
|
||||
debugOut "deleting ${delete.size()} bulbs"
|
||||
debugOut "deleting ${delete}"
|
||||
delete.each {
|
||||
deleteChildDevice(it.device.deviceNetworkId)
|
||||
}
|
||||
}
|
||||
|
||||
def uninstallFromChildDevice(childDevice)
|
||||
{
|
||||
def errorMsg = "uninstallFromChildDevice was called and "
|
||||
if (!settings.selectedBulbs) {
|
||||
debugOut errorMsg += "had empty list passed in"
|
||||
return
|
||||
}
|
||||
|
||||
def dni = childDevice.device.deviceNetworkId
|
||||
|
||||
if ( !dni ) {
|
||||
debugOut errorMsg += "could not find dni of device"
|
||||
return
|
||||
}
|
||||
|
||||
def newDeviceList = settings.selectedBulbs - dni
|
||||
app.updateSetting("selectedBulbs", newDeviceList)
|
||||
debugOut errorMsg += "completed succesfully"
|
||||
}
|
||||
|
||||
|
||||
def setupBulbs() {
|
||||
debugOut "setupBulbs()"
|
||||
def bulbs = state.devices
|
||||
def deviceFile = "TCP Bulb"
|
||||
|
||||
selectedBulbs.each { did ->
|
||||
//see if this is a selected bulb and install it if not already
|
||||
def d = getChildDevice(did)
|
||||
|
||||
if(!d) {
|
||||
def newBulb = bulbs.find { (it.did) == did }
|
||||
d = addChildDevice("mujica", deviceFile, did, null, [name: "${newBulb?.name}", label: "${newBulb?.name}", completedSetup: true,"data":["model":newBulb?.model,"nodetype":newBulb?.nodetype,"node":newBulb?.node,"dni":did]])
|
||||
} else {
|
||||
infoOut "Avoid add existent device ${did}"
|
||||
}
|
||||
}
|
||||
def delete = getChildDevices().findAll { !selectedBulbs?.contains(it.deviceNetworkId) }
|
||||
removeChildDevices(delete)
|
||||
}
|
||||
|
||||
|
||||
def deviceDiscovery() {
|
||||
log.trace "deviceDiscovery()"
|
||||
def data = "<gip><version>1</version><token>${state.token}</token></gip>"
|
||||
|
||||
def Params = [
|
||||
cmd: "RoomGetCarousel",
|
||||
data: "${data}",
|
||||
fmt: "json"
|
||||
]
|
||||
|
||||
def cmd = toQueryString(Params)
|
||||
|
||||
debugOut "deviceDiscovery()"
|
||||
|
||||
apiGet(cmd,"RoomGetCarouselHandler")
|
||||
}
|
||||
|
||||
def apiGet(String data, String calledBackHandler) {
|
||||
debugOut "apiGet($data, $calledBackHandler) $ipGateway"
|
||||
sendHubCommand(new physicalgraph.device.HubAction([
|
||||
method: "GET",
|
||||
path: "/gwr/gop.php?$data",
|
||||
headers: [
|
||||
HOST: "$ipGateway:80"
|
||||
]], getNetworkId("$ipGateway","80"), [callback: calledBackHandler]))
|
||||
}
|
||||
|
||||
|
||||
void SendCommandHandler(physicalgraph.device.HubResponse hubResponse){
|
||||
debugOut "SendCommandHandler($hubResponse)"
|
||||
debugOut "hubResponse.body ${hubResponse.body}"
|
||||
}
|
||||
void RoomGetCarouselHandler(physicalgraph.device.HubResponse hubResponse){
|
||||
debugOut "RoomGetCarouselHandler($hubResponse)"
|
||||
def bodyXml
|
||||
|
||||
if (hubResponse?.body?.contains("<gip>"))
|
||||
{ // description.xml response (application/xml)
|
||||
debugOut "body contains xml"
|
||||
bodyXml = new XmlSlurper().parseText(hubResponse.body)
|
||||
debugOut "bodyXml $bodyXml"
|
||||
}
|
||||
|
||||
|
||||
def rooms = ""
|
||||
def devices = []
|
||||
def deviceList = []
|
||||
|
||||
|
||||
rooms = bodyXml.room
|
||||
|
||||
|
||||
debugOut "rooms ${rooms[1]}"
|
||||
|
||||
rooms.each({
|
||||
devices = it.device
|
||||
debugOut "it.device ${it.device}"
|
||||
def roomName = it.name
|
||||
debugOut "roomName = ${it.name}"
|
||||
debugOut "devices[1] ${devices[1]}"
|
||||
debugOut "devices[1] != null"
|
||||
def roomId = it?.rid
|
||||
debugOut "Room Device Data: did:${roomId} roomName:${roomName}"
|
||||
devices.each({
|
||||
debugOut "Bulb Device Data: did:${it?.did} room:${roomName} BulbName:${it?.name}"
|
||||
deviceList += ["name" : "${roomName} ${it?.name}", "did" : "${it?.did}", "type" : "${devices?.type}", "node" : "${devices?.node}", "nodetype" : "${devices?.nodetype}", "model" : "${devices?.prodmodel}"]
|
||||
})
|
||||
})
|
||||
|
||||
devices = ["devices" : deviceList]
|
||||
debugOut "devices $devices"
|
||||
state.devices = devices.devices
|
||||
state.loadStatus = "Loaded"
|
||||
}
|
||||
|
||||
def getDevices()
|
||||
{
|
||||
state.devices = state.devices ?: [:]
|
||||
}
|
||||
|
||||
void RoomGetCarouselUpdateHandler(physicalgraph.device.HubResponse hubResponse){
|
||||
debugOut "RoomGetCarouselUpdateHandler($hubResponse)"
|
||||
|
||||
|
||||
debugOut "msg ${parseLanMessage(hubResponse.body)}"
|
||||
|
||||
def bodyXml
|
||||
|
||||
if (hubResponse?.body?.contains("<gip>"))
|
||||
{
|
||||
debugOut "body contains xml"
|
||||
bodyXml = new XmlSlurper().parseText(hubResponse.body)
|
||||
}
|
||||
|
||||
|
||||
def rooms = ""
|
||||
def devices = []
|
||||
def deviceList = []
|
||||
|
||||
rooms = bodyXml.room
|
||||
|
||||
rooms.each({
|
||||
devices = it.device
|
||||
devices.each({
|
||||
def dni = it.did.text()
|
||||
def bulb = getChildDevice(dni)
|
||||
if ( bulb ){
|
||||
def power = it.power ? it.power.text() as float :0
|
||||
sendEvent( dni, [name: "power", value: power*1000] )
|
||||
if (( it.state.text() == "1" ) && ( bulb?.currentValue("switch") != "on" ))
|
||||
sendEvent( dni, [name: "switch",value:"on"] )
|
||||
|
||||
if (( it.state.text() == "0" ) && ( bulb?.currentValue("switch") != "off" ))
|
||||
sendEvent( dni, [name: "switch",value:"off"] )
|
||||
|
||||
if ( it.level.text() != bulb?.currentValue("level")) {
|
||||
sendEvent( dni, [name: "level",value: "${it.level.text()}"] )
|
||||
sendEvent( dni, [name: "setLevel",value: "${it.level.text()}"] )
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Map devicesDiscovered() {
|
||||
def devices = state.devices
|
||||
def map = [:]
|
||||
if (devices instanceof java.util.Map) {
|
||||
devices.each {
|
||||
def value = "${it?.name}"
|
||||
def key = it?.did
|
||||
map["${key}"] = value
|
||||
}
|
||||
} else { //backwards compatable
|
||||
devices.each {
|
||||
def value = "${it?.name}"
|
||||
def key = it?.did
|
||||
map["${key}"] = value
|
||||
}
|
||||
}
|
||||
map
|
||||
}
|
||||
|
||||
def getToken() {
|
||||
|
||||
state.token = "1234567890"
|
||||
}
|
||||
|
||||
String toQueryString(Map m) {
|
||||
return m.collect { k, v -> "${k}=${URLEncoder.encode(v.toString())}" }.sort().join("&")
|
||||
}
|
||||
|
||||
def syncronizeDevices() {
|
||||
poll(null)
|
||||
}
|
||||
|
||||
def getNetworkId(ipaddr, port) {
|
||||
"${ipaddr.tokenize('.').collect {String.format('%02X', it.toInteger())}.join()}:${String.format('%04X', port.toInteger())}"
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
Child Device Call In Methods
|
||||
**************************************************************************/
|
||||
def on(childDevice) {
|
||||
|
||||
def dni = childDevice.device.deviceNetworkId
|
||||
def data = ""
|
||||
def cmd = ""
|
||||
|
||||
data = "<gip><version>1</version><token>$state.token</token><did>${dni}</did><type>power</type><value>1</value></gip>"
|
||||
cmd = "DeviceSendCommand"
|
||||
|
||||
def qParams = [
|
||||
cmd: cmd,
|
||||
data: "${data}",
|
||||
fmt: "json"
|
||||
]
|
||||
|
||||
cmd = toQueryString(qParams)
|
||||
apiGet(cmd,"SendCommandHandler" )
|
||||
}
|
||||
|
||||
def off(childDevice) {
|
||||
|
||||
def dni = childDevice.device.deviceNetworkId
|
||||
def data = ""
|
||||
def cmd = ""
|
||||
|
||||
data = "<gip><version>1</version><token>$state.token</token><did>${dni}</did><type>power</type><value>0</value></gip>"
|
||||
cmd = "DeviceSendCommand"
|
||||
|
||||
def qParams = [
|
||||
cmd: cmd,
|
||||
data: "${data}",
|
||||
fmt: "json"
|
||||
]
|
||||
|
||||
cmd = toQueryString(qParams)
|
||||
apiGet(cmd,"SendCommandHandler")
|
||||
|
||||
}
|
||||
|
||||
def setLevel(childDevice, value) {
|
||||
debugOut "setLevel request from child device"
|
||||
|
||||
def dni = childDevice.device.deviceNetworkId
|
||||
def data = ""
|
||||
def cmd = ""
|
||||
|
||||
data = "<gip><version>1</version><token>${state.token}</token><did>${dni}</did><type>level</type><value>${value}</value></gip>"
|
||||
cmd = "DeviceSendCommand"
|
||||
|
||||
|
||||
def qParams = [
|
||||
cmd: cmd,
|
||||
data: "${data}",
|
||||
fmt: "json"
|
||||
]
|
||||
|
||||
cmd = toQueryString(qParams)
|
||||
|
||||
apiGet(cmd,"SendCommandHandler")
|
||||
}
|
||||
|
||||
def poll(childDevice) {
|
||||
infoOut "poll()"
|
||||
def eventTime = new Date().time
|
||||
if ((state.lastPollTime ?:0) + 10000 <= eventTime ){
|
||||
state.lastPollTime = new Date().time
|
||||
def Params = [
|
||||
cmd: "RoomGetCarousel",
|
||||
data: "<gip><version>1</version><token>${state.token}</token></gip>",
|
||||
fmt: "json"
|
||||
]
|
||||
def cmd = toQueryString(Params)
|
||||
apiGet(cmd,"RoomGetCarouselUpdateHandler")
|
||||
}else{
|
||||
infoOut "Multiple poll requests avoided"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
Msg Methods
|
||||
**************************************************************************/
|
||||
|
||||
def debugOut(msg) {
|
||||
//log.debug msg
|
||||
}
|
||||
|
||||
def traceOut(msg) {
|
||||
log.trace msg
|
||||
}
|
||||
|
||||
def infoOut(msg) {
|
||||
log.info msg
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
//DEPRECATED. INTEGRATION MOVED TO SUPER LAN CONNECT
|
||||
|
||||
/**
|
||||
* Bose SoundTouch (Connect)
|
||||
*
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//DEPRECATED. INTEGRATION MOVED TO SUPER LAN CONNECT
|
||||
|
||||
/**
|
||||
* Hue Service Manager
|
||||
*
|
||||
@@ -1083,7 +1085,6 @@ def on(childDevice) {
|
||||
log.debug "Executing 'on'"
|
||||
def id = getId(childDevice)
|
||||
updateInProgress()
|
||||
createSwitchEvent(childDevice, "on")
|
||||
put("lights/$id/state", [on: true])
|
||||
return "Bulb is turning On"
|
||||
}
|
||||
@@ -1092,7 +1093,6 @@ def off(childDevice) {
|
||||
log.debug "Executing 'off'"
|
||||
def id = getId(childDevice)
|
||||
updateInProgress()
|
||||
createSwitchEvent(childDevice, "off")
|
||||
put("lights/$id/state", [on: false])
|
||||
return "Bulb is turning Off"
|
||||
}
|
||||
@@ -1108,8 +1108,6 @@ def setLevel(childDevice, percent) {
|
||||
else
|
||||
level = Math.min(Math.round(percent * 254 / 100), 254)
|
||||
|
||||
createSwitchEvent(childDevice, level > 0, percent)
|
||||
|
||||
// For Zigbee lights, if level is set to 0 ST just turns them off without changing level
|
||||
// that means that the light will still be on when on is called next time
|
||||
// Lets emulate that here
|
||||
@@ -1128,7 +1126,6 @@ def setSaturation(childDevice, percent) {
|
||||
// 0 - 254
|
||||
def level = Math.min(Math.round(percent * 254 / 100), 254)
|
||||
// TODO should this be done by app only or should we default to on?
|
||||
createSwitchEvent(childDevice, "on")
|
||||
put("lights/$id/state", [sat: level, on: true])
|
||||
return "Setting saturation to $percent"
|
||||
}
|
||||
@@ -1140,7 +1137,6 @@ def setHue(childDevice, percent) {
|
||||
// 0 - 65535
|
||||
def level = Math.min(Math.round(percent * 65535 / 100), 65535)
|
||||
// TODO should this be done by app only or should we default to on?
|
||||
createSwitchEvent(childDevice, "on")
|
||||
put("lights/$id/state", [hue: level, on: true])
|
||||
return "Setting hue to $percent"
|
||||
}
|
||||
@@ -1151,7 +1147,6 @@ def setColorTemperature(childDevice, huesettings) {
|
||||
updateInProgress()
|
||||
// 153 (6500K) to 500 (2000K)
|
||||
def ct = hueSettings == 6500 ? 153 : Math.round(1000000 / huesettings)
|
||||
createSwitchEvent(childDevice, "on")
|
||||
put("lights/$id/state", [ct: ct, on: true])
|
||||
return "Setting color temperature to $ct"
|
||||
}
|
||||
@@ -1210,7 +1205,6 @@ def setColor(childDevice, huesettings) {
|
||||
if (huesettings.switch == "off")
|
||||
value.on = false
|
||||
|
||||
createSwitchEvent(childDevice, value.on ? "on" : "off")
|
||||
put("lights/$id/state", value)
|
||||
return "Setting color to $value"
|
||||
}
|
||||
@@ -1322,32 +1316,6 @@ private List getRealHubFirmwareVersions() {
|
||||
return location.hubs*.firmwareVersionString.findAll { it }
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends appropriate turningOn/turningOff state events depending on switch or level changes.
|
||||
*
|
||||
* @param childDevice device to send event for
|
||||
* @param setSwitch The new switch state, "on" or "off"
|
||||
* @param setLevel Optional, switchLevel between 0-100, used if you set level to 0 for example since
|
||||
* that should generate "off" instead of level change
|
||||
*/
|
||||
private void createSwitchEvent(childDevice, setSwitch, setLevel = null) {
|
||||
|
||||
if (setLevel == null) {
|
||||
setLevel = childDevice.device?.currentValue("level")
|
||||
}
|
||||
// Create on, off, turningOn or turningOff event as necessary
|
||||
def currentState = childDevice.device?.currentValue("switch")
|
||||
if ((currentState == "off" || currentState == "turningOff")) {
|
||||
if (setSwitch == "on" || setLevel > 0) {
|
||||
childDevice.sendEvent(name: "switch", value: "turningOn", displayed: false)
|
||||
}
|
||||
} else if ((currentState == "on" || currentState == "turningOn")) {
|
||||
if (setSwitch == "off" || setLevel == 0) {
|
||||
childDevice.sendEvent(name: "switch", value: "turningOff", displayed: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the supported color range for different Hue lights. If model is not specified
|
||||
* it defaults to the smallest Gamut (B) to ensure that colors set on a mix of devices
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//DEPRECATED. INTEGRATION MOVED TO SUPER LAN CONNECT
|
||||
|
||||
/**
|
||||
* Copyright 2015 SmartThings
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user