Compare commits

..

3 Commits

Author SHA1 Message Date
Marco
d2aa30fb45 MSA-1849: Send an alert of one presence sensor leaves without the other 2017-03-18 18:30:04 -07:00
Zach Varberg
f734c5490b Merge pull request #1793 from varzac/fix-open-close-temp-offset
[DVCSMP-2516] Properly handle tempOffset in smartsense sensors
2017-03-17 08:56:17 -05:00
Zach Varberg
a79d56e467 Properly handle tempOffset in smartsense sensors
This was accidentally dropped as a part of the zigbee DTH cleanup that
was done a while ago.  This properly adjusts according to the offset.

This resolves: https://smartthings.atlassian.net/browse/DVCSMP-2516
2017-03-16 09:30:52 -05:00
6 changed files with 137 additions and 145 deletions

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"]
}

View 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)
}
}