mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-21 05:10:50 +00:00
Compare commits
1 Commits
MSA-1918-2
...
MSA-1900-9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2640a9ac87 |
@@ -1,2 +0,0 @@
|
|||||||
.st-ignore
|
|
||||||
README.md
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
# Osotech Plant Link
|
|
||||||
|
|
||||||
Cloud Execution
|
|
||||||
|
|
||||||
Works with:
|
|
||||||
|
|
||||||
* [OSO Technologies PlantLink Soil Moisture Sensor](https://www.smartthings.com/works-with-smartthings/oso-technologies/oso-technologies-plantlink-soil-moisture-sensor)
|
|
||||||
|
|
||||||
## Table of contents
|
|
||||||
|
|
||||||
* [Capabilities](#capabilities)
|
|
||||||
* [Health](#device-health)
|
|
||||||
* [Troubleshooting](#troubleshooting)
|
|
||||||
|
|
||||||
## Capabilities
|
|
||||||
|
|
||||||
* **Sensor** - detects sensor events
|
|
||||||
* **Health Check** - indicates ability to get device health notifications
|
|
||||||
|
|
||||||
## Device Health
|
|
||||||
|
|
||||||
Plant Link sensor is a ZigBee sleepy device and checks in every 15 minutes.
|
|
||||||
Device-Watch allows 2 check-in misses from device plus some lag time. So Check-in interval = (2*15 + 2)mins = 32 mins.
|
|
||||||
|
|
||||||
* __32min__ checkInterval
|
|
||||||
|
|
||||||
## Troubleshooting
|
|
||||||
|
|
||||||
If the device doesn't pair when trying from the SmartThings mobile app, it is possible that the sensor is out of range.
|
|
||||||
Pairing needs to be tried again by placing the sensor closer to the hub.
|
|
||||||
Instructions related to pairing, resetting and removing the different motion sensors from SmartThings can be found in the following links
|
|
||||||
for the different models:
|
|
||||||
* [OSO Technologies PlantLink Soil Moisture Sensor Troubleshooting Tips](https://support.smartthings.com/hc/en-us/articles/206868986-PlantLink-Soil-Moisture-Sensor)
|
|
||||||
@@ -24,7 +24,6 @@ import groovy.json.JsonBuilder
|
|||||||
metadata {
|
metadata {
|
||||||
definition (name: "PlantLink", namespace: "OsoTech", author: "Oso Technologies") {
|
definition (name: "PlantLink", namespace: "OsoTech", author: "Oso Technologies") {
|
||||||
capability "Sensor"
|
capability "Sensor"
|
||||||
capability "Health Check"
|
|
||||||
|
|
||||||
command "setStatusIcon"
|
command "setStatusIcon"
|
||||||
command "setPlantFuelLevel"
|
command "setPlantFuelLevel"
|
||||||
@@ -71,16 +70,6 @@ metadata {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def updated() {
|
|
||||||
// Device-Watch allows 2 check-in misses from device
|
|
||||||
sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID])
|
|
||||||
}
|
|
||||||
|
|
||||||
def installed() {
|
|
||||||
// Device-Watch allows 2 check-in misses from device
|
|
||||||
sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID])
|
|
||||||
}
|
|
||||||
|
|
||||||
def setStatusIcon(value){
|
def setStatusIcon(value){
|
||||||
def status = ''
|
def status = ''
|
||||||
switch (value) {
|
switch (value) {
|
||||||
@@ -172,4 +161,4 @@ def parseDescriptionAsMap(description) {
|
|||||||
map += []
|
map += []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,7 @@ Works with:
|
|||||||
|
|
||||||
## Device Health
|
## Device Health
|
||||||
|
|
||||||
Plant Link sensor is a ZigBee sleepy device and checks in every 15 minutes.
|
Plant Link sensor is a Z-wave sleepy device and checks in every 15 minutes.
|
||||||
Device-Watch allows 2 check-in misses from device plus some lag time. So Check-in interval = (2*15 + 2)mins = 32 mins.
|
Device-Watch allows 2 check-in misses from device plus some lag time. So Check-in interval = (2*15 + 2)mins = 32 mins.
|
||||||
|
|
||||||
* __32min__ checkInterval
|
* __32min__ checkInterval
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
.st-ignore
|
|
||||||
README.md
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
# Smartalert Siren
|
|
||||||
|
|
||||||
Cloud Execution
|
|
||||||
|
|
||||||
Works with:
|
|
||||||
|
|
||||||
* [FortrezZ Siren Strobe Alarm](https://www.smartthings.com/works-with-smartthings/other/fortrezz-water-valve)
|
|
||||||
|
|
||||||
## Table of contents
|
|
||||||
|
|
||||||
* [Capabilities](#capabilities)
|
|
||||||
* [Health](#device-health)
|
|
||||||
* [Troubleshooting](#troubleshooting)
|
|
||||||
|
|
||||||
## Capabilities
|
|
||||||
|
|
||||||
* **Actuator** - represents that a Device has commands
|
|
||||||
* **Switch** - can detect state (possible values: on/off)
|
|
||||||
* **Sensor** - detects sensor events
|
|
||||||
* **Alarm** - allows for interacting with devices that serve as alarms
|
|
||||||
* **Health Check** - indicates ability to get device health notifications
|
|
||||||
|
|
||||||
## Device Health
|
|
||||||
|
|
||||||
FortrezZ Siren Strobe Alarm is polled by the hub.
|
|
||||||
As of hubCore version 0.14.38 the hub sends up reports every 15 minutes regardless of whether the state changed.
|
|
||||||
Device-Watch allows 2 check-in misses from device plus some lag time. So Check-in interval = (2*15 + 2)mins = 32 mins.
|
|
||||||
Not to mention after going OFFLINE when the device is plugged back in, it might take a considerable amount of time for
|
|
||||||
the device to appear as ONLINE again. This is because if this listening device does not respond to two poll requests in a row,
|
|
||||||
it is not polled for 5 minutes by the hub. This can delay up the process of being marked ONLINE by quite some time.
|
|
||||||
|
|
||||||
* __32min__ checkInterval
|
|
||||||
|
|
||||||
## Troubleshooting
|
|
||||||
|
|
||||||
If the device doesn't pair when trying from the SmartThings mobile app, it is possible that the device is out of range.
|
|
||||||
Pairing needs to be tried again by placing the device closer to the hub.
|
|
||||||
Instructions related to pairing, resetting and removing the device from SmartThings can be found in the following link:
|
|
||||||
* [FortrezZ Siren Strobe Alarm Troubleshooting Tips](https://support.smartthings.com/hc/en-us/articles/202294760-FortrezZ-Siren-Strobe-Alarm)
|
|
||||||
@@ -21,12 +21,10 @@ metadata {
|
|||||||
capability "Switch"
|
capability "Switch"
|
||||||
capability "Sensor"
|
capability "Sensor"
|
||||||
capability "Alarm"
|
capability "Alarm"
|
||||||
capability "Health Check"
|
|
||||||
|
|
||||||
command "test"
|
command "test"
|
||||||
|
|
||||||
fingerprint deviceId: "0x1100", inClusters: "0x26,0x71"
|
fingerprint deviceId: "0x1100", inClusters: "0x26,0x71"
|
||||||
fingerprint mfr:"0084", prod:"0313", model:"010B", deviceJoinName: "FortrezZ Siren Strobe Alarm"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
simulator {
|
simulator {
|
||||||
@@ -70,16 +68,6 @@ metadata {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def installed() {
|
|
||||||
// Device-Watch simply pings if no device events received for 32min(checkInterval)
|
|
||||||
sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
|
|
||||||
}
|
|
||||||
|
|
||||||
def updated() {
|
|
||||||
// Device-Watch simply pings if no device events received for 32min(checkInterval)
|
|
||||||
sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
|
|
||||||
}
|
|
||||||
|
|
||||||
def on() {
|
def on() {
|
||||||
[
|
[
|
||||||
zwave.basicV1.basicSet(value: 0xFF).format(),
|
zwave.basicV1.basicSet(value: 0xFF).format(),
|
||||||
@@ -161,10 +149,3 @@ def createEvents(physicalgraph.zwave.commands.basicv1.BasicReport cmd)
|
|||||||
def zwaveEvent(physicalgraph.zwave.Command cmd) {
|
def zwaveEvent(physicalgraph.zwave.Command cmd) {
|
||||||
log.warn "UNEXPECTED COMMAND: $cmd"
|
log.warn "UNEXPECTED COMMAND: $cmd"
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* PING is used by Device-Watch in attempt to reach the Device
|
|
||||||
* */
|
|
||||||
def ping() {
|
|
||||||
secure(zwave.basicV1.basicGet())
|
|
||||||
}
|
|
||||||
@@ -192,10 +192,6 @@ private List<Map> parseAxis(List<Map> attrData) {
|
|||||||
def y = hexToSignedInt(attrData.find { it.attrInt == 0x0013 }?.value)
|
def y = hexToSignedInt(attrData.find { it.attrInt == 0x0013 }?.value)
|
||||||
def z = hexToSignedInt(attrData.find { it.attrInt == 0x0014 }?.value)
|
def z = hexToSignedInt(attrData.find { it.attrInt == 0x0014 }?.value)
|
||||||
|
|
||||||
if ([x, y ,z].any { it == null }) {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
def xyzResults = [:]
|
def xyzResults = [:]
|
||||||
if (device.getDataValue("manufacturer") == "SmartThings") {
|
if (device.getDataValue("manufacturer") == "SmartThings") {
|
||||||
// This mapping matches the current behavior of the Device Handler for the Centralite sensors
|
// This mapping matches the current behavior of the Device Handler for the Centralite sensors
|
||||||
@@ -376,10 +372,6 @@ def updated() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private hexToSignedInt(hexVal) {
|
private hexToSignedInt(hexVal) {
|
||||||
if (!hexVal) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
def unsignedVal = hexToInt(hexVal)
|
def unsignedVal = hexToInt(hexVal)
|
||||||
unsignedVal > 32767 ? unsignedVal - 65536 : unsignedVal
|
unsignedVal > 32767 ? unsignedVal - 65536 : unsignedVal
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,27 +70,19 @@ def parse(String description) {
|
|||||||
else {
|
else {
|
||||||
sendEvent(event)
|
sendEvent(event)
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
def descMap = zigbee.parseDescriptionAsMap(description)
|
else {
|
||||||
if (descMap && descMap.clusterInt == 0x0006 && descMap.commandInt == 0x07) {
|
def cluster = zigbee.parse(description)
|
||||||
if (descMap.data[0] == "00") {
|
if (cluster && cluster.clusterId == 0x0006 && cluster.command == 0x07) {
|
||||||
|
if (cluster.data[0] == 0x00){
|
||||||
log.debug "ON/OFF REPORTING CONFIG RESPONSE: " + cluster
|
log.debug "ON/OFF REPORTING CONFIG RESPONSE: " + cluster
|
||||||
sendEvent(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 "ON/OFF REPORTING CONFIG FAILED- error code:${cluster.data[0]}"
|
log.warn "ON/OFF REPORTING CONFIG FAILED- error code:${cluster.data[0]}"
|
||||||
}
|
}
|
||||||
} else if (device.getDataValue("manufacturer") == "sengled" && descMap && descMap.clusterInt == 0x0008 && descMap.attrInt == 0x0000) {
|
}
|
||||||
// This is being done because the sengled element touch incorrectly uses the value 0xFF for the max level.
|
else {
|
||||||
// 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.warn "DID NOT PARSE MESSAGE for description : $description"
|
||||||
log.debug zigbee.parseDescriptionAsMap(description)
|
log.debug zigbee.parseDescriptionAsMap(description)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Z-Wave Lock
|
# Z-Wave Switch
|
||||||
|
|
||||||
Cloud Execution
|
Cloud Execution
|
||||||
|
|
||||||
@@ -6,6 +6,7 @@ Works with:
|
|||||||
|
|
||||||
* [Yale Key Free Touchscreen Deadbolt (YRD240)](https://www.smartthings.com/works-with-smartthings/yale/yale-key-free-touchscreen-deadbolt-yrd240)
|
* [Yale Key Free Touchscreen Deadbolt (YRD240)](https://www.smartthings.com/works-with-smartthings/yale/yale-key-free-touchscreen-deadbolt-yrd240)
|
||||||
|
|
||||||
|
|
||||||
## Table of contents
|
## Table of contents
|
||||||
|
|
||||||
* [Capabilities](#capabilities)
|
* [Capabilities](#capabilities)
|
||||||
@@ -40,3 +41,5 @@ If the device doesn't pair when trying from the SmartThings mobile app, it is po
|
|||||||
Pairing needs to be tried again by placing the device closer to the hub.
|
Pairing needs to be tried again by placing the device closer to the hub.
|
||||||
Instructions related to pairing, resetting and removing the device from SmartThings can be found in the following link:
|
Instructions related to pairing, resetting and removing the device from SmartThings can be found in the following link:
|
||||||
* [General Z-Wave/ZigBee Yale Lock Troubleshooting](https://support.smartthings.com/hc/en-us/articles/205138400-How-to-connect-Yale-locks)
|
* [General Z-Wave/ZigBee Yale Lock Troubleshooting](https://support.smartthings.com/hc/en-us/articles/205138400-How-to-connect-Yale-locks)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
711
smartapps/app-home-ai/app-home-ai.src/app-home-ai.groovy
Normal file
711
smartapps/app-home-ai/app-home-ai.src/app-home-ai.groovy
Normal file
@@ -0,0 +1,711 @@
|
|||||||
|
definition(
|
||||||
|
name: "app.home.ai",
|
||||||
|
namespace: "app.home.ai",
|
||||||
|
author: "Eric Greer",
|
||||||
|
description: "SmartThings SmartApp for app.home.ai.",
|
||||||
|
category: "Fun & Social",
|
||||||
|
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// These are preferences displayed in the smart phone app
|
||||||
|
preferences {
|
||||||
|
// we need a settings section to enable subscriptions
|
||||||
|
section("Pick which devices home.ai will help you automate:"){
|
||||||
|
input "motion", "capability.motionSensor", title: "Choose motion sensors", required: false, multiple: true
|
||||||
|
input "contact", "capability.contactSensor", title: "Choose contact sensors", required: false, multiple: true
|
||||||
|
input "lightswitch", "capability.switch", title: "Choose normal power switches", required: false, multiple: true
|
||||||
|
input "lightswitchlevel", "capability.switchLevel", title: "Choose dimmer power switches", required: false, multiple: true
|
||||||
|
input "presence", "capability.presenceSensor", title: "Choose presence sensors", required: false, multiple: true
|
||||||
|
// removed in prod until dual-signal devices are supported
|
||||||
|
//input "tempSensor", "capability.temperatureMeasurement", title: "Choose temperature sensors", required: false, multiple: true
|
||||||
|
//input "humidity", "capability.relativeHumidityMeasurement", title: "Choose humidity sensors", required: false, multiple: true
|
||||||
|
input "waterSensor", "capability.waterSensor", title: "Choose water sensors", required: false, multiple: true
|
||||||
|
input "lock", "capability.lock", title: "Pick Door Locks", required: false, multiple: true
|
||||||
|
input "garagedoor", "capability.garageDoorControl", title: "Pick garage doors", required: false, multiple: true
|
||||||
|
input "touchsensor", "capability.touchSensor", title: "Pick touch sensors", required: false, multiple: true
|
||||||
|
input "speechparser", "capability.speechRecognition", title: "Pick speech recognizers", required: false, multiple: true
|
||||||
|
input "soundsensor", "capability.soundSensor", title: "Pick sound sensors", required: false, multiple: true
|
||||||
|
input "smokedetector", "capability.smokeDetector", title: "Pick smoke detectors", required: false, multiple: true
|
||||||
|
input "sleepsensor", "capability.sleepSensor", title: "Pick sleep sensors", required: false, multiple: true
|
||||||
|
input "carbonsensor", "capability.carbonMonoxideDetector", title: "Pick carbon monoxide detectors", required: false, multiple: true
|
||||||
|
input "button", "capability.button", title: "Pick buttons", required: false, multiple: true
|
||||||
|
input "beacon", "capability.beacon", title: "Pick beacons", required: false, multiple: true
|
||||||
|
input "alarm", "capability.alarm", title: "Pick alarms", required: false, multiple: true
|
||||||
|
input "thermostat", "capability.thermostat", title: "Pick thermostats", required: false, multiple: true
|
||||||
|
input "voltage", "capability.voltageMeasurement", title: "Pick voltage sensors", required: false, multiple: true
|
||||||
|
input "windowshade", "capability.windowShade", title: "Pick window shades", required: false, multiple: true
|
||||||
|
input "powermeter", "capability.powerMeter", title: "Pick power meters", required: false, multiple: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// vlaues for security system are 'away', 'stay', or 'off'
|
||||||
|
// off security
|
||||||
|
def offSecurity() {
|
||||||
|
sendLocationEvent(
|
||||||
|
name: "alarmSystemStatus",
|
||||||
|
value: "off",
|
||||||
|
displayed: false,
|
||||||
|
isStateChange: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// stay security
|
||||||
|
def staySecurity() {
|
||||||
|
sendLocationEvent(
|
||||||
|
name: "alarmSystemStatus",
|
||||||
|
value: "stay",
|
||||||
|
displayed: false,
|
||||||
|
isStateChange: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// away security
|
||||||
|
def awaySecurity() {
|
||||||
|
sendLocationEvent(
|
||||||
|
name: "alarmSystemStatus",
|
||||||
|
value: "away",
|
||||||
|
displayed: false,
|
||||||
|
isStateChange: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets window shade open temperature
|
||||||
|
def setWindowShadeOpen() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setWindowShadeOpen command recieved ${deviceID}")
|
||||||
|
windowshade.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating window shade because it is the one specified: ${deviceID}");
|
||||||
|
it.open()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting window shade because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets window shade close temperature
|
||||||
|
def setWindowShadeClosed() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setWindowShadeClosed command recieved ${deviceID}")
|
||||||
|
windowshade.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating window shade because it is the one specified: ${deviceID}");
|
||||||
|
it.close()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting window shade because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets thermostat heating temperature
|
||||||
|
def setThermostatHeatTemp() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setThermostatHeat command recieved ${deviceID}")
|
||||||
|
thermostat.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating thermostat because it is the one specified: ${deviceID}");
|
||||||
|
it.setHeatingSetpoint(params.temp)
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting thermostat because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets thermostat cooling temperature
|
||||||
|
def setThermostatCoolTemp() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setThermostatCool command recieved ${deviceID}")
|
||||||
|
thermostat.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating thermostat because it is the one specified: ${deviceID}");
|
||||||
|
it.setCoolingSetpoint(params.temp)
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting thermostat because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets thermostat off
|
||||||
|
def setThermostatOff() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setThermostatOff command recieved ${deviceID}")
|
||||||
|
thermostat.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating thermostat because it is the one specified: ${deviceID}");
|
||||||
|
it.off()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting thermostat because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets thermostat to heat
|
||||||
|
def setThermostatHeat() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setThermostatHeat command recieved ${deviceID}")
|
||||||
|
thermostat.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating thermostat because it is the one specified: ${deviceID}");
|
||||||
|
it.heat()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting thermostat because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets thermostat to cool
|
||||||
|
def setThermostatCool() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setThermostatCool command recieved ${deviceID}")
|
||||||
|
thermostat.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating thermostat because it is the one specified: ${deviceID}");
|
||||||
|
it.cool()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting thermostat because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets thermostat mode
|
||||||
|
def setThermostatMode() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setThermostatMode command recieved ${deviceID}")
|
||||||
|
thermostat.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating thermostat because it is the one specified: ${deviceID}");
|
||||||
|
it.setThermostatMode(params.mode)
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting thermostat because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets thermostat fan mode
|
||||||
|
def setThermostatFanMode() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setThermostatFanMode command recieved ${deviceID}")
|
||||||
|
thermostat.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating thermostat because it is the one specified: ${deviceID}");
|
||||||
|
it.setThermostatFanMode(params.mode)
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting thermostat because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sends an alarm strobe
|
||||||
|
def strobeAlarm() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Alarm strobe command recieved ${deviceID}")
|
||||||
|
alarm.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating alarm because it is the one specified: ${deviceID}");
|
||||||
|
it.strobe()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting alarm because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sends an alarm siren
|
||||||
|
def sirenAlarm() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Alarm siren command recieved ${deviceID}")
|
||||||
|
alarm.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating alarm because it is the one specified: ${deviceID}");
|
||||||
|
it.siren()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting alarm because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// disables an alarm siren
|
||||||
|
def silenceAlarm() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Alarm silence command recieved ${deviceID}")
|
||||||
|
alarm.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating alarm because it is the one specified: ${deviceID}");
|
||||||
|
it.off()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting alarm because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// opens a garage door
|
||||||
|
def openGarage() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Open Garage command recieved ${deviceID}")
|
||||||
|
garagedoor.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating garage door because it is the one specified: ${deviceID}");
|
||||||
|
it.open()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting garage door device because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// closes a garage door
|
||||||
|
def closeGarage() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Close Garage command recieved ${deviceID}")
|
||||||
|
garagedoor.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating garage door because it is the one specified: ${deviceID}");
|
||||||
|
it.close()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting garage door device because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// lock locks a door lock
|
||||||
|
def lockDoor() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Lock command recieved ${deviceID}")
|
||||||
|
lock.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating lock device because it is the one specified: ${deviceID}");
|
||||||
|
it.lock()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting lock device because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// unlock unlocks a door lock
|
||||||
|
def unlockDoor() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Unlock command recieved ${deviceID}")
|
||||||
|
lock.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating lock device because it is the one specified: ${deviceID}");
|
||||||
|
it.unlock()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting lock device because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// turns on a wall switch as instructed from the homeai webservice
|
||||||
|
def switchOn() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Switch on command recieved ${deviceID}")
|
||||||
|
lightswitch.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating switch device because it is the one specified: ${deviceID}");
|
||||||
|
it.on()
|
||||||
|
} else {
|
||||||
|
log.debug("Skipping switch device because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// turns off a wall switch as instructed from the homeai webservice
|
||||||
|
def switchOff() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Switch off desired for ${deviceID}")
|
||||||
|
lightswitch.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating switch device because it is the one specified: ${deviceID}");
|
||||||
|
it.off()
|
||||||
|
} else {
|
||||||
|
log.debug("Skipping switch device because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fetch the id of this smartthings hub
|
||||||
|
def hubId() {
|
||||||
|
log.debug("hub id requested.")
|
||||||
|
def response = [hubId: location.hubs.id[0]]
|
||||||
|
}
|
||||||
|
|
||||||
|
// This handles requests for device inventories
|
||||||
|
def inventory() {
|
||||||
|
def response = []
|
||||||
|
|
||||||
|
lightswitch.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("switch"), deviceId: it.id, type: "lightSwitch"]
|
||||||
|
}
|
||||||
|
|
||||||
|
contact.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("contact"), deviceId: it.id, type: "contact"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
motion.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("motion"), deviceId: it.id, type: "motion"]
|
||||||
|
}
|
||||||
|
|
||||||
|
presence.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("presence"), deviceId: it.id, type: "presence"]
|
||||||
|
}
|
||||||
|
|
||||||
|
// removed until dual device functions are supported on the backend
|
||||||
|
//tempSensor.each {
|
||||||
|
// response << [name: it.displayName, value: it.currentValue("temperature"), deviceId: it.id, type: "tempSensor"]
|
||||||
|
//}
|
||||||
|
|
||||||
|
//humidity.each {
|
||||||
|
// response << [name: it.displayName, value: it.currentValue("humidity"), deviceId: it.id, type: "humiditySensor"]
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
waterSensor.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("water"), deviceId: it.id, type: "waterSensor"]
|
||||||
|
}
|
||||||
|
|
||||||
|
lock.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("lock"), deviceId: it.id, type: "lock"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
garagedoor.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("door"), deviceId: it.id, type: "garagedoor"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
touchsensor.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("touch"), deviceId: it.id, type: "touchsensor"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
speechparser.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("phraseSpoken"), deviceId: it.id, type: "speechparser"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
soundsensor.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("sound"), deviceId: it.id, type: "sound"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
smokedetector.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("smoke"), deviceId: it.id, type: "smoke"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sleepsensor.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("sleeping"), deviceId: it.id, type: "sleepsensor"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
carbonsensor.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("carbonMonoxide"), deviceId: it.id, type: "carbonsensor"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
button.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("button"), deviceId: it.id, type: "button"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
beacon.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("presence"), deviceId: it.id, type: "beacon"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
alarm.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("alarm"), deviceId: it.id, type: "alarm"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
thermostat.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("thermostatMode"), deviceId: it.id, type: "thermostat"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
voltage.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("voltage"), deviceId: it.id, type: "voltage"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
windowshade.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("windowShade"), deviceId: it.id, type: "windowshade"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
powermeter.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("power"), deviceId: it.id, type: "powermeter"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
lightswitchlevel.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("level"), deviceId: it.id, type: "lightswitchlevel"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
log.debug("Inventory request processed. Response: " + response)
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
|
// After the user hits the 'install' button in the mobile app
|
||||||
|
def installed() {
|
||||||
|
initialize()
|
||||||
|
}
|
||||||
|
|
||||||
|
// After app settings are changed. All subscriptions are wiped before this is invoked by smartthings.
|
||||||
|
def updated() {
|
||||||
|
unsubscribe()
|
||||||
|
initialize()
|
||||||
|
}
|
||||||
|
|
||||||
|
// This appears to be what the tutorials meant to use in the examples
|
||||||
|
def initialize() {
|
||||||
|
|
||||||
|
// SHM subscription
|
||||||
|
// evt.value will be "off", "stay", or "away"
|
||||||
|
subscribe(location, "alarmSystemStatus", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// motion sensor subscription
|
||||||
|
subscribe(motion, "motion", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// Contact sensor subscription
|
||||||
|
subscribe(contact, "contact", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// power plug subscription
|
||||||
|
subscribe(lightswitch, "switch", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// presence sensor subscription
|
||||||
|
subscribe(presence, "presence", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// temperature sensor subscription
|
||||||
|
subscribe(tempSensor, "temperature", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// water sensor subscription
|
||||||
|
subscribe(waterSensor, "water", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// humidity sensor subscription
|
||||||
|
subscribe(humidity, "humidity", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// lock subscription
|
||||||
|
subscribe(lock, "lock", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// garage door subscription
|
||||||
|
subscribe(garagedoor, "garagedoor", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// touch sensor subscription
|
||||||
|
subscribe(touchsensor, "touchsensor", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// speech parser subscription
|
||||||
|
subscribe(speechparser, "phraseSpoken", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// sound sensor subscription
|
||||||
|
subscribe(soundsensor, "sound", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// smoke detector subscription
|
||||||
|
subscribe(smokedetector, "smoke", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// sleep sensor subscription
|
||||||
|
subscribe(sleepsensor, "sleeping", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// carbon monoxide sensor subscription
|
||||||
|
subscribe(carbonsensor, "carbonMonoxide", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// button subscription
|
||||||
|
subscribe(button, "button", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// beacon subscription
|
||||||
|
subscribe(beacon, "presence", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// alarm subscription
|
||||||
|
subscribe(alarm, "alarm", eventForwarder)
|
||||||
|
|
||||||
|
// thermostat subscriptions
|
||||||
|
subscribe(thermostat, "temperature", eventForwarder)
|
||||||
|
subscribe(thermostat, "heatingSetpoint", eventForwarder)
|
||||||
|
subscribe(thermostat, "coolingSetpoint", eventForwarder)
|
||||||
|
subscribe(thermostat, "thermostatSetpoint", eventForwarder)
|
||||||
|
subscribe(thermostat, "thermostatMode", eventForwarder)
|
||||||
|
subscribe(thermostat, "thermostatFanMode", eventForwarder)
|
||||||
|
subscribe(thermostat, "thermostatOperatingState", eventForwarder)
|
||||||
|
|
||||||
|
// voltage subscription
|
||||||
|
subscribe(voltage, "voltage", eventForwarder)
|
||||||
|
|
||||||
|
// window shade subscription
|
||||||
|
subscribe(windowshade, "windowShade", eventForwarder)
|
||||||
|
|
||||||
|
// shm events
|
||||||
|
subscribe(location, "alarmSystemStatus", shmEventForwarder)
|
||||||
|
|
||||||
|
// power meter subscription
|
||||||
|
subscribe(powermeter, "power", eventForwarder)
|
||||||
|
|
||||||
|
// level switch (dimmer switch)
|
||||||
|
subscribe(lightswitchlevel, "level", eventForwarder)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
def shmEventForwarder(evt) {
|
||||||
|
// evt.value will be "off", "stay", or "away"
|
||||||
|
log.debug("FORWARDING SHM CHANGE" + evt.value + " " + evt.hub.id)
|
||||||
|
|
||||||
|
def deviceState = evt.value
|
||||||
|
def deviceId = "smarthomemonitor"
|
||||||
|
def hubId = hubId()
|
||||||
|
def params = [
|
||||||
|
uri: "https://app.home.ai",
|
||||||
|
path: "/smartThingsPostback/shmStateChange/${hubId}/${deviceId}/${deviceState}"
|
||||||
|
]
|
||||||
|
log.info(params)
|
||||||
|
httpGet(params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is used to forward events to the home.ai webservice
|
||||||
|
def eventForwarder(evt) {
|
||||||
|
|
||||||
|
def hubId = location.hubs.id[0]
|
||||||
|
|
||||||
|
log.debug(params.uri + " " + params.path)
|
||||||
|
log.debug("FORWARDING EVENT" + evt.deviceId + " " + evt.value + " " + hubId)
|
||||||
|
|
||||||
|
def deviceId = evt.deviceId
|
||||||
|
def deviceState = evt.value
|
||||||
|
def params = [
|
||||||
|
uri: "https://app.home.ai",
|
||||||
|
path: "/smartThingsPostback/stateChange/${hubId}/${deviceId}/${deviceState}"
|
||||||
|
]
|
||||||
|
log.info(params)
|
||||||
|
httpGet(params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mappings that serve web requests against our smart app
|
||||||
|
mappings {
|
||||||
|
path("/inventory") {
|
||||||
|
action: [
|
||||||
|
GET: "inventory"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/hubId") {
|
||||||
|
action: [
|
||||||
|
GET: "hubId"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/switchOn/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "switchOn"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/switchOff/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "switchOff"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/lock/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "lockDoor"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/unlock/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "unlockDoor"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/opengarage/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "openGarage"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/closegarage/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "closeGarage"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/strobeAlarm/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "strobeAlarm"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/sirenAlarm/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "sirenAlarm"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/silenceAlarm/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "silenceAlarm"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/setThermostatHeatTemp/:deviceID/:temp") {
|
||||||
|
action: [
|
||||||
|
GET: "setThermostatHeatTemp"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/setThermostatCoolTemp/:deviceID/:temp") {
|
||||||
|
action: [
|
||||||
|
GET: "setThermostatCoolTemp"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/setThermostatHeat/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "setThermostatHeat"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/setThermostatCool/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "setThermostatCool"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/setThermostatMode/:deviceID/:mode") {
|
||||||
|
action: [
|
||||||
|
GET: "setThermostatMode"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/setThermostatFanMode/:deviceID/:mode") {
|
||||||
|
action: [
|
||||||
|
GET: "setThermostatFanMode"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/closeWindowShade/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "setWindowShadeClosed"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/openWindowShade/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "setWindowShadeOpen"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/awaySecurity") {
|
||||||
|
action: [
|
||||||
|
GET: "awaySecurity"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/staySecurity") {
|
||||||
|
action: [
|
||||||
|
GET: "staySecurity"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/offSecurity") {
|
||||||
|
action: [
|
||||||
|
GET: "offSecurity"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
829
smartapps/demo-home-ai/demo-home-ai.src/demo-home-ai.groovy
Normal file
829
smartapps/demo-home-ai/demo-home-ai.src/demo-home-ai.groovy
Normal file
@@ -0,0 +1,829 @@
|
|||||||
|
definition(
|
||||||
|
name: "demo.home.ai",
|
||||||
|
namespace: "demo.home.ai",
|
||||||
|
author: "Eric Greer",
|
||||||
|
description: "SmartThings demo SmartApp for home.ai.",
|
||||||
|
category: "Fun & Social",
|
||||||
|
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// These are preferences displayed in the smart phone app
|
||||||
|
preferences {
|
||||||
|
// we need a settings section to enable subscriptions
|
||||||
|
section("Pick which devices home.ai will help you automate:"){
|
||||||
|
input "motion", "capability.motionSensor", title: "Choose motion sensors", required: false, multiple: true
|
||||||
|
input "contact", "capability.contactSensor", title: "Choose contact sensors", required: false, multiple: true
|
||||||
|
input "lightswitch", "capability.switch", title: "Choose normal power switches", required: false, multiple: true
|
||||||
|
input "lightswitchlevel", "capability.switchLevel", title: "Choose dimmer power switches", required: false, multiple: true
|
||||||
|
input "presence", "capability.presenceSensor", title: "Choose presence sensors", required: false, multiple: true
|
||||||
|
input "tempSensor", "capability.temperatureMeasurement", title: "Choose temperature sensors", required: false, multiple: true
|
||||||
|
input "humidity", "capability.relativeHumidityMeasurement", title: "Choose humidity sensors", required: false, multiple: true
|
||||||
|
input "waterSensor", "capability.waterSensor", title: "Choose water sensors", required: false, multiple: true
|
||||||
|
input "lock", "capability.lock", title: "Pick Door Locks", required: false, multiple: true
|
||||||
|
input "garagedoor", "capability.garageDoorControl", title: "Pick garage doors", required: false, multiple: true
|
||||||
|
input "touchsensor", "capability.touchSensor", title: "Pick touch sensors", required: false, multiple: true
|
||||||
|
input "speechparser", "capability.speechRecognition", title: "Pick speech recognizers", required: false, multiple: true
|
||||||
|
input "soundsensor", "capability.soundSensor", title: "Pick sound sensors", required: false, multiple: true
|
||||||
|
input "smokedetector", "capability.smokeDetector", title: "Pick smoke detectors", required: false, multiple: true
|
||||||
|
input "sleepsensor", "capability.sleepSensor", title: "Pick sleep sensors", required: false, multiple: true
|
||||||
|
input "carbonsensor", "capability.carbonMonoxideDetector", title: "Pick carbon monoxide detectors", required: false, multiple: true
|
||||||
|
input "button", "capability.button", title: "Pick buttons", required: false, multiple: true
|
||||||
|
input "beacon", "capability.beacon", title: "Pick beacons", required: false, multiple: true
|
||||||
|
input "alarm", "capability.alarm", title: "Pick alarms", required: false, multiple: true
|
||||||
|
input "thermostat", "capability.thermostat", title: "Pick thermostats", required: false, multiple: true
|
||||||
|
input "voltage", "capability.voltageMeasurement", title: "Pick voltage sensors", required: false, multiple: true
|
||||||
|
input "windowshade", "capability.windowShade", title: "Pick window shades", required: false, multiple: true
|
||||||
|
input "powermeter", "capability.powerMeter", title: "Pick power meters", required: false, multiple: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// vlaues for security system are 'away', 'stay', or 'off'
|
||||||
|
// off security
|
||||||
|
def offSecurity() {
|
||||||
|
sendLocationEvent(
|
||||||
|
name: "alarmSystemStatus",
|
||||||
|
value: "off",
|
||||||
|
displayed: false,
|
||||||
|
isStateChange: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// stay security
|
||||||
|
def staySecurity() {
|
||||||
|
sendLocationEvent(
|
||||||
|
name: "alarmSystemStatus",
|
||||||
|
value: "stay",
|
||||||
|
displayed: false,
|
||||||
|
isStateChange: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// away security
|
||||||
|
def awaySecurity() {
|
||||||
|
sendLocationEvent(
|
||||||
|
name: "alarmSystemStatus",
|
||||||
|
value: "away",
|
||||||
|
displayed: false,
|
||||||
|
isStateChange: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// sets window shade open temperature
|
||||||
|
def setWindowShadeOpen() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setWindowShadeOpen command recieved ${deviceID}")
|
||||||
|
windowshade.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating window shade because it is the one specified: ${deviceID}");
|
||||||
|
it.open()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting window shade because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets window shade close temperature
|
||||||
|
def setWindowShadeClosed() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setWindowShadeClosed command recieved ${deviceID}")
|
||||||
|
windowshade.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating window shade because it is the one specified: ${deviceID}");
|
||||||
|
it.close()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting window shade because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// sets thermostat heating temperature
|
||||||
|
def setThermostatHeatTemp() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setThermostatHeat command recieved ${deviceID}")
|
||||||
|
thermostat.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating thermostat because it is the one specified: ${deviceID}");
|
||||||
|
it.setHeatingSetpoint(params.temp)
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting thermostat because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets thermostat cooling temperature
|
||||||
|
def setThermostatCoolTemp() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setThermostatCool command recieved ${deviceID}")
|
||||||
|
thermostat.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating thermostat because it is the one specified: ${deviceID}");
|
||||||
|
it.setCoolingSetpoint(params.temp)
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting thermostat because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets thermostat off
|
||||||
|
def setThermostatOff() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setThermostatOff command recieved ${deviceID}")
|
||||||
|
thermostat.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating thermostat because it is the one specified: ${deviceID}");
|
||||||
|
it.off()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting thermostat because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// sets thermostat to heat
|
||||||
|
def setThermostatHeat() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setThermostatHeat command recieved ${deviceID}")
|
||||||
|
thermostat.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating thermostat because it is the one specified: ${deviceID}");
|
||||||
|
it.heat()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting thermostat because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// sets thermostat to cool
|
||||||
|
def setThermostatCool() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setThermostatCool command recieved ${deviceID}")
|
||||||
|
thermostat.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating thermostat because it is the one specified: ${deviceID}");
|
||||||
|
it.cool()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting thermostat because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// sets thermostat mode
|
||||||
|
def setThermostatMode() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setThermostatMode command recieved ${deviceID}")
|
||||||
|
thermostat.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating thermostat because it is the one specified: ${deviceID}");
|
||||||
|
it.setThermostatMode(params.mode)
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting thermostat because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// sets thermostat fan mode
|
||||||
|
def setThermostatFanMode() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setThermostatFanMode command recieved ${deviceID}")
|
||||||
|
thermostat.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating thermostat because it is the one specified: ${deviceID}");
|
||||||
|
it.setThermostatFanMode(params.mode)
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting thermostat because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// sends an alarm strobe
|
||||||
|
def strobeAlarm() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Alarm strobe command recieved ${deviceID}")
|
||||||
|
alarm.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating alarm because it is the one specified: ${deviceID}");
|
||||||
|
it.strobe()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting alarm because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sends an alarm siren
|
||||||
|
def sirenAlarm() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Alarm siren command recieved ${deviceID}")
|
||||||
|
alarm.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating alarm because it is the one specified: ${deviceID}");
|
||||||
|
it.siren()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting alarm because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// disables an alarm siren
|
||||||
|
def silenceAlarm() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Alarm silence command recieved ${deviceID}")
|
||||||
|
alarm.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating alarm because it is the one specified: ${deviceID}");
|
||||||
|
it.off()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting alarm because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// opens a garage door
|
||||||
|
def openGarage() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Open Garage command recieved ${deviceID}")
|
||||||
|
garagedoor.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating garage door because it is the one specified: ${deviceID}");
|
||||||
|
it.open()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting garage door device because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// closes a garage door
|
||||||
|
def closeGarage() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Close Garage command recieved ${deviceID}")
|
||||||
|
garagedoor.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating garage door because it is the one specified: ${deviceID}");
|
||||||
|
it.close()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting garage door device because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// lock locks a door lock
|
||||||
|
def lockDoor() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Lock command recieved ${deviceID}")
|
||||||
|
lock.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating lock device because it is the one specified: ${deviceID}");
|
||||||
|
it.lock()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting lock device because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// unlock unlocks a door lock
|
||||||
|
def unlockDoor() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Unlock command recieved ${deviceID}")
|
||||||
|
lock.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating lock device because it is the one specified: ${deviceID}");
|
||||||
|
it.unlock()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting lock device because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// turns on a wall switch as instructed from the homeai webservice
|
||||||
|
def switchOn() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Switch on command recieved ${deviceID}")
|
||||||
|
lightswitch.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating switch device because it is the one specified: ${deviceID}");
|
||||||
|
it.on()
|
||||||
|
} else {
|
||||||
|
log.debug("Skipping switch device because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// turns off a wall switch as instructed from the homeai webservice
|
||||||
|
def switchOff() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Switch off desired for ${deviceID}")
|
||||||
|
lightswitch.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating switch device because it is the one specified: ${deviceID}");
|
||||||
|
it.off()
|
||||||
|
} else {
|
||||||
|
log.debug("Skipping switch device because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// sets a level switch to off
|
||||||
|
def setLevelSwitch0() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Level switch off desired for ${deviceID}")
|
||||||
|
lightswitchlevel.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating level switch device because it is the one specified: ${deviceID}");
|
||||||
|
it.setLevel(0)
|
||||||
|
} else {
|
||||||
|
log.debug("Skipping level switch device because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// sets a level switch to 25%
|
||||||
|
def setLevelSwitch25() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Level switch 25 desired for ${deviceID}")
|
||||||
|
lightswitchlevel.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating level switch device because it is the one specified: ${deviceID}");
|
||||||
|
it.setLevel(25)
|
||||||
|
} else {
|
||||||
|
log.debug("Skipping level switch device because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// sets a level switch to 50%
|
||||||
|
def setLevelSwitch50() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Level switch 50 desired for ${deviceID}")
|
||||||
|
lightswitchlevel.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating level switch device because it is the one specified: ${deviceID}");
|
||||||
|
it.setLevel(50)
|
||||||
|
} else {
|
||||||
|
log.debug("Skipping level switch device because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// sets a level switch to 75%
|
||||||
|
def setLevelSwitch75() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Level switch 75 desired for ${deviceID}")
|
||||||
|
lightswitchlevel.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating level switch device because it is the one specified: ${deviceID}");
|
||||||
|
it.setLevel(75)
|
||||||
|
} else {
|
||||||
|
log.debug("Skipping level switch device because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// sets a level switch to 100%
|
||||||
|
def setLevelSwitch100() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Level switch 100 desired for ${deviceID}")
|
||||||
|
lightswitchlevel.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating level switch device because it is the one specified: ${deviceID}");
|
||||||
|
it.setLevel(100)
|
||||||
|
} else {
|
||||||
|
log.debug("Skipping level switch device because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// fetch the id of this smartthings hub
|
||||||
|
def hubId() {
|
||||||
|
log.debug("hub id requested.")
|
||||||
|
def response = [hubId: location.hubs.id[0]]
|
||||||
|
}
|
||||||
|
|
||||||
|
// This handles requests for device inventories
|
||||||
|
def inventory() {
|
||||||
|
def response = []
|
||||||
|
|
||||||
|
lightswitch.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("switch"), deviceId: it.id, type: "lightSwitch"]
|
||||||
|
}
|
||||||
|
|
||||||
|
contact.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("contact"), deviceId: it.id, type: "contact"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
motion.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("motion"), deviceId: it.id, type: "motion"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
presence.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("presence"), deviceId: it.id, type: "presence"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
tempSensor.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("temperature"), deviceId: it.id, type: "tempSensor"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
waterSensor.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("water"), deviceId: it.id, type: "waterSensor"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
humidity.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("humidity"), deviceId: it.id, type: "humiditySensor"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
lock.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("lock"), deviceId: it.id, type: "lock"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
garagedoor.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("door"), deviceId: it.id, type: "garagedoor"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
touchsensor.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("touch"), deviceId: it.id, type: "touchsensor"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
speechparser.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("phraseSpoken"), deviceId: it.id, type: "speechparser"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
soundsensor.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("sound"), deviceId: it.id, type: "sound"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
smokedetector.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("smoke"), deviceId: it.id, type: "smoke"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sleepsensor.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("sleeping"), deviceId: it.id, type: "sleepsensor"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
carbonsensor.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("carbonMonoxide"), deviceId: it.id, type: "carbonsensor"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
button.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("button"), deviceId: it.id, type: "button"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
beacon.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("presence"), deviceId: it.id, type: "beacon"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
alarm.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("alarm"), deviceId: it.id, type: "alarm"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
thermostat.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("thermostatMode"), deviceId: it.id, type: "thermostat"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
voltage.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("voltage"), deviceId: it.id, type: "voltage"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
windowshade.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("windowShade"), deviceId: it.id, type: "windowshade"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
powermeter.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("power"), deviceId: it.id, type: "powermeter"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
lightswitchlevel.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("level"), deviceId: it.id, type: "lightswitchlevel"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
log.debug("Inventory request processed. Response: " + response)
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
|
// After the user hits the 'install' button in the mobile app
|
||||||
|
def installed() {
|
||||||
|
initialize()
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// After app settings are changed. All subscriptions are wiped before this is invoked by smartthings.
|
||||||
|
def updated() {
|
||||||
|
unsubscribe()
|
||||||
|
initialize()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// This appears to be what the tutorials meant to use in the examples
|
||||||
|
def initialize() {
|
||||||
|
|
||||||
|
// motion sensor subscription
|
||||||
|
subscribe(motion, "motion", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// Contact sensor subscription
|
||||||
|
subscribe(contact, "contact", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// power plug subscription
|
||||||
|
subscribe(lightswitch, "switch", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// presence sensor subscription
|
||||||
|
subscribe(presence, "presence", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// temperature sensor subscription
|
||||||
|
subscribe(tempSensor, "temperature", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// water sensor subscription
|
||||||
|
subscribe(waterSensor, "water", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// humidity sensor subscription
|
||||||
|
subscribe(humidity, "humidity", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// lock subscription
|
||||||
|
subscribe(lock, "lock", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// garage door subscription
|
||||||
|
subscribe(garagedoor, "garagedoor", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// touch sensor subscription
|
||||||
|
subscribe(touchsensor, "touchsensor", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// speech parser subscription
|
||||||
|
subscribe(speechparser, "phraseSpoken", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// sound sensor subscription
|
||||||
|
subscribe(soundsensor, "sound", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// smoke detector subscription
|
||||||
|
subscribe(smokedetector, "smoke", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// sleep sensor subscription
|
||||||
|
subscribe(sleepsensor, "sleeping", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// carbon monoxide sensor subscription
|
||||||
|
subscribe(carbonsensor, "carbonMonoxide", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// button subscription
|
||||||
|
subscribe(button, "button", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// beacon subscription
|
||||||
|
subscribe(beacon, "presence", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// alarm subscription
|
||||||
|
subscribe(alarm, "alarm", eventForwarder)
|
||||||
|
|
||||||
|
// thermostat subscriptions
|
||||||
|
subscribe(thermostat, "temperature", eventForwarder)
|
||||||
|
subscribe(thermostat, "heatingSetpoint", eventForwarder)
|
||||||
|
subscribe(thermostat, "coolingSetpoint", eventForwarder)
|
||||||
|
subscribe(thermostat, "thermostatSetpoint", eventForwarder)
|
||||||
|
subscribe(thermostat, "thermostatMode", eventForwarder)
|
||||||
|
subscribe(thermostat, "thermostatFanMode", eventForwarder)
|
||||||
|
subscribe(thermostat, "thermostatOperatingState", eventForwarder)
|
||||||
|
|
||||||
|
// voltage subscription
|
||||||
|
subscribe(voltage, "voltage", eventForwarder)
|
||||||
|
|
||||||
|
// window shade subscription
|
||||||
|
subscribe(windowshade, "windowShade", eventForwarder)
|
||||||
|
|
||||||
|
// shm events
|
||||||
|
subscribe(location, "alarmSystemStatus", shmEventForwarder)
|
||||||
|
|
||||||
|
// power meter subscription
|
||||||
|
subscribe(powermeter, "power", eventForwarder)
|
||||||
|
|
||||||
|
// level switch (dimmer switch)
|
||||||
|
subscribe(lightswitchlevel, "level", eventForwarder)
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is used to forward events to the home.ai webservice
|
||||||
|
def eventForwarder(evt) {
|
||||||
|
|
||||||
|
|
||||||
|
log.debug(params.uri + " " + params.path)
|
||||||
|
|
||||||
|
log.debug("FORWARDING EVENT" + evt.deviceId + " " + evt.value + " " + evt.hub.id)
|
||||||
|
|
||||||
|
def deviceId = evt.deviceId
|
||||||
|
def deviceState = evt.value
|
||||||
|
def hubId = evt.hub.id
|
||||||
|
def params = [
|
||||||
|
uri: "https://demo.home.ai",
|
||||||
|
path: "/smartThingsPostback/stateChange/${hubId}/${deviceId}/${deviceState}"
|
||||||
|
]
|
||||||
|
log.info(params)
|
||||||
|
httpGet(params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mappings that serve web requests against our smart app
|
||||||
|
mappings {
|
||||||
|
path("/inventory") {
|
||||||
|
action: [
|
||||||
|
GET: "inventory"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/hubId") {
|
||||||
|
action: [
|
||||||
|
GET: "hubId"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/switchOn/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "switchOn"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/switchOff/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "switchOff"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/lock/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "lockDoor"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/unlock/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "unlockDoor"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/opengarage/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "openGarage"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/closegarage/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "closeGarage"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
path("/strobeAlarm/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "strobeAlarm"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/sirenAlarm/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "sirenAlarm"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/silenceAlarm/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "silenceAlarm"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
path("/setThermostatHeatTemp/:deviceID/:temp") {
|
||||||
|
action: [
|
||||||
|
GET: "setThermostatHeatTemp"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/setThermostatCoolTemp/:deviceID/:temp") {
|
||||||
|
action: [
|
||||||
|
GET: "setThermostatCoolTemp"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/setThermostatHeat/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "setThermostatHeat"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/setThermostatCool/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "setThermostatCool"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/setThermostatMode/:deviceID/:mode") {
|
||||||
|
action: [
|
||||||
|
GET: "setThermostatMode"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/setThermostatFanMode/:deviceID/:mode") {
|
||||||
|
action: [
|
||||||
|
GET: "setThermostatFanMode"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
path("/closeWindowShade/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "setWindowShadeClosed"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/openWindowShade/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "setWindowShadeOpen"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
// level switch setting endpoints
|
||||||
|
path("/levelSwitch0/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "setLevelSwitch0"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/levelSwitch25/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "setLevelSwitch25"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/levelSwitch50/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "setLevelSwitch50"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/levelSwitch75/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "setLevelSwitch75"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/levelSwitch100/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "setLevelSwitch100"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Smart home monitor controls
|
||||||
|
path("/awaySecurity") {
|
||||||
|
action: [
|
||||||
|
GET: "awaySecurity"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/staySecurity") {
|
||||||
|
action: [
|
||||||
|
GET: "staySecurity"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/offSecurity") {
|
||||||
|
action: [
|
||||||
|
GET: "offSecurity"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -765,6 +765,7 @@ def turnOffSwitch() {
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
device.off();
|
device.off();
|
||||||
|
|
||||||
return [Device_id: params.id, result_action: "200"]
|
return [Device_id: params.id, result_action: "200"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -788,7 +789,6 @@ def getTempSensorsStatus(id) {
|
|||||||
return []
|
return []
|
||||||
} else {
|
} else {
|
||||||
def bat = getBatteryStatus(device.id)
|
def bat = getBatteryStatus(device.id)
|
||||||
def scale = [Scale: location.temperatureScale]
|
return [temperature: device.currentValue('temperature')] + bat
|
||||||
return [temperature: device.currentValue('temperature')] + bat + scale
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,6 @@ def getCallbackUrl() { return "${getServerUrl()}/oauth/callback" }
|
|||||||
def apiURL(path = '/') { return "https://api.lifx.com/v1${path}" }
|
def apiURL(path = '/') { return "https://api.lifx.com/v1${path}" }
|
||||||
def getSecretKey() { return appSettings.secretKey }
|
def getSecretKey() { return appSettings.secretKey }
|
||||||
def getClientId() { return appSettings.clientId }
|
def getClientId() { return appSettings.clientId }
|
||||||
private getVendorName() { "LIFX" }
|
|
||||||
|
|
||||||
def authPage() {
|
def authPage() {
|
||||||
log.debug "authPage test1"
|
log.debug "authPage test1"
|
||||||
@@ -77,7 +76,6 @@ def authPage() {
|
|||||||
return dynamicPage(name:"Credentials", title:"", nextPage:"", install:true, uninstall: true) {
|
return dynamicPage(name:"Credentials", title:"", nextPage:"", install:true, uninstall: true) {
|
||||||
section("Select your location") {
|
section("Select your location") {
|
||||||
input "selectedLocationId", "enum", required:true, title:"Select location ({{count}} found)", messageArgs: [count: count], multiple:false, options:options, submitOnChange: true
|
input "selectedLocationId", "enum", required:true, title:"Select location ({{count}} found)", messageArgs: [count: count], multiple:false, options:options, submitOnChange: true
|
||||||
paragraph "Devices will be added automatically from your ${vendorName} account. To add or delete devices please use the Official ${vendorName} App."
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,713 @@
|
|||||||
|
definition(
|
||||||
|
name: "stage.app.home.ai",
|
||||||
|
namespace: "stage.app.home.ai",
|
||||||
|
author: "Eric Greer",
|
||||||
|
description: "SmartThings SmartApp for stage.app.home.ai.",
|
||||||
|
category: "Fun & Social",
|
||||||
|
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
// These are preferences displayed in the smart phone app
|
||||||
|
preferences {
|
||||||
|
// we need a settings section to enable subscriptions
|
||||||
|
section("Pick which devices home.ai will help you automate:"){
|
||||||
|
input "motion", "capability.motionSensor", title: "Choose motion sensors", required: false, multiple: true
|
||||||
|
input "contact", "capability.contactSensor", title: "Choose contact sensors", required: false, multiple: true
|
||||||
|
input "lightswitch", "capability.switch", title: "Choose normal power switches", required: false, multiple: true
|
||||||
|
input "lightswitchlevel", "capability.switchLevel", title: "Choose dimmer power switches", required: false, multiple: true
|
||||||
|
input "presence", "capability.presenceSensor", title: "Choose presence sensors", required: false, multiple: true
|
||||||
|
input "tempSensor", "capability.temperatureMeasurement", title: "Choose temperature sensors", required: false, multiple: true
|
||||||
|
input "humidity", "capability.relativeHumidityMeasurement", title: "Choose humidity sensors", required: false, multiple: true
|
||||||
|
input "waterSensor", "capability.waterSensor", title: "Choose water sensors", required: false, multiple: true
|
||||||
|
input "lock", "capability.lock", title: "Pick Door Locks", required: false, multiple: true
|
||||||
|
input "garagedoor", "capability.garageDoorControl", title: "Pick garage doors", required: false, multiple: true
|
||||||
|
input "touchsensor", "capability.touchSensor", title: "Pick touch sensors", required: false, multiple: true
|
||||||
|
input "speechparser", "capability.speechRecognition", title: "Pick speech recognizers", required: false, multiple: true
|
||||||
|
input "soundsensor", "capability.soundSensor", title: "Pick sound sensors", required: false, multiple: true
|
||||||
|
input "smokedetector", "capability.smokeDetector", title: "Pick smoke detectors", required: false, multiple: true
|
||||||
|
input "sleepsensor", "capability.sleepSensor", title: "Pick sleep sensors", required: false, multiple: true
|
||||||
|
input "carbonsensor", "capability.carbonMonoxideDetector", title: "Pick carbon monoxide detectors", required: false, multiple: true
|
||||||
|
input "button", "capability.button", title: "Pick buttons", required: false, multiple: true
|
||||||
|
input "beacon", "capability.beacon", title: "Pick beacons", required: false, multiple: true
|
||||||
|
input "alarm", "capability.alarm", title: "Pick alarms", required: false, multiple: true
|
||||||
|
input "thermostat", "capability.thermostat", title: "Pick thermostats", required: false, multiple: true
|
||||||
|
input "voltage", "capability.voltageMeasurement", title: "Pick voltage sensors", required: false, multiple: true
|
||||||
|
input "windowshade", "capability.windowShade", title: "Pick window shades", required: false, multiple: true
|
||||||
|
input "powermeter", "capability.powerMeter", title: "Pick power meters", required: false, multiple: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// vlaues for security system are 'away', 'stay', or 'off'
|
||||||
|
// off security
|
||||||
|
def offSecurity() {
|
||||||
|
sendLocationEvent(
|
||||||
|
name: "alarmSystemStatus",
|
||||||
|
value: "off",
|
||||||
|
displayed: false,
|
||||||
|
isStateChange: true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// stay security
|
||||||
|
def staySecurity() {
|
||||||
|
sendLocationEvent(
|
||||||
|
name: "alarmSystemStatus",
|
||||||
|
value: "stay",
|
||||||
|
displayed: false,
|
||||||
|
isStateChange: true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// away security
|
||||||
|
def awaySecurity() {
|
||||||
|
sendLocationEvent(
|
||||||
|
name: "alarmSystemStatus",
|
||||||
|
value: "away",
|
||||||
|
displayed: false,
|
||||||
|
isStateChange: true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets window shade open temperature
|
||||||
|
def setWindowShadeOpen() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setWindowShadeOpen command recieved ${deviceID}")
|
||||||
|
windowshade.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating window shade because it is the one specified: ${deviceID}");
|
||||||
|
it.open()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting window shade because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets window shade close temperature
|
||||||
|
def setWindowShadeClosed() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setWindowShadeClosed command recieved ${deviceID}")
|
||||||
|
windowshade.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating window shade because it is the one specified: ${deviceID}");
|
||||||
|
it.close()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting window shade because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets thermostat heating temperature
|
||||||
|
def setThermostatHeatTemp() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setThermostatHeat command recieved ${deviceID}")
|
||||||
|
thermostat.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating thermostat because it is the one specified: ${deviceID}");
|
||||||
|
it.setHeatingSetpoint(params.temp)
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting thermostat because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets thermostat cooling temperature
|
||||||
|
def setThermostatCoolTemp() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setThermostatCool command recieved ${deviceID}")
|
||||||
|
thermostat.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating thermostat because it is the one specified: ${deviceID}");
|
||||||
|
it.setCoolingSetpoint(params.temp)
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting thermostat because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets thermostat off
|
||||||
|
def setThermostatOff() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setThermostatOff command recieved ${deviceID}")
|
||||||
|
thermostat.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating thermostat because it is the one specified: ${deviceID}");
|
||||||
|
it.off()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting thermostat because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets thermostat to heat
|
||||||
|
def setThermostatHeat() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setThermostatHeat command recieved ${deviceID}")
|
||||||
|
thermostat.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating thermostat because it is the one specified: ${deviceID}");
|
||||||
|
it.heat()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting thermostat because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets thermostat to cool
|
||||||
|
def setThermostatCool() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setThermostatCool command recieved ${deviceID}")
|
||||||
|
thermostat.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating thermostat because it is the one specified: ${deviceID}");
|
||||||
|
it.cool()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting thermostat because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets thermostat mode
|
||||||
|
def setThermostatMode() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setThermostatMode command recieved ${deviceID}")
|
||||||
|
thermostat.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating thermostat because it is the one specified: ${deviceID}");
|
||||||
|
it.setThermostatMode(params.mode)
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting thermostat because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sets thermostat fan mode
|
||||||
|
def setThermostatFanMode() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("setThermostatFanMode command recieved ${deviceID}")
|
||||||
|
thermostat.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating thermostat because it is the one specified: ${deviceID}");
|
||||||
|
it.setThermostatFanMode(params.mode)
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting thermostat because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sends an alarm strobe
|
||||||
|
def strobeAlarm() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Alarm strobe command recieved ${deviceID}")
|
||||||
|
alarm.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating alarm because it is the one specified: ${deviceID}");
|
||||||
|
it.strobe()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting alarm because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sends an alarm siren
|
||||||
|
def sirenAlarm() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Alarm siren command recieved ${deviceID}")
|
||||||
|
alarm.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating alarm because it is the one specified: ${deviceID}");
|
||||||
|
it.siren()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting alarm because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// disables an alarm siren
|
||||||
|
def silenceAlarm() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Alarm silence command recieved ${deviceID}")
|
||||||
|
alarm.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating alarm because it is the one specified: ${deviceID}");
|
||||||
|
it.off()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting alarm because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// opens a garage door
|
||||||
|
def openGarage() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Open Garage command recieved ${deviceID}")
|
||||||
|
garagedoor.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating garage door because it is the one specified: ${deviceID}");
|
||||||
|
it.open()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting garage door device because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// closes a garage door
|
||||||
|
def closeGarage() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Close Garage command recieved ${deviceID}")
|
||||||
|
garagedoor.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating garage door because it is the one specified: ${deviceID}");
|
||||||
|
it.close()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting garage door device because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// lock locks a door lock
|
||||||
|
def lockDoor() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Lock command recieved ${deviceID}")
|
||||||
|
lock.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating lock device because it is the one specified: ${deviceID}");
|
||||||
|
it.lock()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting lock device because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// unlock unlocks a door lock
|
||||||
|
def unlockDoor() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Unlock command recieved ${deviceID}")
|
||||||
|
lock.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating lock device because it is the one specified: ${deviceID}");
|
||||||
|
it.unlock()
|
||||||
|
} else {
|
||||||
|
log.debug("NOT operting lock device because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// turns on a wall switch as instructed from the homeai webservice
|
||||||
|
def switchOn() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Switch on command recieved ${deviceID}")
|
||||||
|
lightswitch.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating switch device because it is the one specified: ${deviceID}");
|
||||||
|
it.on()
|
||||||
|
} else {
|
||||||
|
log.debug("Skipping switch device because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// turns off a wall switch as instructed from the homeai webservice
|
||||||
|
def switchOff() {
|
||||||
|
def deviceID = params.deviceID
|
||||||
|
log.debug("Switch off desired for ${deviceID}")
|
||||||
|
lightswitch.each {
|
||||||
|
if (it.id == deviceID) {
|
||||||
|
log.debug("Operating switch device because it is the one specified: ${deviceID}");
|
||||||
|
it.off()
|
||||||
|
} else {
|
||||||
|
log.debug("Skipping switch device because it is not the one specified: ${deviceID}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fetch the id of this smartthings hub
|
||||||
|
def hubId() {
|
||||||
|
log.debug("hub id requested.")
|
||||||
|
def response = [hubId: location.hubs.id[0]]
|
||||||
|
}
|
||||||
|
|
||||||
|
// This handles requests for device inventories
|
||||||
|
def inventory() {
|
||||||
|
def response = []
|
||||||
|
|
||||||
|
lightswitch.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("switch"), deviceId: it.id, type: "lightSwitch"]
|
||||||
|
}
|
||||||
|
|
||||||
|
contact.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("contact"), deviceId: it.id, type: "contact"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
motion.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("motion"), deviceId: it.id, type: "motion"]
|
||||||
|
}
|
||||||
|
|
||||||
|
presence.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("presence"), deviceId: it.id, type: "presence"]
|
||||||
|
}
|
||||||
|
|
||||||
|
// removed until dual device functions are supported on the backend
|
||||||
|
//tempSensor.each {
|
||||||
|
// response << [name: it.displayName, value: it.currentValue("temperature"), deviceId: it.id, type: "tempSensor"]
|
||||||
|
//}
|
||||||
|
|
||||||
|
//humidity.each {
|
||||||
|
// response << [name: it.displayName, value: it.currentValue("humidity"), deviceId: it.id, type: "humiditySensor"]
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
waterSensor.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("water"), deviceId: it.id, type: "waterSensor"]
|
||||||
|
}
|
||||||
|
|
||||||
|
lock.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("lock"), deviceId: it.id, type: "lock"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
garagedoor.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("door"), deviceId: it.id, type: "garagedoor"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
touchsensor.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("touch"), deviceId: it.id, type: "touchsensor"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
speechparser.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("phraseSpoken"), deviceId: it.id, type: "speechparser"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
soundsensor.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("sound"), deviceId: it.id, type: "sound"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
smokedetector.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("smoke"), deviceId: it.id, type: "smoke"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sleepsensor.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("sleeping"), deviceId: it.id, type: "sleepsensor"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
carbonsensor.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("carbonMonoxide"), deviceId: it.id, type: "carbonsensor"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
button.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("button"), deviceId: it.id, type: "button"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
beacon.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("presence"), deviceId: it.id, type: "beacon"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
alarm.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("alarm"), deviceId: it.id, type: "alarm"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
thermostat.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("thermostatMode"), deviceId: it.id, type: "thermostat"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
voltage.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("voltage"), deviceId: it.id, type: "voltage"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
windowshade.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("windowShade"), deviceId: it.id, type: "windowshade"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
powermeter.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("power"), deviceId: it.id, type: "powermeter"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
lightswitchlevel.each {
|
||||||
|
response << [name: it.displayName, value: it.currentValue("level"), deviceId: it.id, type: "lightswitchlevel"]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
log.debug("Inventory request processed. Response: " + response)
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
|
// After the user hits the 'install' button in the mobile app
|
||||||
|
def installed() {
|
||||||
|
initialize()
|
||||||
|
}
|
||||||
|
|
||||||
|
// After app settings are changed. All subscriptions are wiped before this is invoked by smartthings.
|
||||||
|
def updated() {
|
||||||
|
unsubscribe()
|
||||||
|
initialize()
|
||||||
|
}
|
||||||
|
|
||||||
|
// This appears to be what the tutorials meant to use in the examples
|
||||||
|
def initialize() {
|
||||||
|
|
||||||
|
// SHM subscription
|
||||||
|
// evt.value will be "off", "stay", or "away"
|
||||||
|
subscribe(location, "alarmSystemStatus", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// motion sensor subscription
|
||||||
|
subscribe(motion, "motion", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// Contact sensor subscription
|
||||||
|
subscribe(contact, "contact", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// power plug subscription
|
||||||
|
subscribe(lightswitch, "switch", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// presence sensor subscription
|
||||||
|
subscribe(presence, "presence", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// temperature sensor subscription
|
||||||
|
subscribe(tempSensor, "temperature", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// water sensor subscription
|
||||||
|
subscribe(waterSensor, "water", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// humidity sensor subscription
|
||||||
|
subscribe(humidity, "humidity", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// lock subscription
|
||||||
|
subscribe(lock, "lock", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// garage door subscription
|
||||||
|
subscribe(garagedoor, "garagedoor", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// touch sensor subscription
|
||||||
|
subscribe(touchsensor, "touchsensor", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// speech parser subscription
|
||||||
|
subscribe(speechparser, "phraseSpoken", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// sound sensor subscription
|
||||||
|
subscribe(soundsensor, "sound", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// smoke detector subscription
|
||||||
|
subscribe(smokedetector, "smoke", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// sleep sensor subscription
|
||||||
|
subscribe(sleepsensor, "sleeping", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// carbon monoxide sensor subscription
|
||||||
|
subscribe(carbonsensor, "carbonMonoxide", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// button subscription
|
||||||
|
subscribe(button, "button", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// beacon subscription
|
||||||
|
subscribe(beacon, "presence", eventForwarder)
|
||||||
|
|
||||||
|
|
||||||
|
// alarm subscription
|
||||||
|
subscribe(alarm, "alarm", eventForwarder)
|
||||||
|
|
||||||
|
// thermostat subscriptions
|
||||||
|
subscribe(thermostat, "temperature", eventForwarder)
|
||||||
|
subscribe(thermostat, "heatingSetpoint", eventForwarder)
|
||||||
|
subscribe(thermostat, "coolingSetpoint", eventForwarder)
|
||||||
|
subscribe(thermostat, "thermostatSetpoint", eventForwarder)
|
||||||
|
subscribe(thermostat, "thermostatMode", eventForwarder)
|
||||||
|
subscribe(thermostat, "thermostatFanMode", eventForwarder)
|
||||||
|
subscribe(thermostat, "thermostatOperatingState", eventForwarder)
|
||||||
|
|
||||||
|
// voltage subscription
|
||||||
|
subscribe(voltage, "voltage", eventForwarder)
|
||||||
|
|
||||||
|
// window shade subscription
|
||||||
|
subscribe(windowshade, "windowShade", eventForwarder)
|
||||||
|
|
||||||
|
// shm events
|
||||||
|
subscribe(location, "alarmSystemStatus", shmEventForwarder)
|
||||||
|
|
||||||
|
// power meter subscription
|
||||||
|
subscribe(powermeter, "power", eventForwarder)
|
||||||
|
|
||||||
|
// level switch (dimmer switch)
|
||||||
|
subscribe(lightswitchlevel, "level", eventForwarder)
|
||||||
|
}
|
||||||
|
|
||||||
|
def shmEventForwarder(evt) {
|
||||||
|
// evt.value will be "off", "stay", or "away"
|
||||||
|
log.debug("FORWARDING SHM CHANGE" + evt.value + " " + evt.hub.id)
|
||||||
|
|
||||||
|
def deviceState = evt.value
|
||||||
|
def deviceId = "smarthomemonitor"
|
||||||
|
def hubId = hubId()
|
||||||
|
def params = [
|
||||||
|
uri: "https://stage.app.home.ai",
|
||||||
|
path: "/smartThingsPostback/shmStateChange/${hubId}/${deviceId}/${deviceState}"
|
||||||
|
]
|
||||||
|
log.info(params)
|
||||||
|
httpGet(params)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is used to forward events to the home.ai webservice
|
||||||
|
def eventForwarder(evt) {
|
||||||
|
|
||||||
|
def hubId = location.hubs.id[0]
|
||||||
|
|
||||||
|
log.debug(params.uri + " " + params.path)
|
||||||
|
log.debug("FORWARDING EVENT" + evt.deviceId + " " + evt.value + " " + hubId)
|
||||||
|
|
||||||
|
def deviceId = evt.deviceId
|
||||||
|
def deviceState = evt.value
|
||||||
|
def params = [
|
||||||
|
uri: "https://stage.app.home.ai",
|
||||||
|
path: "/smartThingsPostback/stateChange/${hubId}/${deviceId}/${deviceState}"
|
||||||
|
]
|
||||||
|
log.info(params)
|
||||||
|
httpGet(params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mappings that serve web requests against our smart app
|
||||||
|
mappings {
|
||||||
|
path("/inventory") {
|
||||||
|
action: [
|
||||||
|
GET: "inventory"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/hubId") {
|
||||||
|
action: [
|
||||||
|
GET: "hubId"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/switchOn/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "switchOn"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/switchOff/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "switchOff"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/lock/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "lockDoor"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/unlock/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "unlockDoor"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/opengarage/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "openGarage"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/closegarage/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "closeGarage"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/strobeAlarm/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "strobeAlarm"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/sirenAlarm/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "sirenAlarm"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/silenceAlarm/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "silenceAlarm"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/setThermostatHeatTemp/:deviceID/:temp") {
|
||||||
|
action: [
|
||||||
|
GET: "setThermostatHeatTemp"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/setThermostatCoolTemp/:deviceID/:temp") {
|
||||||
|
action: [
|
||||||
|
GET: "setThermostatCoolTemp"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/setThermostatHeat/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "setThermostatHeat"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/setThermostatCool/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "setThermostatCool"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/setThermostatMode/:deviceID/:mode") {
|
||||||
|
action: [
|
||||||
|
GET: "setThermostatMode"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/setThermostatFanMode/:deviceID/:mode") {
|
||||||
|
action: [
|
||||||
|
GET: "setThermostatFanMode"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/closeWindowShade/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "setWindowShadeClosed"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/openWindowShade/:deviceID") {
|
||||||
|
action: [
|
||||||
|
GET: "setWindowShadeOpen"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/awaySecurity") {
|
||||||
|
action: [
|
||||||
|
GET: "awaySecurity"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/staySecurity") {
|
||||||
|
action: [
|
||||||
|
GET: "staySecurity"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
path("/offSecurity") {
|
||||||
|
action: [
|
||||||
|
GET: "offSecurity"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user