Compare commits

..

1 Commits

2 changed files with 340 additions and 547 deletions

View File

@@ -0,0 +1,87 @@
/**
* Door Sensor Light Toggle
*
* Copyright 2017 Garrett Geier
*
* 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: "Toggle lights on/off using Door Sensor",
namespace: "GarrettGeier",
author: "Garrett Geier",
description: "Toggle lights on/off with a door sensor. When the door is opened, the lights will toggle based on the master switch.",
category: "Convenience",
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")
//main screen options
preferences
{
//choose the door/contact sensor here.
section("When this door is opened")
{
input "doorToggler", "capability.contactSensor", title: "Select Door Sensor", required: true, multiple: false
}
// this is the master switch. If this switch is ON, then the lights will turn OFF when the door is opened.
// If this switch is OFF, then the lights will turn ON when the door is opened.
// Don't care about if the door is closed, this is designed for a normal door which will eventually be shut. :)
section("Select the Master switch")
{
input "masterToggle", "capability.switch", title: "Master switch", required: true, multiple: false
}
//based on the master switch, these will turn on or off.
section("Stuff you want to turn on/off")
{
input "switchesToToggle", "capability.switch", title: "If master is ON, these will turn OFF. When the master is OFF, these will turn ON.", required: true, multiple: true
}
}
//required
def installed()
{
initialize()
}
//required
def updated()
{
unsubscribe()
initialize()
}
// the event we care about, when the door is opened.
// see http://docs.smartthings.com/en/latest/capabilities-reference.html#contactsensor for device capabilities
def initialize()
{
subscribe(doorToggler, "contact.open", toggleSwitches)
}
def toggleSwitches(evt)
{
//log.debug "$evt.value"
if (evt.value == "open" && masterToggle.currentSwitch == "off")
{
//log.debug "Light! Yay!"
switchesToToggle.on()
masterToggle.on()
}
else if (evt.value == "open" && masterToggle.currentSwitch == "on")
{
//log.debug "Kill the lights"
switchesToToggle.off()
masterToggle.off()
}
}

View File

@@ -1,547 +1,253 @@
/** /**
* Gideon * Gideon
* *
* Copyright 2016 Nicola Russo * Copyright 2016 Nicola Russo
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * 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: * in compliance with the License. You may obtain a copy of the License at:
* *
* http://www.apache.org/licenses/LICENSE-2.0 * 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 * 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 * 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. * for the specific language governing permissions and limitations under the License.
* *
*/ */
definition( definition(
name: "Gideon", name: "Gideon",
namespace: "gideon.api", namespace: "gideon.api",
author: "Braindrain Solutions ltd", author: "Braindrain Solutions",
description: "Gideon Smart Home SmartApp allows you to connect and control all of your SmartThings devices through the Gideon app, making your SmartThings devices even smarter.", description: "Gideon AI Smart app allows you to connect and control all of your SmartThings devices through the Gideon AI app, making your SmartThings devices even smarter.",
category: "Family", category: "Family",
iconUrl: "http://s33.postimg.org/t77u7y7v3/logo.png", iconUrl: "http://s33.postimg.org/t77u7y7v3/logo.png",
iconX2Url: "http://s33.postimg.org/t77u7y7v3/logo.png", iconX2Url: "http://s33.postimg.org/t77u7y7v3/logo.png",
iconX3Url: "http://s33.postimg.org/t77u7y7v3/logo.png", iconX3Url: "http://s33.postimg.org/t77u7y7v3/logo.png",
oauth: [displayName: "Gideon Smart Home API app", displayLink: "gideon.ai"]) oauth: [displayName: "Gideon AI API", displayLink: "gideon.ai"])
preferences { preferences {
section("Control these contact sensors...") { section("Control these switches...") {
input "contact", "capability.contactSensor", multiple:true, required:false input "switches", "capability.switch", multiple:true
} }
section("Control these switches...") { section("Control these motion sensors...") {
input "switches", "capability.switch", multiple:true, required:false input "motions", "capability.motionSensor", multiple:true
} }
section("Control these smoke alarms...") { section("Control these presence sensors...") {
input "smoke_alarms", "capability.smokeDetector", multiple:true, required:false input "presence_sensors", "capability.presenceSensor", multiple:true
} }
section("Control these window shades...") { section("Control these outlets...") {
input "shades", "capability.windowShade", multiple:true, required:false input "outlets", "capability.switch", multiple:true
} }
section("Control these garage doors...") { section("Control these locks...") {
input "garage", "capability.garageDoorControl", multiple:true, required:false input "locks", "capability.lock", multiple:true
} }
section("Control these water sensors...") { section("Control these locks...") {
input "water_sensors", "capability.waterSensor", multiple:true, required:false input "temperature_sensors", "capability.temperatureMeasurement"
} }
section("Control these motion sensors...") { }
input "motions", "capability.motionSensor", multiple:true, required:false
} def installed() {
section("Control these presence sensors...") { log.debug "Installed with settings: ${settings}"
input "presence_sensors", "capability.presenceSensor", multiple:true, required:false
} initialize()
/** section("Control these outlets...") { }
input "outlets", "capability.switch", multiple:true, required:false
} def updated() {
*/ log.debug "Updated with settings: ${settings}"
section("Control these power meters...") {
input "meters", "capability.powerMeter", multiple:true, required:false unsubscribe()
} initialize()
section("Control these locks...") { }
input "locks", "capability.lock", multiple:true, required:false
} def initialize() {
section("Control these temperature sensors...") { // TODO: subscribe to attributes, devices, locations, etc.
input "temperature_sensors", "capability.temperatureMeasurement", multiple:true, required:false subscribe(outlet, "energy", outletHandler)
} subscribe(outlet, "switch", outletHandler)
section("Control these batteries...") { }
input "batteries", "capability.battery", multiple:true, required:false
} // TODO: implement event handlers
} def outletHandler(evt) {
log.debug "$outlet.currentEnergy"
def installed() { //TODO call G API
log.debug "Installed with settings: ${settings}" }
initialize()
} private device(it, type) {
it ? [id: it.id, label: it.label, type: type] : null
def updated() { }
log.debug "Updated with settings: ${settings}"
//API Mapping
unsubscribe() mappings {
initialize() path("/getalldevices") {
} action: [
GET: "getAllDevices"
def initialize() { ]
} }
path("/doorlocks/:id/:command") {
private device(it, type) { action: [
it ? [id: it.id, label: it.label, type: type] : null GET: "updateDoorLock"
} ]
}
//API Mapping path("/doorlocks/:id") {
mappings { action: [
path("/getalldevices") { GET: "getDoorLockStatus"
action: [ ]
GET: "getAllDevices" }
] path("/tempsensors/:id") {
} action: [
path("/doorlocks/lock/:id") { GET: "getTempSensorsStatus"
action: [ ]
GET: "lockDoorLock" }
] path("/presences/:id") {
} action: [
path("/doorlocks/unlock/:id") { GET: "getPresenceStatus"
action: [ ]
GET: "unlockDoorLock" }
] path("/motions/:id") {
} action: [
path("/doorlocks/:id") { GET: "getMotionStatus"
action: [ ]
GET: "getDoorLockStatus" }
] path("/outlets/:id") {
} action: [
path("/contacts/:id") { GET: "getOutletStatus"
action: [ ]
GET: "getContactStatus" }
] path("/outlets/:id/:command") {
} action: [
path("/smoke/:id") { GET: "updateOutlet"
action: [ ]
GET: "getSmokeStatus" }
] path("/switches/:command") {
} action: [
path("/shades/open/:id") { PUT: "updateSwitch"
action: [ ]
GET: "openShade" }
] }
}
path("/shades/preset/:id") { //API Methods
action: [ def getAllDevices() {
GET: "presetShade" def locks_list = locks.collect{device(it,"Lock")}
] def presences_list = presence_sensors.collect{device(it,"Presence")}
} def motions_list = motions.collect{device(it,"Motion")}
path("/shades/close/:id") { def outlets_list = outlets.collect{device(it,"Outlet")}
action: [ def switches_list = switches.collect{device(it,"Switch")}
GET: "closeShade" def temp_list = temperature_sensors.collect{device(it,"Temperature")}
] return [Locks: locks_list, Presences: presences_list, Motions: motions_list, Outlets: outlets_list, Switches: switches_list, Temperatures: temp_list]
} }
path("/shades/:id") {
action: [ //LOCKS
GET: "getShadeStatus" def getDoorLockStatus() {
] def device = locks.find { it.id == params.id }
} if (!device) {
path("/garage/open/:id") { httpError(404, "Device not found")
action: [ } else {
GET: "openGarage" return [Device_state: device.currentValue('lock')]
] }
} }
path("/garage/close/:id") {
action: [ def updateDoorLock() {
GET: "closeGarage" def command = params.command
] def device = locks.find { it.id == params.id }
} if (command){
path("/garage/:id") { if (!device) {
action: [ httpError(404, "Device not found")
GET: "getGarageStatus" } else {
] if(command == "toggle")
} {
path("/watersensors/:id") { if(device.currentValue('lock') == "locked")
action: [ device.unlock();
GET: "getWaterSensorStatus" else
] device.lock();
}
path("/tempsensors/:id") { return [Device_id: params.id, result_action: "200"]
action: [ }
GET: "getTempSensorsStatus" }
] }
} }
path("/meters/:id") {
action: [ //PRESENCE
GET: "getMeterStatus" def getPresenceStatus() {
]
} def device = presence_sensors.find { it.id == params.id }
path("/batteries/:id") { if (!device) {
action: [ httpError(404, "Device not found")
GET: "getBatteryStatus" } else {
] return [Device_state: device.currentValue('presence')]
} }
path("/presences/:id") { }
action: [
GET: "getPresenceStatus" //MOTION
] def getMotionStatus() {
}
path("/motions/:id") { def device = motions.find { it.id == params.id }
action: [ if (!device) {
GET: "getMotionStatus" httpError(404, "Device not found")
] } else {
} return [Device_state: device.currentValue('motion')]
/** path("/outlets/:id") { }
action: [ }
GET: "getOutletStatus"
] //OUTLET
} def getOutletStatus() {
path("/outlets/turnon/:id") {
action: [ def device = outlets.find { it.id == params.id }
GET: "turnOnOutlet" if (!device) {
] httpError(404, "Device not found")
} } else {
path("/outlets/turnoff/:id") { return [Device_state: device.currentSwitch, Current_watt: device.currentValue("energy")]
action: [ }
GET: "turnOffOutlet" }
]
} def updateOutlet() {
*/
path("/switches/turnon/:id") { def command = params.command
action: [ def device = outlets.find { it.id == params.id }
GET: "turnOnSwitch" if (command){
] if (!device) {
} httpError(404, "Device not found")
path("/switches/turnoff/:id") { } else {
action: [ if(command == "toggle")
GET: "turnOffSwitch" {
] if(device.currentSwitch == "on")
} device.off();
path("/switches/:id") { else
action: [ device.on();
GET: "getSwitchStatus"
] return [Device_id: params.id, result_action: "200"]
} }
} }
}
//API Methods }
def getAllDevices() {
def locks_list = locks.collect{device(it,"Lock")} //SWITCH
def contact_list = contact.collect{device(it,"Contact Sensor")} def updateSwitch() {
def smokes_list = smoke_alarms.collect{device(it,"Smoke Alarm")} def command = params.command
def shades_list = shades.collect{device(it,"Window Shade")} def device = switches.find { it.id == params.id }
def garage_list = garage.collect{device(it,"Garage Door")} if (command){
def water_sensors_list = water_sensors.collect{device(it,"Water Sensor")} if (!device) {
def presences_list = presence_sensors.collect{device(it,"Presence")} httpError(404, "Device not found")
def motions_list = motions.collect{device(it,"Motion")} } else {
/** def outlets_list = outlets.collect{device(it,"Outlet")} */ if(command == "toggle")
def switches_list = switches.collect{device(it,"Switch")} {
def temp_list = temperature_sensors.collect{device(it,"Temperature")} if(device.currentSwitch == "on")
def meters_list = meters.collect{device(it,"Power Meters")} device.off();
def battery_list = batteries.collect{device(it,"Batteries")} else
return smokes_list + contact_list + water_sensors_list + shades_list + garage_list + locks_list + presences_list + motions_list + switches_list + temp_list + meters_list + battery_list device.on();
}
return [Device_id: params.id, result_action: "200"]
//contact sensors }
def getContactStatus() { }
def device = contact.find { it.id == params.id } }
if (!device) { }
httpError(404, "Device not found")
} else { //TEMPERATURE
def args = getTempSensorsStatus(device.id) def getTempSensorsStatus() {
return [Device_state: device.currentValue('contact')] + args
} def device = temperature_sensors.find { it.id == params.id }
} if (!device) {
httpError(404, "Device not found")
//smoke detectors } else {
def getSmokeStatus() { return [Device_state: device.currentValue('temperature')]
def device = smoke_alarms.find { it.id == params.id } }
if (!device) { }
httpError(404, "Device not found")
} else {
def bat = getBatteryStatus(device.id)
return [Device_state: device.currentValue('smoke')] + bat
}
}
//garage
def getGarageStatus() {
def device = garage.find { it.id == params.id }
if (!device) {
httpError(404, "Device not found")
} else {
return [Device_state: device.currentValue('door')]
}
}
def openGarage() {
def device = garage.find { it.id == params.id }
if (!device) {
httpError(404, "Device not found")
} else {
device.open();
return [Device_id: params.id, result_action: "200"]
}
}
def closeGarage() {
def device = garage.find { it.id == params.id }
if (!device) {
httpError(404, "Device not found")
} else {
device.close();
return [Device_id: params.id, result_action: "200"]
}
}
//shades
def getShadeStatus() {
def device = shades.find { it.id == params.id }
if (!device) {
httpError(404, "Device not found")
} else {
return [Device_state: device.currentValue('windowShade')]
}
}
def openShade() {
def device = shades.find { it.id == params.id }
if (!device) {
httpError(404, "Device not found")
} else {
device.open();
return [Device_id: params.id, result_action: "200"]
}
}
def presetShade() {
def device = shades.find { it.id == params.id }
if (!device) {
httpError(404, "Device not found")
} else {
device.presetPosition();
return [Device_id: params.id, result_action: "200"]
}
}
def closeShade() {
def device = shades.find { it.id == params.id }
if (!device) {
httpError(404, "Device not found")
} else {
device.close();
return [Device_id: params.id, result_action: "200"]
}
}
//water sensor
def getWaterSensorStatus() {
def device = water_sensors.find { it.id == params.id }
if (!device) {
httpError(404, "Device not found")
} else {
def bat = getBatteryStatus(device.id)
return [Device_state: device.currentValue('water')] + bat
}
}
//batteries
def getBatteryStatus() {
def device = batteries.find { it.id == params.id }
if (!device) {
httpError(404, "Device not found")
} else {
return [Device_state: device.latestValue("battery")]
}
}
def getBatteryStatus(id) {
def device = batteries.find { it.id == id }
if (!device) {
return []
} else {
return [battery_state: device.latestValue("battery")]
}
}
//LOCKS
def getDoorLockStatus() {
def device = locks.find { it.id == params.id }
if (!device) {
httpError(404, "Device not found")
} else {
def bat = getBatteryStatus(device.id)
return [Device_state: device.currentValue('lock')] + bat
}
}
def lockDoorLock() {
def device = locks.find { it.id == params.id }
if (!device) {
httpError(404, "Device not found")
} else {
device.lock();
return [Device_id: params.id, result_action: "200"]
}
}
def unlockDoorLock() {
def device = locks.find { it.id == params.id }
if (!device) {
httpError(404, "Device not found")
} else {
device.unlock();
return [Device_id: params.id, result_action: "200"]
}
}
//PRESENCE
def getPresenceStatus() {
def device = presence_sensors.find { it.id == params.id }
if (!device) {
httpError(404, "Device not found")
} else {
def bat = getBatteryStatus(device.id)
return [Device_state: device.currentValue('presence')] + bat
}
}
//MOTION
def getMotionStatus() {
def device = motions.find { it.id == params.id }
if (!device) {
httpError(404, "Device not found")
} else {
def args = getTempSensorsStatus(device.id)
return [Device_state: device.currentValue('motion')] + args
}
}
//OUTLET
/**
def getOutletStatus() {
def device = outlets.find { it.id == params.id }
if (!device) {
httpError(404, "Device not found")
} else {
def watt = getMeterStatus(device.id)
return [Device_state: device.currentSwitch] + watt
}
}
*/
def getMeterStatus() {
def device = meters.find { it.id == params.id }
if (!device) {
httpError(404, "Device not found")
} else {
return [Device_id: device.id, Device_type: device.type, Current_watt: device.currentValue("power")]
}
}
def getMeterStatus(id) {
def device = meters.find { it.id == id }
if (!device) {
return []
} else {
return [Current_watt: device.currentValue("power")]
}
}
/**
def turnOnOutlet() {
def device = outlets.find { it.id == params.id }
if (command){
if (!device) {
httpError(404, "Device not found")
} else {
device.on();
return [Device_id: params.id, result_action: "200"]
}
}
}
def turnOffOutlet() {
def device = outlets.find { it.id == params.id }
if (command){
if (!device) {
httpError(404, "Device not found")
} else {
device.off();
return [Device_id: params.id, result_action: "200"]
}
}
}
*/
//SWITCH
def getSwitchStatus() {
def device = switches.find { it.id == params.id }
if (!device) {
httpError(404, "Device not found")
} else {
return [Device_state: device.currentValue('switch')]
}
}
def turnOnSwitch() {
def device = switches.find { it.id == params.id }
if (command){
if (!device) {
httpError(404, "Device not found")
} else {
device.on();
return [Device_id: params.id, result_action: "200"]
}
}
}
def turnOffSwitch() {
def device = switches.find { it.id == params.id }
if (command){
if (!device) {
httpError(404, "Device not found")
} else {
device.on();
return [Device_id: params.id, result_action: "200"]
}
}
}
//TEMPERATURE
def getTempSensorsStatus() {
def device = temperature_sensors.find { it.id == params.id }
if (!device) {
httpError(404, "Device not found")
} else {
def bat = getBatteryStatus(device.id)
return [Device_state: device.currentValue('temperature')] + bat
}
}
def getTempSensorsStatus(id) {
def device = temperature_sensors.find { it.id == id }
if (!device) {
return []
} else {
def bat = getBatteryStatus(device.id)
return [temperature: device.currentValue('temperature')] + bat
}
}