mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-11 21:03:07 +00:00
Compare commits
3 Commits
MSA-1846-2
...
MSA-1849-1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2aa30fb45 | ||
|
|
f734c5490b | ||
|
|
a79d56e467 |
@@ -106,6 +106,12 @@ def parse(String description) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (map.name == "temperature") {
|
||||
if (tempOffset) {
|
||||
map.value = (int) map.value + (int) tempOffset
|
||||
}
|
||||
map.descriptionText = temperatureScale == 'C' ? '{{ device.displayName }} was {{ value }}°C' : '{{ device.displayName }} was {{ value }}°F'
|
||||
map.translatable = true
|
||||
}
|
||||
|
||||
log.debug "Parse returned $map"
|
||||
|
||||
@@ -112,6 +112,12 @@ def parse(String description) {
|
||||
map = getMotionResult(value)
|
||||
}
|
||||
}
|
||||
} else if (map.name == "temperature") {
|
||||
if (tempOffset) {
|
||||
map.value = (int) map.value + (int) tempOffset
|
||||
}
|
||||
map.descriptionText = temperatureScale == 'C' ? '{{ device.displayName }} was {{ value }}°C' : '{{ device.displayName }} was {{ value }}°F'
|
||||
map.translatable = true
|
||||
}
|
||||
|
||||
log.debug "Parse returned $map"
|
||||
|
||||
@@ -95,6 +95,12 @@ def parse(String description) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (map.name == "temperature") {
|
||||
if (tempOffset) {
|
||||
map.value = (int) map.value + (int) tempOffset
|
||||
}
|
||||
map.descriptionText = temperatureScale == 'C' ? '{{ device.displayName }} was {{ value }}°C' : '{{ device.displayName }} was {{ value }}°F'
|
||||
map.translatable = true
|
||||
}
|
||||
|
||||
log.debug "Parse returned $map"
|
||||
|
||||
@@ -88,6 +88,12 @@ def parse(String description) {
|
||||
log.warn "TEMP REPORTING CONFIG FAILED- error code: ${descMap.data[0]}"
|
||||
}
|
||||
}
|
||||
} else if (map.name == "temperature") {
|
||||
if (tempOffset) {
|
||||
map.value = (int) map.value + (int) tempOffset
|
||||
}
|
||||
map.descriptionText = temperatureScale == 'C' ? '{{ device.displayName }} was {{ value }}°C' : '{{ device.displayName }} was {{ value }}°F'
|
||||
map.translatable = true
|
||||
}
|
||||
|
||||
log.debug "Parse returned $map"
|
||||
|
||||
@@ -1,145 +0,0 @@
|
||||
/**
|
||||
* JSON
|
||||
*
|
||||
* Copyright 2015 Jesse Newland
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing permissions and limitations under the License.
|
||||
*
|
||||
*/
|
||||
definition(
|
||||
name: "JSON API",
|
||||
namespace: "jnewland",
|
||||
author: "Jesse Newland",
|
||||
description: "A JSON API for SmartThings",
|
||||
category: "SmartThings Labs",
|
||||
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
|
||||
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
|
||||
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
|
||||
oauth: true)
|
||||
|
||||
|
||||
def installed() {
|
||||
initialize()
|
||||
}
|
||||
|
||||
def updated() {
|
||||
unsubscribe()
|
||||
initialize()
|
||||
}
|
||||
|
||||
def initialize() {
|
||||
if (!state.accessToken) {
|
||||
createAccessToken()
|
||||
}
|
||||
}
|
||||
|
||||
preferences {
|
||||
page(name: "copyConfig")
|
||||
}
|
||||
|
||||
def copyConfig() {
|
||||
if (!state.accessToken) {
|
||||
createAccessToken()
|
||||
}
|
||||
dynamicPage(name: "copyConfig", title: "Config", install:true) {
|
||||
section("Select devices to include in the /devices API call") {
|
||||
input "switches", "capability.switch", title: "Switches", multiple: true, required: false
|
||||
input "hues", "capability.colorControl", title: "Hues", multiple: true, required: false
|
||||
}
|
||||
|
||||
section() {
|
||||
paragraph "View this SmartApp's configuration to use it in other places."
|
||||
href url:"https://graph.api.smartthings.com/api/smartapps/installations/${app.id}/config?access_token=${state.accessToken}", style:"embedded", required:false, title:"Config", description:"Tap, select, copy, then click \"Done\""
|
||||
}
|
||||
|
||||
section() {
|
||||
href url:"https://graph.api.smartthings.com/api/smartapps/installations/${app.id}/devices?access_token=${state.accessToken}", style:"embedded", required:false, title:"Debug", description:"View accessories JSON"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def renderConfig() {
|
||||
def configJson = new groovy.json.JsonOutput().toJson([
|
||||
description: "JSON API",
|
||||
platforms: [
|
||||
[
|
||||
platform: "SmartThings",
|
||||
name: "SmartThings",
|
||||
app_id: app.id,
|
||||
access_token: state.accessToken
|
||||
]
|
||||
],
|
||||
])
|
||||
|
||||
def configString = new groovy.json.JsonOutput().prettyPrint(configJson)
|
||||
render contentType: "text/plain", data: configString
|
||||
}
|
||||
|
||||
def deviceCommandMap(device, type) {
|
||||
device.supportedCommands.collectEntries { command->
|
||||
def commandUrl = "https://graph.api.smartthings.com/api/smartapps/installations/${app.id}/${type}/${device.id}/command/${command.name}?access_token=${state.accessToken}"
|
||||
[
|
||||
(command.name): commandUrl
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
def authorizedDevices() {
|
||||
[
|
||||
switches: switches,
|
||||
hues: hues
|
||||
]
|
||||
}
|
||||
|
||||
def renderDevices() {
|
||||
def deviceData = authorizedDevices().collectEntries { devices->
|
||||
[
|
||||
(devices.key): devices.value.collect { device->
|
||||
[
|
||||
name: device.displayName,
|
||||
commands: deviceCommandMap(device, devices.key)
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
def deviceJson = new groovy.json.JsonOutput().toJson(deviceData)
|
||||
def deviceString = new groovy.json.JsonOutput().prettyPrint(deviceJson)
|
||||
render contentType: "application/json", data: deviceString
|
||||
}
|
||||
|
||||
def deviceCommand() {
|
||||
def device = authorizedDevices()[params.type].find { it.id == params.id }
|
||||
def command = params.command
|
||||
if (!device) {
|
||||
httpError(404, "Device not found")
|
||||
} else {
|
||||
if (params.value) {
|
||||
device."$command"(params.value)
|
||||
} else {
|
||||
device."$command"()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mappings {
|
||||
if (!params.access_token || (params.access_token && params.access_token != state.accessToken)) {
|
||||
path("/devices") { action: [GET: "authError"] }
|
||||
path("/config") { action: [GET: "authError"] }
|
||||
path("/:type/:id/command/:command") { action: [PUT: "authError"] }
|
||||
} else {
|
||||
path("/devices") { action: [GET: "renderDevices"] }
|
||||
path("/config") { action: [GET: "renderConfig"] }
|
||||
path("/:type/:id/command/:command") { action: [PUT: "deviceCommand"] }
|
||||
}
|
||||
}
|
||||
|
||||
def authError() {
|
||||
[error: "Permission denied"]
|
||||
}
|
||||
113
smartapps/mrnohr/linked-presence.src/linked-presence.groovy
Normal file
113
smartapps/mrnohr/linked-presence.src/linked-presence.groovy
Normal file
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* Double Presence
|
||||
*
|
||||
* Copyright 2014 Matt Nohr
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing permissions and limitations under the License.
|
||||
*
|
||||
*/
|
||||
definition(
|
||||
name: "Linked Presence",
|
||||
namespace: "mrnohr",
|
||||
author: "Matt Nohr",
|
||||
description: "Send an alert of one presence sensor leaves without the other",
|
||||
category: "My Apps",
|
||||
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/text_presence.png",
|
||||
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/text_presence@2x.png")
|
||||
|
||||
/**
|
||||
* Based on the discussion here: http://community.smartthings.com/t/linking-presence-sensors-in-pairs-for-seniors/4915
|
||||
*
|
||||
* Get an alert if one presence sensor leaves without the other one. The alert could be turning on a light, or sending
|
||||
* a push/text message. The original idea was to monitor aging parents where one parent shouldn't be leaving the house
|
||||
* without the other one. Could also work with parents and children, making sure a child doesn't leave without a parent.
|
||||
*
|
||||
* It works by subscribing to "not present" events for the "dependant" presence sensor. If the "main" sensor hasn't also
|
||||
* recently left (in the past minute), then send the alert.
|
||||
*/
|
||||
preferences {
|
||||
section("Presence Sensors") {
|
||||
input "sensorDependant", "capability.presenceSensor", title: "When this person leaves alone"
|
||||
input "sensorMain", "capability.presenceSensor", title: "Without this person"
|
||||
input "timeDelay", "number", title: "With this delay (minutes)", default: 1
|
||||
}
|
||||
section("Alerts") {
|
||||
input "switches", "capability.switch", title: "Turn on some lights?", required: false, multiple: true
|
||||
input "sendPushMessage", "enum", title: "Send a push notification?", options: ["Yes", "No"], required: false
|
||||
input "phoneNumber", "phone", title: "Send a text message?", required: false
|
||||
}
|
||||
}
|
||||
|
||||
def installed() {
|
||||
log.debug "Installed with settings: ${settings}"
|
||||
|
||||
initialize()
|
||||
}
|
||||
|
||||
def updated() {
|
||||
log.debug "Updated with settings: ${settings}"
|
||||
|
||||
unsubscribe()
|
||||
unschedule()
|
||||
initialize()
|
||||
}
|
||||
|
||||
def initialize() {
|
||||
subscribe(sensorDependant, "presence.not present", "leavingHandler")
|
||||
}
|
||||
|
||||
//this will just handle scheduling/calling the checkOtherPresence method to handle the delay
|
||||
def leavingHandler(evt) {
|
||||
if(timeDelay > 0) {
|
||||
log.debug "scheduling presence check for $timeDelay minute(s)"
|
||||
runIn(timeDelay * 60, "checkOtherPresence")
|
||||
} else {
|
||||
checkOtherPresence()
|
||||
}
|
||||
}
|
||||
|
||||
def checkOtherPresence() {
|
||||
log.debug "checking other presence sensor"
|
||||
def dependantEvent = sensorDependant.latestState("presence")
|
||||
|
||||
//first make sure the dependant is still away
|
||||
if(dependantEvent.value == "not present") {
|
||||
//make sure there is an event first, just in the rare case there are no events
|
||||
def mainEvent = sensorMain.latestState("presence")
|
||||
if(mainEvent) {
|
||||
//compare latest events from both devices
|
||||
def eventTimeDifference = Math.abs(dependantEvent.date.time - mainEvent.date.time) / (1000 * 60) //minutes
|
||||
def allowedTimeDifference = 1 //maybe use same timeDelay?
|
||||
|
||||
//make sure dependant left with main
|
||||
if(mainEvent != "not present" || eventTimeDifference > allowedTimeDifference) {
|
||||
def message = "$sensorDependant left without $sensorMain"
|
||||
log.warn message
|
||||
send(message) // send push/text
|
||||
switches.on() // turn on lights
|
||||
}
|
||||
} else {
|
||||
//this should only happen if sensorMain is brand new and has never had any events
|
||||
log.warn "$sensorDependant left but no events for $sensorMain"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private send(msg) {
|
||||
if(sendPushMessage != "No") {
|
||||
log.debug "Sending push notification: $msg"
|
||||
sendPush(msg)
|
||||
}
|
||||
|
||||
if(phoneNumber) {
|
||||
log.debug "Sending text notification: $msg"
|
||||
sendSms(phoneNumber, msg)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user