mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-29 14:23:08 +01:00
Compare commits
3 Commits
MSA-1646-1
...
MSA-1603-1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
724886d5d1 | ||
|
|
957c33b49c | ||
|
|
b945243aa3 |
@@ -39,7 +39,7 @@ metadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def generatePresenceEvent(boolean present) {
|
def generatePresenceEvent(boolean present) {
|
||||||
log.info "Life360 generatePresenceEvent($present)"
|
log.debug "Here in generatePresenceEvent!"
|
||||||
def value = formatValue(present)
|
def value = formatValue(present)
|
||||||
def linkText = getLinkText(device)
|
def linkText = getLinkText(device)
|
||||||
def descriptionText = formatDescriptionText(linkText, present)
|
def descriptionText = formatDescriptionText(linkText, present)
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ private Map parseCatchAllMessage(String description) {
|
|||||||
if (cluster.command == 0x07) {
|
if (cluster.command == 0x07) {
|
||||||
if (cluster.data[0] == 0x00){
|
if (cluster.data[0] == 0x00){
|
||||||
log.debug "TEMP REPORTING CONFIG RESPONSE" + cluster
|
log.debug "TEMP REPORTING CONFIG RESPONSE" + cluster
|
||||||
resultMap = [name: "checkInterval", value: 60 * 12, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID]]
|
sendEvent(name: "checkInterval", value: 60 * 12, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID])
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.warn "TEMP REPORTING CONFIG FAILED- error code:${cluster.data[0]}"
|
log.warn "TEMP REPORTING CONFIG FAILED- error code:${cluster.data[0]}"
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ private Map parseCatchAllMessage(String description) {
|
|||||||
if (cluster.command == 0x07) {
|
if (cluster.command == 0x07) {
|
||||||
if (cluster.data[0] == 0x00) {
|
if (cluster.data[0] == 0x00) {
|
||||||
log.debug "TEMP REPORTING CONFIG RESPONSE" + cluster
|
log.debug "TEMP REPORTING CONFIG RESPONSE" + cluster
|
||||||
resultMap = [name: "checkInterval", value: 60 * 12, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID]]
|
sendEvent(name: "checkInterval", value: 60 * 12, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID])
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.warn "TEMP REPORTING CONFIG FAILED- error code:${cluster.data[0]}"
|
log.warn "TEMP REPORTING CONFIG FAILED- error code:${cluster.data[0]}"
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ private Map parseCatchAllMessage(String description) {
|
|||||||
if (cluster.command == 0x07) {
|
if (cluster.command == 0x07) {
|
||||||
if(cluster.data[0] == 0x00) {
|
if(cluster.data[0] == 0x00) {
|
||||||
log.debug "TEMP REPORTING CONFIG RESPONSE" + cluster
|
log.debug "TEMP REPORTING CONFIG RESPONSE" + cluster
|
||||||
resultMap = [name: "checkInterval", value: 60 * 12, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID]]
|
sendEvent(name: "checkInterval", value: 60 * 12, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID])
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.warn "TEMP REPORTING CONFIG FAILED- error code:${cluster.data[0]}"
|
log.warn "TEMP REPORTING CONFIG FAILED- error code:${cluster.data[0]}"
|
||||||
@@ -339,7 +339,7 @@ private Map getContactResult(value) {
|
|||||||
log.debug "Contact: ${device.displayName} value = ${value}"
|
log.debug "Contact: ${device.displayName} value = ${value}"
|
||||||
def descriptionText = value == 'open' ? '{{ device.displayName }} was opened' : '{{ device.displayName }} was closed'
|
def descriptionText = value == 'open' ? '{{ device.displayName }} was opened' : '{{ device.displayName }} was closed'
|
||||||
sendEvent(name: 'contact', value: value, descriptionText: descriptionText, displayed: false, translatable: true)
|
sendEvent(name: 'contact', value: value, descriptionText: descriptionText, displayed: false, translatable: true)
|
||||||
return [name: 'status', value: value, descriptionText: descriptionText, translatable: true]
|
sendEvent(name: 'status', value: value, descriptionText: descriptionText, translatable: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private getAccelerationResult(numValue) {
|
private getAccelerationResult(numValue) {
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ private Map parseCatchAllMessage(String description) {
|
|||||||
if (cluster.command == 0x07){
|
if (cluster.command == 0x07){
|
||||||
if (cluster.data[0] == 0x00) {
|
if (cluster.data[0] == 0x00) {
|
||||||
log.debug "TEMP REPORTING CONFIG RESPONSE" + cluster
|
log.debug "TEMP REPORTING CONFIG RESPONSE" + cluster
|
||||||
resultMap = [name: "checkInterval", value: 60 * 12, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID]]
|
sendEvent(name: "checkInterval", value: 60 * 12, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID])
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.warn "TEMP REPORTING CONFIG FAILED- error code:${cluster.data[0]}"
|
log.warn "TEMP REPORTING CONFIG FAILED- error code:${cluster.data[0]}"
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ private Map parseCatchAllMessage(String description) {
|
|||||||
if (cluster.command == 0x07) {
|
if (cluster.command == 0x07) {
|
||||||
if (cluster.data[0] == 0x00){
|
if (cluster.data[0] == 0x00){
|
||||||
log.debug "TEMP REPORTING CONFIG RESPONSE" + cluster
|
log.debug "TEMP REPORTING CONFIG RESPONSE" + cluster
|
||||||
resultMap = [name: "checkInterval", value: 60 * 12, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID]]
|
sendEvent(name: "checkInterval", value: 60 * 12, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID])
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.warn "TEMP REPORTING CONFIG FAILED- error code:${cluster.data[0]}"
|
log.warn "TEMP REPORTING CONFIG FAILED- error code:${cluster.data[0]}"
|
||||||
|
|||||||
@@ -127,8 +127,8 @@ def configureHealthCheck() {
|
|||||||
|
|
||||||
def configure() {
|
def configure() {
|
||||||
log.debug "configure()"
|
log.debug "configure()"
|
||||||
configureHealthCheck()
|
|
||||||
zigbee.onOffConfig() + zigbee.levelConfig() + zigbee.onOffRefresh() + zigbee.levelRefresh()
|
zigbee.onOffConfig() + zigbee.levelConfig() + zigbee.onOffRefresh() + zigbee.levelRefresh()
|
||||||
|
configureHealthCheck()
|
||||||
}
|
}
|
||||||
|
|
||||||
def updated() {
|
def updated() {
|
||||||
|
|||||||
@@ -1,536 +0,0 @@
|
|||||||
/**
|
|
||||||
* MyQ Lite
|
|
||||||
*
|
|
||||||
* Copyright 2015 Jason Mok/Brian Beaird/Barry Burke
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* Last Updated : 06/14/2016
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
definition(
|
|
||||||
name: "MyQ Lite",
|
|
||||||
namespace: "brbeaird",
|
|
||||||
author: "Jason Mok/Brian Beaird/Barry Burke",
|
|
||||||
description: "Integrate MyQ with Smartthings",
|
|
||||||
category: "SmartThings Labs",
|
|
||||||
iconUrl: "http://smartthings.copyninja.net/icons/MyQ@1x.png",
|
|
||||||
iconX2Url: "http://smartthings.copyninja.net/icons/MyQ@2x.png",
|
|
||||||
iconX3Url: "http://smartthings.copyninja.net/icons/MyQ@3x.png"
|
|
||||||
)
|
|
||||||
|
|
||||||
preferences {
|
|
||||||
page(name: "prefLogIn", title: "MyQ")
|
|
||||||
page(name: "prefListDevices", title: "MyQ")
|
|
||||||
page(name: "prefSensor1", title: "MyQ")
|
|
||||||
page(name: "prefSensor2", title: "MyQ")
|
|
||||||
page(name: "prefSensor3", title: "MyQ")
|
|
||||||
page(name: "prefSensor4", title: "MyQ")
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Preferences */
|
|
||||||
def prefLogIn() {
|
|
||||||
def showUninstall = username != null && password != null
|
|
||||||
return dynamicPage(name: "prefLogIn", title: "Connect to MyQ", nextPage:"prefListDevices", uninstall:showUninstall, install: false) {
|
|
||||||
section("Login Credentials"){
|
|
||||||
input("username", "email", title: "Username", description: "MyQ Username (email address)")
|
|
||||||
input("password", "password", title: "Password", description: "MyQ password")
|
|
||||||
}
|
|
||||||
section("Gateway Brand"){
|
|
||||||
input(name: "brand", title: "Gateway Brand", type: "enum", metadata:[values:["Liftmaster","Chamberlain","Craftsman"]] )
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def prefListDevices() {
|
|
||||||
if (forceLogin()) {
|
|
||||||
def doorList = getDoorList()
|
|
||||||
if ((doorList)) {
|
|
||||||
return dynamicPage(name: "prefListDevices", title: "Devices", nextPage:"prefSensor1", install:false, uninstall:true) {
|
|
||||||
if (doorList) {
|
|
||||||
section("Select which garage door/gate to use"){
|
|
||||||
input(name: "doors", type: "enum", required:false, multiple:true, metadata:[values:doorList])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
def devList = getDeviceList()
|
|
||||||
return dynamicPage(name: "prefListDevices", title: "Error!", install:false, uninstall:true) {
|
|
||||||
section(""){
|
|
||||||
paragraph "Could not find any supported device(s). Please report to author about these devices: " + devList
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return dynamicPage(name: "prefListDevices", title: "Error!", install:false, uninstall:true) {
|
|
||||||
section(""){
|
|
||||||
paragraph "The username or password you entered is incorrect. Try again. "
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def prefSensor1() {
|
|
||||||
log.debug "Doors chosen: " + doors
|
|
||||||
|
|
||||||
//Set defaults
|
|
||||||
def nextPage = ""
|
|
||||||
def showInstall = true
|
|
||||||
def titleText = ""
|
|
||||||
|
|
||||||
//Determine if we have multiple doors and need to send to another page
|
|
||||||
if (doors instanceof String){ //simulator seems to just make a single door a string. For that reason we have this weird check.
|
|
||||||
log.debug "Single door detected (string)."
|
|
||||||
titleText = "Select Sensors for Door 1 (" + state.data[doors].name + ")"
|
|
||||||
}
|
|
||||||
else if (doors.size() == 1){
|
|
||||||
log.debug "Single door detected (array)."
|
|
||||||
titleText = "Select Sensors for Door 1 (" + state.data[doors[0]].name + ")"
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
log.debug "Multiple doors detected."
|
|
||||||
nextPage = "prefSensor2"
|
|
||||||
titleText = "Select Sensors for Door 1 (" + state.data[doors[0]].name + ")"
|
|
||||||
showInstall = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return dynamicPage(name: "prefSensor1", title: "Sensors", nextPage:nextPage, install:showInstall, uninstall:true) {
|
|
||||||
section(titleText){
|
|
||||||
input(name: "door1Sensor", title: "Contact Sensor", type: "capability.contactSensor", required: true, multiple: false)
|
|
||||||
input(name: "door1Acceleration", title: "Acceleration Sensor", type: "capability.accelerationSensor", required: false, multiple: false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def prefSensor2() {
|
|
||||||
def nextPage = ""
|
|
||||||
def showInstall = true
|
|
||||||
def titleText = "Sensors for Door 2 (" + state.data[doors[1]].name + ")"
|
|
||||||
|
|
||||||
if (doors.size() > 2){
|
|
||||||
nextPage = "prefSensor3"
|
|
||||||
showInstall = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return dynamicPage(name: "prefSensor2", title: "Sensors", nextPage:nextPage, install:showInstall, uninstall:true) {
|
|
||||||
section(titleText){
|
|
||||||
input(name: "door2Sensor", title: "Contact Sensor", type: "capability.contactSensor", required: true, multiple: false)
|
|
||||||
input(name: "door2Acceleration", title: "Acceleration Sensor", type: "capability.accelerationSensor", required: false, multiple: false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def prefSensor3() {
|
|
||||||
def nextPage = ""
|
|
||||||
def showInstall = true
|
|
||||||
def titleText = "Sensors for Door 3 (" + state.data[doors[2]].name + ")"
|
|
||||||
|
|
||||||
if (doors.size() > 3){
|
|
||||||
nextPage = "prefSensor4"
|
|
||||||
showInstall = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return dynamicPage(name: "prefSensor3", title: "Sensors", nextPage:nextPage, install:showInstall, uninstall:true) {
|
|
||||||
section(titleText){
|
|
||||||
input(name: "door3Sensor", title: "Contact Sensor", type: "capability.contactSensor", required: true, multiple: false)
|
|
||||||
input(name: "door3Acceleration", title: "Acceleration Sensor", type: "capability.accelerationSensor", required: false, multiple: false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def prefSensor4() {
|
|
||||||
def titleText = "Contact Sensor for Door 4 (" + state.data[doors[3]].name + ")"
|
|
||||||
return dynamicPage(name: "prefSensor4", title: "Sensors", install:true, uninstall:true) {
|
|
||||||
section(titleText){
|
|
||||||
input(name: "door4Sensor", title: "Contact Sensor", type: "capability.contactSensor", required: "true", multiple: "false")
|
|
||||||
input(name: "door4Acceleration", title: "Acceleration Sensor", type: "capability.accelerationSensor", required: false, multiple: false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Initialization */
|
|
||||||
def installed() { initialize() }
|
|
||||||
|
|
||||||
def updated() {
|
|
||||||
unsubscribe()
|
|
||||||
initialize()
|
|
||||||
}
|
|
||||||
|
|
||||||
def uninstalled() {}
|
|
||||||
|
|
||||||
def initialize() {
|
|
||||||
login()
|
|
||||||
state.sensorMap = [:]
|
|
||||||
|
|
||||||
// Get initial device status in state.data
|
|
||||||
state.polling = [ last: 0, rescheduler: now() ]
|
|
||||||
state.data = [:]
|
|
||||||
|
|
||||||
// Create selected devices
|
|
||||||
def doorsList = getDoorList()
|
|
||||||
//def lightsList = getLightList()
|
|
||||||
def selectedDevices = [] + getSelectedDevices("doors")
|
|
||||||
|
|
||||||
selectedDevices.each {
|
|
||||||
log.debug "Creating child device: " + it
|
|
||||||
if (!getChildDevice(it)) {
|
|
||||||
if (it.contains("GarageDoorOpener")) { addChildDevice("brbeaird", "MyQ Garage Door Opener", it, null, ["name": "MyQLite: " + doorsList[it]]) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove unselected devices
|
|
||||||
def deleteDevices = (selectedDevices) ? (getChildDevices().findAll { !selectedDevices.contains(it.deviceNetworkId) }) : getAllChildDevices()
|
|
||||||
deleteDevices.each { deleteChildDevice(it.deviceNetworkId) }
|
|
||||||
|
|
||||||
//Create subscriptions
|
|
||||||
if (door1Sensor)
|
|
||||||
subscribe(door1Sensor, "contact", sensorHandler)
|
|
||||||
if (door2Sensor)
|
|
||||||
subscribe(door2Sensor, "contact", sensorHandler)
|
|
||||||
if (door3Sensor)
|
|
||||||
subscribe(door3Sensor, "contact", sensorHandler)
|
|
||||||
if (door4Sensor)
|
|
||||||
subscribe(door4Sensor, "contact", sensorHandler)
|
|
||||||
|
|
||||||
if (door1Acceleration)
|
|
||||||
subscribe(door1Acceleration, "acceleration", sensorHandler)
|
|
||||||
if (door2Acceleration)
|
|
||||||
subscribe(door2Acceleration, "acceleration", sensorHandler)
|
|
||||||
if (door3Acceleration)
|
|
||||||
subscribe(door3Acceleration, "acceleration", sensorHandler)
|
|
||||||
if (door4Acceleration)
|
|
||||||
subscribe(door4Acceleration, "acceleration", sensorHandler)
|
|
||||||
|
|
||||||
//Set initial values
|
|
||||||
syncDoorsWithSensors()
|
|
||||||
}
|
|
||||||
|
|
||||||
def syncDoorsWithSensors(child){
|
|
||||||
def firstDoor = doors[0]
|
|
||||||
|
|
||||||
//Handle single door (sometimes it's just a dumb string thanks to the simulator)
|
|
||||||
if (doors instanceof String)
|
|
||||||
firstDoor = doors
|
|
||||||
|
|
||||||
def doorDNI = null
|
|
||||||
if (child) { // refresh only the requesting door (makes things a bit more efficient if you have more than 1 door
|
|
||||||
doorDNI = child.device.deviceNetworkId
|
|
||||||
switch (doorDNI) {
|
|
||||||
case firstDoor:
|
|
||||||
updateDoorStatus(firstDoor, door1Sensor, door1Acceleration, door1ThreeAxis, child)
|
|
||||||
break
|
|
||||||
case doors[1]:
|
|
||||||
updateDoorStatus(doors[1], door2Sensor, door2Acceleration, door2ThreeAxis, child)
|
|
||||||
break
|
|
||||||
case doors[2]:
|
|
||||||
updateDoorStatus(doors[2], door3Sensor, door3Acceleration, door3ThreeAxis, child)
|
|
||||||
break
|
|
||||||
case doors[3]:
|
|
||||||
updateDoorStatus(doors[3], door4Sensor, door4Acceleration, door4ThreeAxis, child)
|
|
||||||
}
|
|
||||||
} else { // refresh ALL the doors
|
|
||||||
if (firstDoor) updateDoorStatus(firstDoor, door1Sensor, door1Acceleration, door1ThreeAxis, null)
|
|
||||||
if (doors[1]) updateDoorStatus(doors[1], door2Sensor, door2Acceleration, door2ThreeAxis, null)
|
|
||||||
if (doors[2]) updateDoorStatus(doors[2], door3Sensor, door3Acceleration, door3ThreeAxis, null)
|
|
||||||
if (doors[3]) updateDoorStatus(doors[3], door4Sensor, door4Acceleration, door4ThreeAxis, null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def updateDoorStatus(doorDNI, sensor, acceleration, threeAxis, child){
|
|
||||||
|
|
||||||
//Get door to update and set the new value
|
|
||||||
def doorToUpdate = getChildDevice(doorDNI)
|
|
||||||
def doorName = state.data[doorDNI].name
|
|
||||||
|
|
||||||
def value = "unknown"
|
|
||||||
def moving = "unknown"
|
|
||||||
def door = doorToUpdate.latestValue("door")
|
|
||||||
|
|
||||||
if (acceleration) moving = acceleration.latestValue("acceleration")
|
|
||||||
if (sensor) value = sensor.latestValue("contact")
|
|
||||||
|
|
||||||
if (moving == "active") {
|
|
||||||
if (value == "open") {
|
|
||||||
if (door != "opening") value = "closing" else value = "opening" // if door is "open" or "waiting" change to "closing", else it must be "opening"
|
|
||||||
} else if (value == "closed") {
|
|
||||||
if (door != "closing") value = "opening" else value = "closed"
|
|
||||||
}
|
|
||||||
} else if (moving == "inactive") {
|
|
||||||
if (door == "closing") {
|
|
||||||
if (value == "open") { // just stopped but door is still open
|
|
||||||
value = "stopped"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
doorToUpdate.updateDeviceStatus(value)
|
|
||||||
doorToUpdate.updateDeviceSensor("${sensor} is ${sensor.currentContact}")
|
|
||||||
|
|
||||||
log.debug "Door: " + doorName + ": Updating with status - " + value + " - from sensor " + sensor
|
|
||||||
|
|
||||||
//Write to child log if this was initiated from one of the doors
|
|
||||||
if (child)
|
|
||||||
child.log("Door: " + doorName + ": Updating with status - " + value + " - from sensor " + sensor)
|
|
||||||
|
|
||||||
if (acceleration) {
|
|
||||||
doorToUpdate.updateDeviceMoving("${acceleration} is ${moving}")
|
|
||||||
log.debug "Door: " + doorName + ": Updating with status - " + moving + " - from sensor " + acceleration
|
|
||||||
if (child)
|
|
||||||
child.log("Door: " + doorName + ": Updating with status - " + moving + " - from sensor " + acceleration)
|
|
||||||
}
|
|
||||||
|
|
||||||
//Get latest activity timestamp for the sensor (data saved for up to a week)
|
|
||||||
def eventsSinceYesterday = sensor.eventsSince(new Date() - 7)
|
|
||||||
def latestEvent = eventsSinceYesterday[0]?.date
|
|
||||||
def timeStampLogText = "Door: " + doorName + ": Updating timestamp to: " + latestEvent + " - from sensor " + sensor
|
|
||||||
|
|
||||||
if (!latestEvent) //If the door has been inactive for more than a week, timestamp data will be null. Keep current value in that case.
|
|
||||||
timeStampLogText = "Door: " + doorName + ": Null timestamp detected " + " - from sensor " + sensor + " . Keeping current value."
|
|
||||||
else
|
|
||||||
doorToUpdate.updateDeviceLastActivity(latestEvent)
|
|
||||||
|
|
||||||
log.debug timeStampLogText
|
|
||||||
|
|
||||||
//Write to child log if this was initiated from one of the doors
|
|
||||||
if (child)
|
|
||||||
child.log(timeStampLogText)
|
|
||||||
}
|
|
||||||
|
|
||||||
def refresh(child){
|
|
||||||
def door = child.device.deviceNetworkId
|
|
||||||
def doorName = state.data[door].name
|
|
||||||
child.log("refresh called from " + doorName + ' (' + door + ')')
|
|
||||||
syncDoorsWithSensors(child)
|
|
||||||
}
|
|
||||||
|
|
||||||
def sensorHandler(evt) {
|
|
||||||
log.debug "Sensor change detected: Event name " + evt.name + " value: " + evt.value + " deviceID: " + evt.deviceId
|
|
||||||
|
|
||||||
switch (evt.deviceId) {
|
|
||||||
case door1Sensor.id:
|
|
||||||
case door1Acceleration?.id:
|
|
||||||
def firstDoor = doors[0]
|
|
||||||
if (doors instanceof String) firstDoor = doors
|
|
||||||
updateDoorStatus(firstDoor, door1Sensor, door1Acceleration, door1ThreeAxis, null)
|
|
||||||
break
|
|
||||||
case door2Sensor?.id:
|
|
||||||
case door2Acceleration?.id:
|
|
||||||
updateDoorStatus(doors[1], door2Sensor, door2Acceleration, door2ThreeAxis, null)
|
|
||||||
break
|
|
||||||
case door3Sensor?.id:
|
|
||||||
case door3Acceleration?.id:
|
|
||||||
updateDoorStatus(doors[2], door3Sensor, door3Acceleration, door3ThreeAxis, null)
|
|
||||||
break
|
|
||||||
case door4Sensor?.id:
|
|
||||||
case door4Acceleration?.id:
|
|
||||||
updateDoorStatus(doors[3], door4Sensor, door4Acceleration, door4ThreeAxis, null)
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
syncDoorsWithSensors()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def getSelectedDevices( settingsName ) {
|
|
||||||
def selectedDevices = []
|
|
||||||
(!settings.get(settingsName))?:((settings.get(settingsName)?.getAt(0)?.size() > 1) ? settings.get(settingsName)?.each { selectedDevices.add(it) } : selectedDevices.add(settings.get(settingsName)))
|
|
||||||
return selectedDevices
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Access Management */
|
|
||||||
private forceLogin() {
|
|
||||||
//Reset token and expiry
|
|
||||||
state.session = [ brandID: 0, brandName: settings.brand, securityToken: null, expiration: 0 ]
|
|
||||||
state.polling = [ last: 0, rescheduler: now() ]
|
|
||||||
state.data = [:]
|
|
||||||
return doLogin()
|
|
||||||
}
|
|
||||||
|
|
||||||
private login() { return (!(state.session.expiration > now())) ? doLogin() : true }
|
|
||||||
|
|
||||||
private doLogin() {
|
|
||||||
apiGet("/api/user/validate", [username: settings.username, password: settings.password] ) { response ->
|
|
||||||
log.debug "got login response: " + response
|
|
||||||
if (response.status == 200) {
|
|
||||||
if (response.data.SecurityToken != null) {
|
|
||||||
state.session.brandID = response.data.BrandId
|
|
||||||
state.session.brandName = response.data.BrandName
|
|
||||||
state.session.securityToken = response.data.SecurityToken
|
|
||||||
state.session.expiration = now() + 150000
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Listing all the garage doors you have in MyQ
|
|
||||||
private getDoorList() {
|
|
||||||
def deviceList = [:]
|
|
||||||
apiGet("/api/v4/userdevicedetails/get", []) { response ->
|
|
||||||
if (response.status == 200) {
|
|
||||||
//log.debug "response data: " + response.data.Devices
|
|
||||||
//sendAlert("response data: " + response.data.Devices)
|
|
||||||
response.data.Devices.each { device ->
|
|
||||||
// 2 = garage door, 5 = gate, 7 = MyQGarage(no gateway), 17 = Garage Door Opener WGDO
|
|
||||||
if (device.MyQDeviceTypeId == 2||device.MyQDeviceTypeId == 5||device.MyQDeviceTypeId == 7||device.MyQDeviceTypeId == 17) {
|
|
||||||
log.debug "Found door: " + device.MyQDeviceId
|
|
||||||
def dni = [ app.id, "GarageDoorOpener", device.MyQDeviceId ].join('|')
|
|
||||||
def description = ''
|
|
||||||
def doorState = ''
|
|
||||||
def updatedTime = ''
|
|
||||||
device.Attributes.each {
|
|
||||||
|
|
||||||
if (it.AttributeDisplayName=="desc") //deviceList[dni] = it.Value
|
|
||||||
{
|
|
||||||
description = it.Value
|
|
||||||
}
|
|
||||||
|
|
||||||
if (it.AttributeDisplayName=="doorstate") {
|
|
||||||
doorState = it.Value
|
|
||||||
updatedTime = it.UpdatedTime
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Ignore any doors with blank descriptions
|
|
||||||
if (description != ''){
|
|
||||||
log.debug "adding door: " + description + "type: " + device.MyQDeviceTypeId + " status: " + doorState
|
|
||||||
deviceList[dni] = description
|
|
||||||
state.data[dni] = [ status: doorState, lastAction: updatedTime, name: description ]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return deviceList
|
|
||||||
}
|
|
||||||
|
|
||||||
private getDeviceList() {
|
|
||||||
def deviceList = []
|
|
||||||
apiGet("/api/v4/userdevicedetails/get", []) { response ->
|
|
||||||
if (response.status == 200) {
|
|
||||||
response.data.Devices.each { device ->
|
|
||||||
log.debug "MyQDeviceTypeId : " + device.MyQDeviceTypeId.toString()
|
|
||||||
if (!(device.MyQDeviceTypeId == 1||device.MyQDeviceTypeId == 2||device.MyQDeviceTypeId == 3||device.MyQDeviceTypeId == 5||device.MyQDeviceTypeId == 7)) {
|
|
||||||
device.Attributes.each {
|
|
||||||
def description = ''
|
|
||||||
def doorState = ''
|
|
||||||
def updatedTime = ''
|
|
||||||
if (it.AttributeDisplayName=="desc") //deviceList[dni] = it.Value
|
|
||||||
description = it.Value
|
|
||||||
|
|
||||||
//Ignore any doors with blank descriptions
|
|
||||||
if (description != ''){
|
|
||||||
log.debug "found device: " + description
|
|
||||||
deviceList.add( device.MyQDeviceTypeId.toString() + "|" + device.TypeID )
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return deviceList
|
|
||||||
}
|
|
||||||
|
|
||||||
/* api connection */
|
|
||||||
// get URL
|
|
||||||
private getApiURL() {
|
|
||||||
if (settings.brand == "Craftsman") {
|
|
||||||
return "https://craftexternal.myqdevice.com"
|
|
||||||
} else {
|
|
||||||
return "https://myqexternal.myqdevice.com"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private getApiAppID() {
|
|
||||||
if (settings.brand == "Craftsman") {
|
|
||||||
return "QH5AzY8MurrilYsbcG1f6eMTffMCm3cIEyZaSdK/TD/8SvlKAWUAmodIqa5VqVAs"
|
|
||||||
} else {
|
|
||||||
return "JVM/G9Nwih5BwKgNCjLxiFUQxQijAebyyg8QUHr7JOrP+tuPb8iHfRHKwTmDzHOu"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// HTTP GET call
|
|
||||||
private apiGet(apiPath, apiQuery = [], callback = {}) {
|
|
||||||
// set up query
|
|
||||||
apiQuery = [ appId: getApiAppID() ] + apiQuery
|
|
||||||
if (state.session.securityToken) { apiQuery = apiQuery + [SecurityToken: state.session.securityToken ] }
|
|
||||||
|
|
||||||
try {
|
|
||||||
httpGet([ uri: getApiURL(), path: apiPath, query: apiQuery ]) { response -> callback(response) }
|
|
||||||
} catch (SocketException e) {
|
|
||||||
//sendAlert("API Error: $e")
|
|
||||||
log.debug "API Error: $e"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// HTTP PUT call
|
|
||||||
private apiPut(apiPath, apiBody = [], callback = {}) {
|
|
||||||
// set up body
|
|
||||||
apiBody = [ ApplicationId: getApiAppID() ] + apiBody
|
|
||||||
if (state.session.securityToken) { apiBody = apiBody + [SecurityToken: state.session.securityToken ] }
|
|
||||||
|
|
||||||
// set up query
|
|
||||||
def apiQuery = [ appId: getApiAppID() ]
|
|
||||||
if (state.session.securityToken) { apiQuery = apiQuery + [SecurityToken: state.session.securityToken ] }
|
|
||||||
|
|
||||||
try {
|
|
||||||
httpPut([ uri: getApiURL(), path: apiPath, contentType: "application/json; charset=utf-8", body: apiBody, query: apiQuery ]) { response -> callback(response) }
|
|
||||||
} catch (SocketException e) {
|
|
||||||
log.debug "API Error: $e"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get Device ID
|
|
||||||
def getChildDeviceID(child) {
|
|
||||||
return child.device.deviceNetworkId.split("\\|")[2]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get single device status
|
|
||||||
def getDeviceStatus(child) {
|
|
||||||
return state.data[child.device.deviceNetworkId].status
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get single device last activity
|
|
||||||
def getDeviceLastActivity(child) {
|
|
||||||
return state.data[child.device.deviceNetworkId].lastAction.toLong()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send command to start or stop
|
|
||||||
def sendCommand(child, attributeName, attributeValue) {
|
|
||||||
if (login()) {
|
|
||||||
//Send command
|
|
||||||
apiPut("/api/v4/deviceattribute/putdeviceattribute", [ MyQDeviceId: getChildDeviceID(child), AttributeName: attributeName, AttributeValue: attributeValue ])
|
|
||||||
|
|
||||||
if ((attributeName == "desireddoorstate") && (attributeValue == 0)) { // if we are closing, check if we have an Acceleration sensor, if so, "waiting" until it moves
|
|
||||||
def firstDoor = doors[0]
|
|
||||||
if (doors instanceof String) firstDoor = doors
|
|
||||||
def doorDNI = child.device.deviceNetworkId
|
|
||||||
switch (doorDNI) {
|
|
||||||
case firstDoor:
|
|
||||||
if (door1Acceleration) child.updateDeviceStatus("waiting") else child.updateDeviceStatus("opening")
|
|
||||||
break
|
|
||||||
case doors[1]:
|
|
||||||
if (door2Acceleration) child.updateDeviceStatus("waiting") else child.updateDeviceStatus("opening")
|
|
||||||
break
|
|
||||||
case doors[2]:
|
|
||||||
if (door3Acceleration) child.updateDeviceStatus("waiting") else child.updateDeviceStatus("opening")
|
|
||||||
break
|
|
||||||
case doors[3]:
|
|
||||||
if (door4Acceleration) child.updateDeviceStatus("waiting") else child.updateDeviceStatus("opening")
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -289,12 +289,12 @@ def initializeLife360Connection() {
|
|||||||
state.life360AccessToken = result.data.access_token
|
state.life360AccessToken = result.data.access_token
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
log.info "Life360 initializeLife360Connection, response=${result.data}"
|
log.debug "Response=${result.data}"
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
log.error "Life360 initializeLife360Connection, error: $e"
|
log.debug e
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -656,7 +656,7 @@ def generateInitialEvent (member, childDevice) {
|
|||||||
|
|
||||||
try { // we are going to just ignore any errors
|
try { // we are going to just ignore any errors
|
||||||
|
|
||||||
log.info "Life360 generateInitialEvent($member, $childDevice)"
|
log.debug "Generate Initial Event for New Device for Member = ${member.id}"
|
||||||
|
|
||||||
def place = state.places.find{it.id==settings.place}
|
def place = state.places.find{it.id==settings.place}
|
||||||
|
|
||||||
@@ -678,8 +678,6 @@ def generateInitialEvent (member, childDevice) {
|
|||||||
|
|
||||||
boolean isPresent = (distanceAway <= placeRadius)
|
boolean isPresent = (distanceAway <= placeRadius)
|
||||||
|
|
||||||
log.info "Life360 generateInitialEvent, member: ($memberLatitude, $memberLongitude), place: ($placeLatitude, $placeLongitude), radius: $placeRadius, dist: $distanceAway, present: $isPresent"
|
|
||||||
|
|
||||||
// log.debug "External Id=${app.id}:${member.id}"
|
// log.debug "External Id=${app.id}:${member.id}"
|
||||||
|
|
||||||
// def childDevice2 = getChildDevice("${app.id}.${member.id}")
|
// def childDevice2 = getChildDevice("${app.id}.${member.id}")
|
||||||
@@ -720,7 +718,7 @@ def haversine(lat1, lon1, lat2, lon2) {
|
|||||||
|
|
||||||
def placeEventHandler() {
|
def placeEventHandler() {
|
||||||
|
|
||||||
log.info "Life360 placeEventHandler: params=$params, settings.place=$settings.place"
|
log.debug "In placeEventHandler method."
|
||||||
|
|
||||||
// the POST to this end-point will look like:
|
// the POST to this end-point will look like:
|
||||||
// POST http://test.com/webhook?circleId=XXXX&placeId=XXXX&userId=XXXX&direction=arrive
|
// POST http://test.com/webhook?circleId=XXXX&placeId=XXXX&userId=XXXX&direction=arrive
|
||||||
@@ -731,6 +729,8 @@ def placeEventHandler() {
|
|||||||
def direction = params?.direction
|
def direction = params?.direction
|
||||||
def timestamp = params?.timestamp
|
def timestamp = params?.timestamp
|
||||||
|
|
||||||
|
log.debug "Life360 Event: Circle: ${circleId}, Place: ${placeId}, User: ${userId}, Direction: ${direction}"
|
||||||
|
|
||||||
if (placeId == settings.place) {
|
if (placeId == settings.place) {
|
||||||
|
|
||||||
def presenceState = (direction=="in")
|
def presenceState = (direction=="in")
|
||||||
@@ -745,10 +745,10 @@ def placeEventHandler() {
|
|||||||
|
|
||||||
if (deviceWrapper) {
|
if (deviceWrapper) {
|
||||||
deviceWrapper.generatePresenceEvent(presenceState)
|
deviceWrapper.generatePresenceEvent(presenceState)
|
||||||
log.debug "Life360 event raised on child device: ${externalId}"
|
log.debug "Event raised on child device: ${externalId}"
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.warn "Life360 couldn't find child device associated with inbound Life360 event."
|
log.debug "Couldn't find child device associated with inbound Life360 event."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,799 @@
|
|||||||
|
/** * Home Remote
|
||||||
|
*
|
||||||
|
* Copyright 2015 The Home Remote
|
||||||
|
*
|
||||||
|
* 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: "Home Remote",
|
||||||
|
namespace: "thehomeremote.homeremote",
|
||||||
|
author: "The Home Remote",
|
||||||
|
description: "Web service that enables communication between the Home Remote app and a SmartThings hub.",
|
||||||
|
category: "My Apps",
|
||||||
|
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
|
||||||
|
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
|
||||||
|
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
|
||||||
|
oauth: [displayName: "The Home Remote", displayLink: "http://thehomeremote.com/"])
|
||||||
|
|
||||||
|
|
||||||
|
preferences {
|
||||||
|
section() {
|
||||||
|
input "accelerationSensors", "capability.accelerationSensor",title: "Acceleration Sensors", multiple: true, required: false
|
||||||
|
input "alarms", "capability.alarm",title: "Alarms", multiple: true, required: false
|
||||||
|
input "batteries", "capability.battery",title: "Batteries", multiple: true, required: false
|
||||||
|
input "beacons", "capability.beacon",title: "Beacons", multiple: true, required: false
|
||||||
|
input "buttonGroup", "capability.button",title: "Buttons", multiple: true, required: false
|
||||||
|
input "carbonMonoxideDetectors", "capability.carbonMonoxideDetector",title: "CO Detectors", multiple: true, required: false
|
||||||
|
input "colorControls", "capability.colorControl",title: "Color Lights", multiple: true, required: false
|
||||||
|
input "contactSensors", "capability.contactSensor",title: "Contact Sensors", multiple: true, required: false
|
||||||
|
input "doorControls", "capability.doorControl",title: "Door Controllers", multiple: true, required: false
|
||||||
|
input "energyMeters", "capability.energyMeter",title: "Energy Meters", multiple: true, required: false
|
||||||
|
input "illuminanceMeasurements", "capability.illuminanceMeasurement",title: "Illuminance Sensors", multiple: true, required: false
|
||||||
|
input "imageCaptures", "capability.imageCapture",title: "Cameras", multiple: true, required: false
|
||||||
|
input "locks", "capability.lock",title: "Locks", multiple: true, required: false
|
||||||
|
input "mediaControllers", "capability.mediaController",title: "Media Controllers", multiple: true, required: false
|
||||||
|
input "momentaries", "capability.momentary",title: "Momentary Buttons", multiple: true, required: false
|
||||||
|
input "motionSensors", "capability.motionSensor",title: "Motion Sensors", multiple: true, required: false
|
||||||
|
input "musicPlayers", "capability.musicPlayer",title: "Music Players", multiple: true, required: false
|
||||||
|
input "powerMeters", "capability.powerMeter",title: "Power Meters", multiple: true, required: false
|
||||||
|
input "presenceSensors", "capability.presenceSensor",title: "Presence Sensors", multiple: true, required: false
|
||||||
|
input "relativeHumidityMeasurements", "capability.relativeHumidityMeasurement",title: "Humidity Sensors", multiple: true, required: false
|
||||||
|
input "relaySwitches", "capability.relaySwitch",title: "Relays", multiple: true, required: false
|
||||||
|
input "signalStrengths", "capability.signalStrength",title: "Signal Strengths", multiple: true, required: false
|
||||||
|
input "sleepSensors", "capability.sleepSensor",title: "Sleep Sensors", multiple: true, required: false
|
||||||
|
input "smokeDetectors", "capability.smokeDetector",title: "Smoke Detectors", multiple: true, required: false
|
||||||
|
input "speechSyntheses", "capability.speechSynthesis",title: "Speech Syntheses", multiple: true, required: false
|
||||||
|
input "stepSensors", "capability.stepSensor",title: "Step Sensors", multiple: true, required: false
|
||||||
|
input "switches", "capability.switch",title: "Switches", multiple: true, required: false
|
||||||
|
input "switchLevels", "capability.switchLevel",title: "Dimmers", multiple: true, required: false
|
||||||
|
input "temperatureMeasurements", "capability.temperatureMeasurement",title: "Temperature Sensors", multiple: true, required: false
|
||||||
|
input "thermostats", "capability.thermostat",title: "Thermostats", multiple: true, required: false
|
||||||
|
input "threeAxes", "capability.threeAxis",title: "Three axis Sensors", multiple: true, required: false
|
||||||
|
input "tones", "capability.tone",title: "Tones", multiple: true, required: false
|
||||||
|
input "touchSensors", "capability.touchSensor",title: "Touch Sensors", multiple: true, required: false
|
||||||
|
input "valves", "capability.valve",title: "Valves", multiple: true, required: false
|
||||||
|
input "waterSensors", "capability.waterSensor",title: "Water Sensors", multiple: true, required: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mappings {
|
||||||
|
path("/GetCurrentValues") {
|
||||||
|
action: [
|
||||||
|
GET: "getCurrentValues"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/GetCurrentValuesWithDisplayName") {
|
||||||
|
action: [
|
||||||
|
GET: "getCurrentValuesWithDisplayName"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/GetRoutines") {
|
||||||
|
action: [
|
||||||
|
GET: "getRoutines"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/ExecuteCommand") {
|
||||||
|
action: [
|
||||||
|
PUT: "executeCommand"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/ExecuteRoutine") {
|
||||||
|
action: [
|
||||||
|
PUT: "executeRoutine"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def getCurrentValues() {
|
||||||
|
def resp = []
|
||||||
|
|
||||||
|
accelerationSensors.each {
|
||||||
|
resp << [id: it.id, capability: "AccelerationSensor", attribute: "acceleration", value: it.currentValue("acceleration")]
|
||||||
|
}
|
||||||
|
|
||||||
|
alarms.each {
|
||||||
|
resp << [id: it.id, capability: "Alarm", attribute: "alarm", value: it.currentValue("alarm")]
|
||||||
|
}
|
||||||
|
|
||||||
|
batteries.each {
|
||||||
|
resp << [id: it.id, capability: "Battery", attribute: "battery", value: it.currentValue("battery")]
|
||||||
|
}
|
||||||
|
|
||||||
|
beacons.each {
|
||||||
|
resp << [id: it.id, capability: "Beacon", attribute: "presence", value: it.currentValue("presence")]
|
||||||
|
}
|
||||||
|
|
||||||
|
buttonGroup.each {
|
||||||
|
resp << [id: it.id, capability: "Button", attribute: "button", value: it.currentValue("button")]
|
||||||
|
}
|
||||||
|
|
||||||
|
carbonMonoxideDetectors.each {
|
||||||
|
resp << [id: it.id, capability: "CarbonMonoxideDetector", attribute: "carbonMonoxide", value: it.currentValue("carbonMonoxide")]
|
||||||
|
}
|
||||||
|
|
||||||
|
colorControls.each {
|
||||||
|
resp << [id: it.id, capability: "ColorControl", attribute: "hue", value: it.currentValue("hue")]
|
||||||
|
}
|
||||||
|
|
||||||
|
colorControls.each {
|
||||||
|
resp << [id: it.id, capability: "ColorControl", attribute: "saturation", value: it.currentValue("saturation")]
|
||||||
|
}
|
||||||
|
|
||||||
|
colorControls.each {
|
||||||
|
resp << [id: it.id, capability: "ColorControl", attribute: "color", value: it.currentValue("color")]
|
||||||
|
}
|
||||||
|
|
||||||
|
contactSensors.each {
|
||||||
|
resp << [id: it.id, capability: "ContactSensor", attribute: "contact", value: it.currentValue("contact")]
|
||||||
|
}
|
||||||
|
|
||||||
|
doorControls.each {
|
||||||
|
resp << [id: it.id, capability: "DoorControl", attribute: "door", value: it.currentValue("door")]
|
||||||
|
}
|
||||||
|
|
||||||
|
energyMeters.each {
|
||||||
|
resp << [id: it.id, capability: "EnergyMeter", attribute: "energy", value: it.currentValue("energy")]
|
||||||
|
}
|
||||||
|
|
||||||
|
illuminanceMeasurements.each {
|
||||||
|
resp << [id: it.id, capability: "IlluminanceMeasurement", attribute: "illuminance", value: it.currentValue("illuminance")]
|
||||||
|
}
|
||||||
|
|
||||||
|
imageCaptures.each {
|
||||||
|
resp << [id: it.id, capability: "ImageCapture", attribute: "image", value: it.currentValue("image")]
|
||||||
|
}
|
||||||
|
|
||||||
|
locks.each {
|
||||||
|
resp << [id: it.id, capability: "Lock", attribute: "lock", value: it.currentValue("lock")]
|
||||||
|
}
|
||||||
|
|
||||||
|
mediaControllers.each {
|
||||||
|
resp << [id: it.id, capability: "MediaController", attribute: "activities", value: it.currentValue("activities")]
|
||||||
|
}
|
||||||
|
|
||||||
|
mediaControllers.each {
|
||||||
|
resp << [id: it.id, capability: "MediaController", attribute: "currentActivity", value: it.currentValue("currentActivity")]
|
||||||
|
}
|
||||||
|
|
||||||
|
motionSensors.each {
|
||||||
|
resp << [id: it.id, capability: "MotionSensor", attribute: "motion", value: it.currentValue("motion")]
|
||||||
|
}
|
||||||
|
|
||||||
|
musicPlayers.each {
|
||||||
|
resp << [id: it.id, capability: "MusicPlayer", attribute: "status", value: it.currentValue("status")]
|
||||||
|
}
|
||||||
|
|
||||||
|
musicPlayers.each {
|
||||||
|
resp << [id: it.id, capability: "MusicPlayer", attribute: "level", value: it.currentValue("level")]
|
||||||
|
}
|
||||||
|
|
||||||
|
musicPlayers.each {
|
||||||
|
resp << [id: it.id, capability: "MusicPlayer", attribute: "trackDescription", value: it.currentValue("trackDescription")]
|
||||||
|
}
|
||||||
|
|
||||||
|
musicPlayers.each {
|
||||||
|
resp << [id: it.id, capability: "MusicPlayer", attribute: "trackData", value: it.currentValue("trackData")]
|
||||||
|
}
|
||||||
|
|
||||||
|
musicPlayers.each {
|
||||||
|
resp << [id: it.id, capability: "MusicPlayer", attribute: "mute", value: it.currentValue("mute")]
|
||||||
|
}
|
||||||
|
|
||||||
|
powerMeters.each {
|
||||||
|
resp << [id: it.id, capability: "PowerMeter", attribute: "power", value: it.currentValue("power")]
|
||||||
|
}
|
||||||
|
|
||||||
|
presenceSensors.each {
|
||||||
|
resp << [id: it.id, capability: "PresenceSensor", attribute: "presence", value: it.currentValue("presence")]
|
||||||
|
}
|
||||||
|
|
||||||
|
relativeHumidityMeasurements.each {
|
||||||
|
resp << [id: it.id, capability: "RelativeHumidityMeasurement", attribute: "humidity", value: it.currentValue("humidity")]
|
||||||
|
}
|
||||||
|
|
||||||
|
relaySwitches.each {
|
||||||
|
resp << [id: it.id, capability: "RelaySwitch", attribute: "switch", value: it.currentValue("switch")]
|
||||||
|
}
|
||||||
|
|
||||||
|
signalStrengths.each {
|
||||||
|
resp << [id: it.id, capability: "SignalStrength", attribute: "lqi", value: it.currentValue("lqi")]
|
||||||
|
}
|
||||||
|
|
||||||
|
signalStrengths.each {
|
||||||
|
resp << [id: it.id, capability: "SignalStrength", attribute: "rssi", value: it.currentValue("rssi")]
|
||||||
|
}
|
||||||
|
|
||||||
|
sleepSensors.each {
|
||||||
|
resp << [id: it.id, capability: "SleepSensor", attribute: "sleeping", value: it.currentValue("sleeping")]
|
||||||
|
}
|
||||||
|
|
||||||
|
smokeDetectors.each {
|
||||||
|
resp << [id: it.id, capability: "SmokeDetector", attribute: "smoke", value: it.currentValue("smoke")]
|
||||||
|
}
|
||||||
|
|
||||||
|
stepSensors.each {
|
||||||
|
resp << [id: it.id, capability: "StepSensor", attribute: "steps", value: it.currentValue("steps")]
|
||||||
|
}
|
||||||
|
|
||||||
|
stepSensors.each {
|
||||||
|
resp << [id: it.id, capability: "StepSensor", attribute: "goal", value: it.currentValue("goal")]
|
||||||
|
}
|
||||||
|
|
||||||
|
switches.each {
|
||||||
|
resp << [id: it.id, capability: "Switch", attribute: "switch", value: it.currentValue("switch")]
|
||||||
|
}
|
||||||
|
|
||||||
|
switchLevels.each {
|
||||||
|
resp << [id: it.id, capability: "SwitchLevel", attribute: "level", value: it.currentValue("level")]
|
||||||
|
}
|
||||||
|
|
||||||
|
temperatureMeasurements.each {
|
||||||
|
resp << [id: it.id, capability: "TemperatureMeasurement", attribute: "temperature", value: it.currentValue("temperature")]
|
||||||
|
}
|
||||||
|
|
||||||
|
thermostats.each {
|
||||||
|
resp << [id: it.id, capability: "Thermostat", attribute: "temperature", value: it.currentValue("temperature")]
|
||||||
|
}
|
||||||
|
|
||||||
|
thermostats.each {
|
||||||
|
resp << [id: it.id, capability: "Thermostat", attribute: "heatingSetpoint", value: it.currentValue("heatingSetpoint")]
|
||||||
|
}
|
||||||
|
|
||||||
|
thermostats.each {
|
||||||
|
resp << [id: it.id, capability: "Thermostat", attribute: "coolingSetpoint", value: it.currentValue("coolingSetpoint")]
|
||||||
|
}
|
||||||
|
|
||||||
|
//Commented out on 7/23/2016. This randomly started throwing number format exceptions with either my ecobee or Lyric thermostat.
|
||||||
|
//thermostats.each {
|
||||||
|
// resp << [id: it.id, capability: "Thermostat", attribute: "thermostatSetpoint", value: it.currentValue("thermostatSetpoint")]
|
||||||
|
//}
|
||||||
|
|
||||||
|
thermostats.each {
|
||||||
|
resp << [id: it.id, capability: "Thermostat", attribute: "thermostatMode", value: it.currentValue("thermostatMode")]
|
||||||
|
}
|
||||||
|
|
||||||
|
thermostats.each {
|
||||||
|
resp << [id: it.id, capability: "Thermostat", attribute: "thermostatFanMode", value: it.currentValue("thermostatFanMode")]
|
||||||
|
}
|
||||||
|
|
||||||
|
thermostats.each {
|
||||||
|
resp << [id: it.id, capability: "Thermostat", attribute: "thermostatOperatingState", value: it.currentValue("thermostatOperatingState")]
|
||||||
|
}
|
||||||
|
|
||||||
|
threeAxes.each {
|
||||||
|
resp << [id: it.id, capability: "ThreeAxis", attribute: "threeAxis", value: it.currentValue("threeAxis")]
|
||||||
|
}
|
||||||
|
|
||||||
|
touchSensors.each {
|
||||||
|
resp << [id: it.id, capability: "TouchSensor", attribute: "touch", value: it.currentValue("touch")]
|
||||||
|
}
|
||||||
|
|
||||||
|
valves.each {
|
||||||
|
resp << [id: it.id, capability: "Valve", attribute: "contact", value: it.currentValue("contact")]
|
||||||
|
}
|
||||||
|
|
||||||
|
waterSensors.each {
|
||||||
|
resp << [id: it.id, capability: "WaterSensor", attribute: "water", value: it.currentValue("water")]
|
||||||
|
}
|
||||||
|
|
||||||
|
//resp << [id: 0, capability: "Heartbeat", attribute: "heartbeat", value: String.valueOf(state.heartbeat)]
|
||||||
|
|
||||||
|
state.heartbeat = !state.heartbeat
|
||||||
|
|
||||||
|
return resp
|
||||||
|
}
|
||||||
|
|
||||||
|
def getCurrentValuesWithDisplayName() {
|
||||||
|
def resp = []
|
||||||
|
|
||||||
|
accelerationSensors.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "AccelerationSensor", attribute: "acceleration", value: it.currentValue("acceleration")]
|
||||||
|
}
|
||||||
|
|
||||||
|
alarms.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "Alarm", attribute: "alarm", value: it.currentValue("alarm")]
|
||||||
|
}
|
||||||
|
|
||||||
|
batteries.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "Battery", attribute: "battery", value: it.currentValue("battery")]
|
||||||
|
}
|
||||||
|
|
||||||
|
beacons.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "Beacon", attribute: "presence", value: it.currentValue("presence")]
|
||||||
|
}
|
||||||
|
|
||||||
|
buttonGroup.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "Button", attribute: "button", value: it.currentValue("button")]
|
||||||
|
}
|
||||||
|
|
||||||
|
carbonMonoxideDetectors.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "CarbonMonoxideDetector", attribute: "carbonMonoxide", value: it.currentValue("carbonMonoxide")]
|
||||||
|
}
|
||||||
|
|
||||||
|
colorControls.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "ColorControl", attribute: "hue", value: it.currentValue("hue")]
|
||||||
|
}
|
||||||
|
|
||||||
|
colorControls.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "ColorControl", attribute: "saturation", value: it.currentValue("saturation")]
|
||||||
|
}
|
||||||
|
|
||||||
|
colorControls.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "ColorControl", attribute: "color", value: it.currentValue("color")]
|
||||||
|
}
|
||||||
|
|
||||||
|
contactSensors.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "ContactSensor", attribute: "contact", value: it.currentValue("contact")]
|
||||||
|
}
|
||||||
|
|
||||||
|
doorControls.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "DoorControl", attribute: "door", value: it.currentValue("door")]
|
||||||
|
}
|
||||||
|
|
||||||
|
energyMeters.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "EnergyMeter", attribute: "energy", value: it.currentValue("energy")]
|
||||||
|
}
|
||||||
|
|
||||||
|
illuminanceMeasurements.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "IlluminanceMeasurement", attribute: "illuminance", value: it.currentValue("illuminance")]
|
||||||
|
}
|
||||||
|
|
||||||
|
imageCaptures.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "ImageCapture", attribute: "image", value: it.currentValue("image")]
|
||||||
|
}
|
||||||
|
|
||||||
|
locks.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "Lock", attribute: "lock", value: it.currentValue("lock")]
|
||||||
|
}
|
||||||
|
|
||||||
|
mediaControllers.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "MediaController", attribute: "activities", value: it.currentValue("activities")]
|
||||||
|
}
|
||||||
|
|
||||||
|
mediaControllers.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "MediaController", attribute: "currentActivity", value: it.currentValue("currentActivity")]
|
||||||
|
}
|
||||||
|
|
||||||
|
motionSensors.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "MotionSensor", attribute: "motion", value: it.currentValue("motion")]
|
||||||
|
}
|
||||||
|
|
||||||
|
musicPlayers.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "MusicPlayer", attribute: "status", value: it.currentValue("status")]
|
||||||
|
}
|
||||||
|
|
||||||
|
musicPlayers.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "MusicPlayer", attribute: "level", value: it.currentValue("level")]
|
||||||
|
}
|
||||||
|
|
||||||
|
musicPlayers.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "MusicPlayer", attribute: "trackDescription", value: it.currentValue("trackDescription")]
|
||||||
|
}
|
||||||
|
|
||||||
|
musicPlayers.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "MusicPlayer", attribute: "trackData", value: it.currentValue("trackData")]
|
||||||
|
}
|
||||||
|
|
||||||
|
musicPlayers.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "MusicPlayer", attribute: "mute", value: it.currentValue("mute")]
|
||||||
|
}
|
||||||
|
|
||||||
|
powerMeters.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "PowerMeter", attribute: "power", value: it.currentValue("power")]
|
||||||
|
}
|
||||||
|
|
||||||
|
presenceSensors.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "PresenceSensor", attribute: "presence", value: it.currentValue("presence")]
|
||||||
|
}
|
||||||
|
|
||||||
|
relativeHumidityMeasurements.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "RelativeHumidityMeasurement", attribute: "humidity", value: it.currentValue("humidity")]
|
||||||
|
}
|
||||||
|
|
||||||
|
relaySwitches.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "RelaySwitch", attribute: "switch", value: it.currentValue("switch")]
|
||||||
|
}
|
||||||
|
|
||||||
|
signalStrengths.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "SignalStrength", attribute: "lqi", value: it.currentValue("lqi")]
|
||||||
|
}
|
||||||
|
|
||||||
|
signalStrengths.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "SignalStrength", attribute: "rssi", value: it.currentValue("rssi")]
|
||||||
|
}
|
||||||
|
|
||||||
|
sleepSensors.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "SleepSensor", attribute: "sleeping", value: it.currentValue("sleeping")]
|
||||||
|
}
|
||||||
|
|
||||||
|
smokeDetectors.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "SmokeDetector", attribute: "smoke", value: it.currentValue("smoke")]
|
||||||
|
}
|
||||||
|
|
||||||
|
stepSensors.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "StepSensor", attribute: "steps", value: it.currentValue("steps")]
|
||||||
|
}
|
||||||
|
|
||||||
|
stepSensors.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "StepSensor", attribute: "goal", value: it.currentValue("goal")]
|
||||||
|
}
|
||||||
|
|
||||||
|
switches.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "Switch", attribute: "switch", value: it.currentValue("switch")]
|
||||||
|
}
|
||||||
|
|
||||||
|
switchLevels.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "SwitchLevel", attribute: "level", value: it.currentValue("level")]
|
||||||
|
}
|
||||||
|
|
||||||
|
temperatureMeasurements.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "TemperatureMeasurement", attribute: "temperature", value: it.currentValue("temperature")]
|
||||||
|
}
|
||||||
|
|
||||||
|
thermostats.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "Thermostat", attribute: "temperature", value: it.currentValue("temperature")]
|
||||||
|
}
|
||||||
|
|
||||||
|
thermostats.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "Thermostat", attribute: "heatingSetpoint", value: it.currentValue("heatingSetpoint")]
|
||||||
|
}
|
||||||
|
|
||||||
|
thermostats.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "Thermostat", attribute: "coolingSetpoint", value: it.currentValue("coolingSetpoint")]
|
||||||
|
}
|
||||||
|
|
||||||
|
//Commented out on 7/23/2016. This randomly started throwing number format exceptions with either my ecobee or Lyric thermostat.
|
||||||
|
//thermostats.each {
|
||||||
|
// resp << [id: it.id, displayName: it.displayName, capability: "Thermostat", attribute: "thermostatSetpoint", value: it.currentValue("thermostatSetpoint")]
|
||||||
|
//}
|
||||||
|
|
||||||
|
thermostats.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "Thermostat", attribute: "thermostatMode", value: it.currentValue("thermostatMode")]
|
||||||
|
}
|
||||||
|
|
||||||
|
thermostats.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "Thermostat", attribute: "thermostatFanMode", value: it.currentValue("thermostatFanMode")]
|
||||||
|
}
|
||||||
|
|
||||||
|
thermostats.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "Thermostat", attribute: "thermostatOperatingState", value: it.currentValue("thermostatOperatingState")]
|
||||||
|
}
|
||||||
|
|
||||||
|
threeAxes.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "ThreeAxis", attribute: "threeAxis", value: it.currentValue("threeAxis")]
|
||||||
|
}
|
||||||
|
|
||||||
|
touchSensors.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "TouchSensor", attribute: "touch", value: it.currentValue("touch")]
|
||||||
|
}
|
||||||
|
|
||||||
|
valves.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "Valve", attribute: "contact", value: it.currentValue("contact")]
|
||||||
|
}
|
||||||
|
|
||||||
|
waterSensors.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "WaterSensor", attribute: "water", value: it.currentValue("water")]
|
||||||
|
}
|
||||||
|
|
||||||
|
momentaries.each {
|
||||||
|
resp << [id: it.id, displayName: it.displayName, capability: "Momentary", attribute: "", value: ""]
|
||||||
|
}
|
||||||
|
|
||||||
|
//resp << [id: 0, displayName: "Heartbeat", capability: "Heartbeat", attribute: "heartbeat", value: state.heartbeat]
|
||||||
|
|
||||||
|
return resp
|
||||||
|
}
|
||||||
|
|
||||||
|
def getDevices(capability){
|
||||||
|
|
||||||
|
def result
|
||||||
|
|
||||||
|
switch (capability) {
|
||||||
|
case "Alarm":
|
||||||
|
result = alarms
|
||||||
|
break
|
||||||
|
case "ColorControl":
|
||||||
|
result = colorControls
|
||||||
|
break
|
||||||
|
case "DoorControl":
|
||||||
|
result = doorControls
|
||||||
|
break
|
||||||
|
case "ImageCapture":
|
||||||
|
result = imageCaptures
|
||||||
|
break
|
||||||
|
case "Lock":
|
||||||
|
result = locks
|
||||||
|
break
|
||||||
|
case "MediaController":
|
||||||
|
result = mediaControllers
|
||||||
|
break
|
||||||
|
case "Momentary":
|
||||||
|
result = momentaries
|
||||||
|
break
|
||||||
|
case "MusicPlayer":
|
||||||
|
result = musicPlayers
|
||||||
|
break
|
||||||
|
case "RelaySwitch":
|
||||||
|
result = relaySwitches
|
||||||
|
break
|
||||||
|
case "SpeechSynthesis":
|
||||||
|
result = speechSyntheses
|
||||||
|
break
|
||||||
|
case "Switch":
|
||||||
|
result = switches
|
||||||
|
break
|
||||||
|
case "SwitchLevel":
|
||||||
|
result = switchLevels
|
||||||
|
break
|
||||||
|
case "Thermostat":
|
||||||
|
result = thermostats
|
||||||
|
break
|
||||||
|
case "ThermostatCoolingSetpoint":
|
||||||
|
result = thermostatCoolingSetpoints
|
||||||
|
break
|
||||||
|
case "ThermostatFanMode":
|
||||||
|
result = thermostatFanModes
|
||||||
|
break
|
||||||
|
case "ThermostatHeatingSetpoint":
|
||||||
|
result = thermostatHeatingSetpoints
|
||||||
|
break
|
||||||
|
case "ThermostatMode":
|
||||||
|
result = thermostatModes
|
||||||
|
break
|
||||||
|
case "Tone":
|
||||||
|
result = tones
|
||||||
|
break
|
||||||
|
case "Valve":
|
||||||
|
result = valves
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
result = valves
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
def getDoorControlCommand(value){
|
||||||
|
def result
|
||||||
|
switch (value) {
|
||||||
|
case "closed":
|
||||||
|
result = "close"
|
||||||
|
break
|
||||||
|
case "open":
|
||||||
|
result = "open"
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
result = value
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
def getLockCommand(value){
|
||||||
|
def result
|
||||||
|
switch (value) {
|
||||||
|
case "locked":
|
||||||
|
result = "lock"
|
||||||
|
break
|
||||||
|
case "unlocked":
|
||||||
|
result = "unlock"
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
result = value
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
def getMuteCommand(value){
|
||||||
|
def result
|
||||||
|
switch (value) {
|
||||||
|
case "muted":
|
||||||
|
result = "mute"
|
||||||
|
break
|
||||||
|
case "unmuted":
|
||||||
|
result = "unmute"
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
result = value
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
def getContactCommand(value){
|
||||||
|
def result
|
||||||
|
switch (value) {
|
||||||
|
case "closed":
|
||||||
|
result = "close"
|
||||||
|
break
|
||||||
|
case "open":
|
||||||
|
result = "open"
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
result = value
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
def getRoutines() {
|
||||||
|
return location.helloHome?.getPhrases()*.label
|
||||||
|
}
|
||||||
|
|
||||||
|
def getThermostatFanModeCommand(value){
|
||||||
|
def result
|
||||||
|
switch (value) {
|
||||||
|
case "on":
|
||||||
|
result = "fanOn"
|
||||||
|
break
|
||||||
|
case "auto":
|
||||||
|
result = "fanAuto"
|
||||||
|
break
|
||||||
|
case "circulate":
|
||||||
|
result = "fanCirculate"
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
result = value
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
void executeCommand() {
|
||||||
|
def deviceId = request.JSON?.deviceId
|
||||||
|
def capability = request.JSON?.capability
|
||||||
|
def attribute = request.JSON?.attribute
|
||||||
|
def value = request.JSON?.value
|
||||||
|
if (deviceId) {
|
||||||
|
def devices = getDevices(capability)
|
||||||
|
def command
|
||||||
|
def valueIsParameter = false
|
||||||
|
def valueIsInteger = false
|
||||||
|
switch (attribute) {
|
||||||
|
case "hue":
|
||||||
|
command = "setHue"
|
||||||
|
valueIsParameter = true
|
||||||
|
valueIsInteger = true
|
||||||
|
break
|
||||||
|
case "saturation":
|
||||||
|
command = "setSaturation"
|
||||||
|
valueIsParameter = true
|
||||||
|
valueIsInteger = true
|
||||||
|
break
|
||||||
|
case "color":
|
||||||
|
command = "setColor"
|
||||||
|
def rgb = hexToRgb(value)
|
||||||
|
def hsl = rgbToHSL(rgb)
|
||||||
|
value = [hue:hsl.h.toInteger(), saturation:hsl.s.toInteger()]
|
||||||
|
valueIsParameter = true
|
||||||
|
break
|
||||||
|
case "level":
|
||||||
|
command = "setLevel"
|
||||||
|
valueIsParameter = true
|
||||||
|
valueIsInteger = true
|
||||||
|
break
|
||||||
|
case "heatingSetpoint":
|
||||||
|
command = "setHeatingSetpoint"
|
||||||
|
valueIsParameter = true
|
||||||
|
break
|
||||||
|
case "coolingSetpoint":
|
||||||
|
command = "setCoolingSetpoint"
|
||||||
|
valueIsParameter = true
|
||||||
|
break
|
||||||
|
case "currentActivity":
|
||||||
|
command = "startActivity"
|
||||||
|
valueIsParameter = true
|
||||||
|
break
|
||||||
|
case "door":
|
||||||
|
command = getDoorControlCommand(value)
|
||||||
|
break
|
||||||
|
case "lock":
|
||||||
|
command = getLockCommand(value)
|
||||||
|
break
|
||||||
|
case "mute":
|
||||||
|
command = getMuteCommand(value)
|
||||||
|
break
|
||||||
|
case "thermostatFanMode":
|
||||||
|
command = getThermostatFanModeCommand(value)
|
||||||
|
break
|
||||||
|
case "thermostatMode":
|
||||||
|
if (value == "emergency heat") {
|
||||||
|
command = "emergencyHeat"
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
command = value
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case "contact":
|
||||||
|
command = getContactCommand(value)
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
command = value
|
||||||
|
}
|
||||||
|
devices.each {
|
||||||
|
if (it.id == deviceId) {
|
||||||
|
// check that the device supports the specified command
|
||||||
|
// If not, return an error using httpError, providing a HTTP status code.
|
||||||
|
if (!it.hasCommand(command)) {
|
||||||
|
httpError(501, "$command is not a valid command for the device")
|
||||||
|
}
|
||||||
|
if(valueIsParameter){
|
||||||
|
if(valueIsInteger){
|
||||||
|
it."$command"(value as int)
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
it."$command"(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
it."$command"()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void executeRoutine() {
|
||||||
|
def routine = request.JSON?.routine
|
||||||
|
location.helloHome?.execute(routine)
|
||||||
|
}
|
||||||
|
|
||||||
|
def rgbToHSL(rgb) {
|
||||||
|
def r = rgb.r / 255
|
||||||
|
def g = rgb.g / 255
|
||||||
|
def b = rgb.b / 255
|
||||||
|
def h = 0
|
||||||
|
def s = 0
|
||||||
|
def l = 0
|
||||||
|
|
||||||
|
def var_min = [r,g,b].min()
|
||||||
|
def var_max = [r,g,b].max()
|
||||||
|
def del_max = var_max - var_min
|
||||||
|
|
||||||
|
l = (var_max + var_min) / 2
|
||||||
|
|
||||||
|
if (del_max == 0) {
|
||||||
|
h = 0
|
||||||
|
s = 0
|
||||||
|
} else {
|
||||||
|
if (l < 0.5) { s = del_max / (var_max + var_min) }
|
||||||
|
else { s = del_max / (2 - var_max - var_min) }
|
||||||
|
|
||||||
|
def del_r = (((var_max - r) / 6) + (del_max / 2)) / del_max
|
||||||
|
def del_g = (((var_max - g) / 6) + (del_max / 2)) / del_max
|
||||||
|
def del_b = (((var_max - b) / 6) + (del_max / 2)) / del_max
|
||||||
|
|
||||||
|
if (r == var_max) { h = del_b - del_g }
|
||||||
|
else if (g == var_max) { h = (1 / 3) + del_r - del_b }
|
||||||
|
else if (b == var_max) { h = (2 / 3) + del_g - del_r }
|
||||||
|
|
||||||
|
if (h < 0) { h += 1 }
|
||||||
|
if (h > 1) { h -= 1 }
|
||||||
|
}
|
||||||
|
def hsl = [:]
|
||||||
|
hsl = [h: h * 100, s: s * 100, l: l]
|
||||||
|
|
||||||
|
hsl
|
||||||
|
}
|
||||||
|
|
||||||
|
def hexToRgb(colorHex) {
|
||||||
|
def rrInt = Integer.parseInt(colorHex.substring(1,3),16)
|
||||||
|
def ggInt = Integer.parseInt(colorHex.substring(3,5),16)
|
||||||
|
def bbInt = Integer.parseInt(colorHex.substring(5,7),16)
|
||||||
|
|
||||||
|
def colorData = [:]
|
||||||
|
colorData = [r: rrInt, g: ggInt, b: bbInt]
|
||||||
|
colorData
|
||||||
|
}
|
||||||
|
|
||||||
|
def installed() {
|
||||||
|
state.heartbeat = false
|
||||||
|
}
|
||||||
|
|
||||||
|
def updated() {
|
||||||
|
state.heartbeat = false
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user