Compare commits

...

9 Commits

Author SHA1 Message Date
이진희
7a92ba3fe5 MSA-993: 테스트 2016-03-23 02:47:25 -05:00
tslagle13
03c2dec425 Merge pull request #667 from tslagle13/fixes-to-vacation-lighting-director
Update vacation-lighting-director.groovy
2016-03-22 17:38:42 -07:00
tslagle13
38d0ca6170 Update vacation-lighting-director.groovy
* Moved scheduling over to Cron and added time as a trigger. 
 * Cleaned up formatting and some typos.
 * Updated license.
 * Made people option optional
 * Added sttement to unschedule on mode change if people option is not selected
2016-03-22 13:00:49 -07:00
Duncan McKee
836dd608c6 Merge pull request #539 from SmartThingsCommunity/DEVFRWK-78
Fix First Alert smoke alarm check-in handling
2016-03-21 22:33:07 -04:00
Juan Pablo Risso
43e4db28eb Merge pull request #660 from juano2310/hue_discover
Added hubVerification()
2016-03-21 16:21:33 -04:00
juano2310
df421a51ac Added hubVerification()
If the hub exist as a thing parsing the response from description.xml
was lost. Now it is sent back to the parent were the device can be
marked as verified if the modelName starts with "Philips hue bridge"
2016-03-21 14:38:24 -04:00
Duncan McKee
3affdd21fc Merge pull request #540 from SmartThingsCommunity/DVCSMP-1438
Z-Wave Motion Sensor: fix MissingMethodException on NotificationReport
2016-03-21 12:21:30 -04:00
Duncan McKee
e61be4ff9c DVCSMP-1438: Fix Z-Wave Motion handling of Notification Report 2016-02-22 14:55:58 -05:00
Duncan McKee
6123fbeea5 DEVFRWK-78 Fix First Alert smoke alarm check-in handling 2016-02-22 13:52:56 -05:00
7 changed files with 349 additions and 161 deletions

View File

@@ -0,0 +1,42 @@
/**
* 내가만든장치
*
* Copyright 2016 이진희
*
* 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.
*
*/
metadata {
definition (name: "내가만든장치", namespace: "내가만든장치", author: "이진희") {
capability "Health Check"
capability "Test Capability"
}
simulator {
// TODO: define status and reply messages here
}
tiles {
// TODO: define your main and details tiles here
}
}
// parse events into attributes
def parse(String description) {
log.debug "Parsing '${description}'"
// TODO: handle 'checkInterval' attribute
}
// handle commands
def ping() {
log.debug "Executing 'ping'"
// TODO: handle 'ping' command
}

View File

@@ -17,16 +17,13 @@ metadata {
tiles(scale: 2) { tiles(scale: 2) {
multiAttributeTile(name:"rich-control"){ multiAttributeTile(name:"rich-control"){
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") { tileAttribute ("", key: "PRIMARY_CONTROL") {
attributeState "default", label: "Hue Bridge", action: "", icon: "st.Lighting.light99-hue", backgroundColor: "#F3C200" attributeState "default", label: "Hue Bridge", action: "", icon: "st.Lighting.light99-hue", backgroundColor: "#F3C200"
} }
tileAttribute ("serialNumber", key: "SECONDARY_CONTROL") { tileAttribute ("serialNumber", key: "SECONDARY_CONTROL") {
attributeState "default", label:'SN: ${currentValue}' attributeState "default", label:'SN: ${currentValue}'
} }
} }
standardTile("icon", "icon", width: 1, height: 1, canChangeIcon: false, inactiveLabel: true, canChangeBackground: false) {
state "default", label: "Hue Bridge", action: "", icon: "st.Lighting.light99-hue", backgroundColor: "#FFFFFF"
}
valueTile("serialNumber", "device.serialNumber", decoration: "flat", height: 1, width: 2, inactiveLabel: false) { valueTile("serialNumber", "device.serialNumber", decoration: "flat", height: 1, width: 2, inactiveLabel: false) {
state "default", label:'SN: ${currentValue}' state "default", label:'SN: ${currentValue}'
} }
@@ -34,7 +31,7 @@ metadata {
state "default", label:'${currentValue}', height: 1, width: 2, inactiveLabel: false state "default", label:'${currentValue}', height: 1, width: 2, inactiveLabel: false
} }
main (["icon"]) main (["rich-control"])
details(["rich-control", "networkAddress"]) details(["rich-control", "networkAddress"])
} }
} }
@@ -75,6 +72,7 @@ def parse(description) {
} }
else if (contentType?.contains("xml")) { else if (contentType?.contains("xml")) {
log.debug "HUE BRIDGE ALREADY PRESENT" log.debug "HUE BRIDGE ALREADY PRESENT"
parent.hubVerification(device.hub.id, msg.body)
} }
} }
} }

View File

@@ -57,7 +57,7 @@ def parse(String description) {
return result return result
} }
def sensorValueEvent(Short value) { def sensorValueEvent(value) {
if (value) { if (value) {
createEvent(name: "motion", value: "active", descriptionText: "$device.displayName detected motion") createEvent(name: "motion", value: "active", descriptionText: "$device.displayName detected motion")
} else { } else {
@@ -94,24 +94,24 @@ def zwaveEvent(physicalgraph.zwave.commands.notificationv3.NotificationReport cm
{ {
def result = [] def result = []
if (cmd.notificationType == 0x07) { if (cmd.notificationType == 0x07) {
if (cmd.event == 0x01 || cmd.event == 0x02) { if (cmd.v1AlarmType == 0x07) { // special case for nonstandard messages from Monoprice ensors
result << sensorValueEvent(cmd.v1AlarmLevel)
} else if (cmd.event == 0x01 || cmd.event == 0x02 || cmd.event == 0x07 || cmd.event == 0x08) {
result << sensorValueEvent(1) result << sensorValueEvent(1)
} else if (cmd.event == 0x00) {
result << sensorValueEvent(0)
} else if (cmd.event == 0x03) { } else if (cmd.event == 0x03) {
result << createEvent(descriptionText: "$device.displayName covering was removed", isStateChange: true) result << createEvent(name: "tamper", value: "detected", descriptionText: "$device.displayName covering was removed", isStateChange: true)
result << response(zwave.wakeUpV1.wakeUpIntervalSet(seconds:4*3600, nodeid:zwaveHubNodeId)) result << response(zwave.batteryV1.batteryGet())
if(!state.MSR) result << response(zwave.manufacturerSpecificV2.manufacturerSpecificGet())
} else if (cmd.event == 0x05 || cmd.event == 0x06) { } else if (cmd.event == 0x05 || cmd.event == 0x06) {
result << createEvent(descriptionText: "$device.displayName detected glass breakage", isStateChange: true) result << createEvent(descriptionText: "$device.displayName detected glass breakage", isStateChange: true)
} else if (cmd.event == 0x07) {
if(!state.MSR) result << response(zwave.manufacturerSpecificV2.manufacturerSpecificGet())
result << sensorValueEvent(1)
} }
} else if (cmd.notificationType) { } else if (cmd.notificationType) {
def text = "Notification $cmd.notificationType: event ${([cmd.event] + cmd.eventParameter).join(", ")}" def text = "Notification $cmd.notificationType: event ${([cmd.event] + cmd.eventParameter).join(", ")}"
result << createEvent(name: "notification$cmd.notificationType", value: "$cmd.event", descriptionText: text, displayed: false) result << createEvent(name: "notification$cmd.notificationType", value: "$cmd.event", descriptionText: text, isStateChange: true, displayed: false)
} else { } else {
def value = cmd.v1AlarmLevel == 255 ? "active" : cmd.v1AlarmLevel ?: "inactive" def value = cmd.v1AlarmLevel == 255 ? "active" : cmd.v1AlarmLevel ?: "inactive"
result << createEvent(name: "alarm $cmd.v1AlarmType", value: value, displayed: false) result << createEvent(name: "alarm $cmd.v1AlarmType", value: value, isStateChange: true, displayed: false)
} }
result result
} }

View File

@@ -61,37 +61,44 @@ def parse(String description) {
zwaveEvent(cmd, results) zwaveEvent(cmd, results)
} }
} }
// log.debug "\"$description\" parsed to ${results.inspect()}" log.debug "'$description' parsed to ${results.inspect()}"
return results return results
} }
def createSmokeOrCOEvents(name, results) { def createSmokeOrCOEvents(name, results) {
def text = null def text = null
if (name == "smoke") { switch (name) {
text = "$device.displayName smoke was detected!" case "smoke":
// these are displayed:false because the composite event is the one we want to see in the app text = "$device.displayName smoke was detected!"
results << createEvent(name: "smoke", value: "detected", descriptionText: text, displayed: false) // these are displayed:false because the composite event is the one we want to see in the app
} else if (name == "carbonMonoxide") { results << createEvent(name: "smoke", value: "detected", descriptionText: text, displayed: false)
text = "$device.displayName carbon monoxide was detected!" break
results << createEvent(name: "carbonMonoxide", value: "detected", descriptionText: text, displayed: false) case "carbonMonoxide":
} else if (name == "tested") { text = "$device.displayName carbon monoxide was detected!"
text = "$device.displayName was tested" results << createEvent(name: "carbonMonoxide", value: "detected", descriptionText: text, displayed: false)
results << createEvent(name: "smoke", value: "tested", descriptionText: text, displayed: false) break
results << createEvent(name: "carbonMonoxide", value: "tested", descriptionText: text, displayed: false) case "tested":
} else if (name == "smokeClear") { text = "$device.displayName was tested"
text = "$device.displayName smoke is clear" results << createEvent(name: "smoke", value: "tested", descriptionText: text, displayed: false)
results << createEvent(name: "smoke", value: "clear", descriptionText: text, displayed: false) results << createEvent(name: "carbonMonoxide", value: "tested", descriptionText: text, displayed: false)
name = "clear" break
} else if (name == "carbonMonoxideClear") { case "smokeClear":
text = "$device.displayName carbon monoxide is clear" text = "$device.displayName smoke is clear"
results << createEvent(name: "carbonMonoxide", value: "clear", descriptionText: text, displayed: false) results << createEvent(name: "smoke", value: "clear", descriptionText: text, displayed: false)
name = "clear" name = "clear"
} else if (name == "testClear") { break
text = "$device.displayName smoke is clear" case "carbonMonoxideClear":
results << createEvent(name: "smoke", value: "clear", descriptionText: text, displayed: false) text = "$device.displayName carbon monoxide is clear"
results << createEvent(name: "carbonMonoxide", value: "clear", displayed: false) results << createEvent(name: "carbonMonoxide", value: "clear", descriptionText: text, displayed: false)
name = "clear" name = "clear"
break
case "testClear":
text = "$device.displayName test cleared"
results << createEvent(name: "smoke", value: "clear", descriptionText: text, displayed: false)
results << createEvent(name: "carbonMonoxide", value: "clear", displayed: false)
name = "clear"
break
} }
// This composite event is used for updating the tile // This composite event is used for updating the tile
results << createEvent(name: "alarmState", value: name, descriptionText: text) results << createEvent(name: "alarmState", value: name, descriptionText: text)
@@ -117,8 +124,10 @@ def zwaveEvent(physicalgraph.zwave.commands.alarmv2.AlarmReport cmd, results) {
createSmokeOrCOEvents(cmd.alarmLevel ? "tested" : "testClear", results) createSmokeOrCOEvents(cmd.alarmLevel ? "tested" : "testClear", results)
break break
case 13: // sent every hour -- not sure what this means, just a wake up notification? case 13: // sent every hour -- not sure what this means, just a wake up notification?
if (cmd.alarmLevel != 255) { if (cmd.alarmLevel == 255) {
results << createEvent(descriptionText: "$device.displayName code 13 is $cmd.alarmLevel", displayed: true) results << createEvent(descriptionText: "$device.displayName checked in", isStateChange: false)
} else {
results << createEvent(descriptionText: "$device.displayName code 13 is $cmd.alarmLevel", isStateChange:true, displayed:false)
} }
// Clear smoke in case they pulled batteries and we missed the clear msg // Clear smoke in case they pulled batteries and we missed the clear msg
@@ -127,9 +136,8 @@ def zwaveEvent(physicalgraph.zwave.commands.alarmv2.AlarmReport cmd, results) {
} }
// Check battery if we don't have a recent battery event // Check battery if we don't have a recent battery event
def prevBattery = device.currentState("battery") if (!state.lastbatt || (now() - state.lastbatt) >= 48*60*60*1000) {
if (!prevBattery || (new Date().time - prevBattery.date.time)/60000 >= 60 * 53) { results << response(zwave.batteryV1.batteryGet())
results << new physicalgraph.device.HubAction(zwave.batteryV1.batteryGet().format())
} }
break break
default: default:
@@ -158,12 +166,17 @@ def zwaveEvent(physicalgraph.zwave.commands.sensoralarmv1.SensorAlarmReport cmd,
} }
def zwaveEvent(physicalgraph.zwave.commands.wakeupv1.WakeUpNotification cmd, results) { def zwaveEvent(physicalgraph.zwave.commands.wakeupv1.WakeUpNotification cmd, results) {
results << new physicalgraph.device.HubAction(zwave.wakeUpV1.wakeUpNoMoreInformation().format())
results << createEvent(descriptionText: "$device.displayName woke up", isStateChange: false) results << createEvent(descriptionText: "$device.displayName woke up", isStateChange: false)
if (!state.lastbatt || (now() - state.lastbatt) >= 56*60*60*1000) {
results << response(zwave.batteryV1.batteryGet(), "delay 2000", zwave.wakeUpV1.wakeUpNoMoreInformation())
} else {
results << response(zwave.wakeUpV1.wakeUpNoMoreInformation())
}
} }
def zwaveEvent(physicalgraph.zwave.commands.batteryv1.BatteryReport cmd, results) { def zwaveEvent(physicalgraph.zwave.commands.batteryv1.BatteryReport cmd, results) {
def map = [ name: "battery", unit: "%" ] def map = [ name: "battery", unit: "%", isStateChange: true ]
state.lastbatt = now()
if (cmd.batteryLevel == 0xFF) { if (cmd.batteryLevel == 0xFF) {
map.value = 1 map.value = 1
map.descriptionText = "$device.displayName battery is low!" map.descriptionText = "$device.displayName battery is low!"

View File

@@ -68,7 +68,7 @@ def bridgeDiscovery(params=[:])
} }
//setup.xml request every 3 seconds except on discoveries //setup.xml request every 3 seconds except on discoveries
if(((bridgeRefreshCount % 1) == 0) && ((bridgeRefreshCount % 5) != 0)) { if(((bridgeRefreshCount % 3) == 0) && ((bridgeRefreshCount % 5) != 0)) {
verifyHueBridges() verifyHueBridges()
} }
@@ -175,6 +175,7 @@ private discoverHueBulbs() {
} }
private verifyHueBridge(String deviceNetworkId, String host) { private verifyHueBridge(String deviceNetworkId, String host) {
log.trace "Verify Hue Bridge $deviceNetworkId"
sendHubCommand(new physicalgraph.device.HubAction([ sendHubCommand(new physicalgraph.device.HubAction([
method: "GET", method: "GET",
path: "/description.xml", path: "/description.xml",
@@ -602,6 +603,20 @@ def parse(childDevice, description) {
} }
} }
def hubVerification(bodytext) {
log.trace "Bridge sent back description.xml for verification"
def body = new XmlSlurper().parseText(bodytext)
if (body?.device?.modelName?.text().startsWith("Philips hue bridge")) {
def bridges = getHueBridges()
def bridge = bridges.find {it?.key?.contains(body?.device?.UDN?.text())}
if (bridge) {
bridge.value << [name:body?.device?.friendlyName?.text(), serialNumber:body?.device?.serialNumber?.text(), verified: true]
} else {
log.error "/description.xml returned a bridge that didn't exist"
}
}
}
def on(childDevice) { def on(childDevice) {
log.debug "Executing 'on'" log.debug "Executing 'on'"
put("lights/${getId(childDevice)}/state", [on: true]) put("lights/${getId(childDevice)}/state", [on: true])

View File

@@ -0,0 +1,50 @@
/**
* test 앱
*
* Copyright 2016 이진희
*
* 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: "test 앱",
namespace: "test앱",
author: "이진희",
description: "\uD14C\uC2A4\uD2B8\uC785\uB2C8\uB2E4",
category: "",
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")
preferences {
section("Title") {
// TODO: put inputs here
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}
def initialize() {
// TODO: subscribe to attributes, devices, locations, etc.
}
// TODO: implement event handlers

View File

@@ -1,11 +1,17 @@
/** /**
* Vacation Lighting Director * Vacation Lighting Director
* *
* Version 2.4 - Added information paragraphs * Version 2.5 - Moved scheduling over to Cron and added time as a trigger.
* Cleaned up formatting and some typos.
* Updated license.
* Made people option optional
* Added sttement to unschedule on mode change if people option is not selected
*
* Version 2.4 - Added information paragraphs
* *
* Source code can be found here: https://github.com/tslagle13/SmartThings/blob/master/smartapps/tslagle13/vacation-lighting-director.groovy * Source code can be found here: https://github.com/tslagle13/SmartThings/blob/master/smartapps/tslagle13/vacation-lighting-director.groovy
* *
* Copyright 2015 Tim Slagle * Copyright 2016 Tim Slagle
* *
* 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:
@@ -51,8 +57,7 @@ def pageSetup() {
return dynamicPage(pageProperties) { return dynamicPage(pageProperties) {
section(""){ section(""){
paragraph "This app can be used to make your home seem occupied anytime you are away from your home. " + paragraph "This app can be used to make your home seem occupied anytime you are away from your home. " +
"Please use each othe the sections below to setup the different preferences to your liking. " + "Please use each of the the sections below to setup the different preferences to your liking. "
"I recommend this app be used with at least two away modes. An example would be 'Away Day' 'and Away Night'. "
} }
section("Setup Menu") { section("Setup Menu") {
href "Setup", title: "Setup", description: "", state:greyedOut() href "Setup", title: "Setup", description: "", state:greyedOut()
@@ -70,7 +75,7 @@ def Setup() {
def newMode = [ def newMode = [
name: "newMode", name: "newMode",
type: "mode", type: "mode",
title: "Which?", title: "Modes",
multiple: true, multiple: true,
required: true required: true
] ]
@@ -96,14 +101,6 @@ def Setup() {
required: true, required: true,
] ]
def people = [
name: "people",
type: "capability.presenceSensor",
title: "If these people are home do not change light status",
required: true,
multiple: true
]
def pageName = "Setup" def pageName = "Setup"
def pageProperties = [ def pageProperties = [
@@ -116,10 +113,11 @@ def Setup() {
section(""){ section(""){
paragraph "In this section you need to setup the deatils of how you want your lighting to be affected while " + paragraph "In this section you need to setup the deatils of how you want your lighting to be affected while " +
paragraph "you are away. All of these settings are required in order for the simulator to run correctly." "you are away. All of these settings are required in order for the simulator to run correctly."
} }
section("Which mode change triggers the simulator? (This app will only run in selected mode(s))") { section("Simulator Triggers") {
input newMode input newMode
href "timeIntervalInput", title: "Times", description: timeIntervalLabel(), refreshAfterSelection:true
} }
section("Light switches to turn on/off") { section("Light switches to turn on/off") {
input switches input switches
@@ -130,9 +128,6 @@ def Setup() {
section("Number of active lights at any given time") { section("Number of active lights at any given time") {
input number_of_active_lights input number_of_active_lights
} }
section("People") {
input people
}
} }
} }
@@ -162,18 +157,29 @@ def Settings() {
title: "Settings", title: "Settings",
nextPage: "pageSetup" nextPage: "pageSetup"
] ]
def people = [
name: "people",
type: "capability.presenceSensor",
title: "If these people are home do not change light status",
required: false,
multiple: true
]
return dynamicPage(pageProperties) { return dynamicPage(pageProperties) {
section(""){ section(""){
paragraph "In this section you can restrict how your simulator runs. For instance you can restrict on which days it will run " + paragraph "In this section you can restrict how your simulator runs. For instance you can restrict on which days it will run " +
paragraph "as well as a delay for the simulator to start after it is in the correct mode. Delaying the simulator helps with false starts based on a incorrect mode change." "as well as a delay for the simulator to start after it is in the correct mode. Delaying the simulator helps with false starts based on a incorrect mode change."
} }
section("Delay to start simulator") { section("Delay to start simulator") {
input falseAlarmThreshold input falseAlarmThreshold
} }
section("People") {
paragraph "Not using this setting may cause some lights to remain on when you arrive home"
input people
}
section("More options") { section("More options") {
href "timeIntervalInput", title: "Only during a certain time", description: getTimeLabel(starting, ending), state: greyedOutTime(starting, ending), refreshAfterSelection:true
input days input days
} }
} }
@@ -181,9 +187,24 @@ def Settings() {
page(name: "timeIntervalInput", title: "Only during a certain time", refreshAfterSelection:true) { page(name: "timeIntervalInput", title: "Only during a certain time", refreshAfterSelection:true) {
section { section {
input "starting", "time", title: "Starting", required: false input "startTimeType", "enum", title: "Starting at", options: [["time": "A specific time"], ["sunrise": "Sunrise"], ["sunset": "Sunset"]], defaultValue: "time", submitOnChange: true
input "ending", "time", title: "Ending", required: false if (startTimeType in ["sunrise","sunset"]) {
input "startTimeOffset", "number", title: "Offset in minutes (+/-)", range: "*..*", required: false
}
else {
input "starting", "time", title: "Start time", required: false
}
} }
section {
input "endTimeType", "enum", title: "Ending at", options: [["time": "A specific time"], ["sunrise": "Sunrise"], ["sunset": "Sunset"]], defaultValue: "time", submitOnChange: true
if (endTimeType in ["sunrise","sunset"]) {
input "endTimeOffset", "number", title: "Offset in minutes (+/-)", range: "*..*", required: false
}
else {
input "ending", "time", title: "End time", required: false
}
}
} }
def installed() { def installed() {
@@ -201,10 +222,13 @@ def initialize(){
if (newMode != null) { if (newMode != null) {
subscribe(location, modeChangeHandler) subscribe(location, modeChangeHandler)
} }
if (starting != null) {
schedule(starting, modeChangeHandler)
}
log.debug "Installed with settings: ${settings}"
} }
def modeChangeHandler(evt) { def modeChangeHandler(evt) {
log.debug "Mode change to: ${evt.value}"
def delay = (falseAlarmThreshold != null && falseAlarmThreshold != "") ? falseAlarmThreshold * 60 : 2 * 60 def delay = (falseAlarmThreshold != null && falseAlarmThreshold != "") ? falseAlarmThreshold * 60 : 2 * 60
runIn(delay, scheduleCheck) runIn(delay, scheduleCheck)
} }
@@ -212,48 +236,54 @@ def modeChangeHandler(evt) {
//Main logic to pick a random set of lights from the large set of lights to turn on and then turn the rest off //Main logic to pick a random set of lights from the large set of lights to turn on and then turn the rest off
def scheduleCheck(evt) { def scheduleCheck(evt) {
if(allOk){ if(allOk){
log.debug("Running") log.debug("Running")
// turn off all the switches // turn off all the switches
switches.off() switches.off()
// grab a random switch // grab a random switch
def random = new Random() def random = new Random()
def inactive_switches = switches def inactive_switches = switches
for (int i = 0 ; i < number_of_active_lights ; i++) { for (int i = 0 ; i < number_of_active_lights ; i++) {
// if there are no inactive switches to turn on then let's break // if there are no inactive switches to turn on then let's break
if (inactive_switches.size() == 0){ if (inactive_switches.size() == 0){
break break
}
// grab a random switch and turn it on
def random_int = random.nextInt(inactive_switches.size())
inactive_switches[random_int].on()
// then remove that switch from the pool off switches that can be turned on
inactive_switches.remove(random_int)
}
// re-run again when the frequency demands it
schedule("0 0/${frequency_minutes} * 1/1 * ? *", scheduleCheck)
} }
//Check to see if mode is ok but not time/day. If mode is still ok, check again after frequency period.
// grab a random switch and turn it on else if (modeOk) {
def random_int = random.nextInt(inactive_switches.size()) log.debug("mode OK. Running again")
inactive_switches[random_int].on() switches.off()
}
// then remove that switch from the pool off switches that can be turned on //if none is ok turn off frequency check and turn off lights.
inactive_switches.remove(random_int) else {
} if(people){
//don't turn off lights if anyone is home
// re-run again when the frequency demands it if(someoneIsHome()){
runIn(frequency_minutes * 60, scheduleCheck) log.debug("Stopping Check for Light")
} unschedule()
//Check to see if mode is ok but not time/day. If mode is still ok, check again after frequency period. }
else if (modeOk) { else{
log.debug("mode OK. Running again") log.debug("Stopping Check for Light and turning off all lights")
runIn(frequency_minutes * 60, scheduleCheck) switches.off()
switches.off() unschedule()
} }
//if none is ok turn off frequency check and turn off lights.
else if(people){
//don't turn off lights if anyone is home
if(someoneIsHome()){
log.debug("Stopping Check for Light")
} }
else{ else if (!modeOk) {
log.debug("Stopping Check for Light and turning off all lights") unschedule()
switches.off() }
} }
}
} }
@@ -286,26 +316,6 @@ private getDaysOk() {
result result
} }
private getTimeOk() {
def result = true
if (starting && ending) {
def currTime = now()
def start = timeToday(starting).time
def stop = timeToday(ending).time
result = start < stop ? currTime >= start && currTime <= stop : currTime <= stop || currTime >= start
}
else if (starting){
result = currTime >= start
}
else if (ending){
result = currTime <= stop
}
log.trace "timeOk = $result"
result
}
private getHomeIsEmpty() { private getHomeIsEmpty() {
def result = true def result = true
@@ -330,25 +340,59 @@ private getSomeoneIsHome() {
return result return result
} }
private getTimeOk() {
//gets the label for time restriction. Label phrasing changes depending on if there is both start and stop times or just one start/stop time. def result = true
def getTimeLabel(starting, ending){ def start = timeWindowStart()
def stop = timeWindowStop()
def timeLabel = "Tap to set" if (start && stop && location.timeZone) {
result = timeOfDayIsBetween(start, stop, new Date(), location.timeZone)
if(starting && ending){ }
timeLabel = "Between" + " " + hhmm(starting) + " " + "and" + " " + hhmm(ending) log.trace "timeOk = $result"
} result
else if (starting) { }
timeLabel = "Start at" + " " + hhmm(starting)
} private timeWindowStart() {
else if(ending){ def result = null
timeLabel = "End at" + hhmm(ending) if (startTimeType == "sunrise") {
} result = location.currentState("sunriseTime")?.dateValue
timeLabel if (result && startTimeOffset) {
result = new Date(result.time + Math.round(startTimeOffset * 60000))
}
}
else if (startTimeType == "sunset") {
result = location.currentState("sunsetTime")?.dateValue
if (result && startTimeOffset) {
result = new Date(result.time + Math.round(startTimeOffset * 60000))
}
}
else if (starting && location.timeZone) {
result = timeToday(starting, location.timeZone)
}
log.trace "timeWindowStart = ${result}"
result
}
private timeWindowStop() {
def result = null
if (endTimeType == "sunrise") {
result = location.currentState("sunriseTime")?.dateValue
if (result && endTimeOffset) {
result = new Date(result.time + Math.round(endTimeOffset * 60000))
}
}
else if (endTimeType == "sunset") {
result = location.currentState("sunsetTime")?.dateValue
if (result && endTimeOffset) {
result = new Date(result.time + Math.round(endTimeOffset * 60000))
}
}
else if (ending && location.timeZone) {
result = timeToday(ending, location.timeZone)
}
log.trace "timeWindowStop = ${result}"
result
} }
//fomrats time to readable format for time label
private hhmm(time, fmt = "h:mm a") private hhmm(time, fmt = "h:mm a")
{ {
def t = timeToday(time, location.timeZone) def t = timeToday(time, location.timeZone)
@@ -357,6 +401,41 @@ private hhmm(time, fmt = "h:mm a")
f.format(t) f.format(t)
} }
private timeIntervalLabel() {
def start = ""
switch (startTimeType) {
case "time":
if (ending) {
start += hhmm(starting)
}
break
case "sunrise":
case "sunset":
start += startTimeType[0].toUpperCase() + startTimeType[1..-1]
if (startTimeOffset) {
start += startTimeOffset > 0 ? "+${startTimeOffset} min" : "${startTimeOffset} min"
}
break
}
def finish = ""
switch (endTimeType) {
case "time":
if (ending) {
finish += hhmm(ending)
}
break
case "sunrise":
case "sunset":
finish += endTimeType[0].toUpperCase() + endTimeType[1..-1]
if (endTimeOffset) {
finish += endTimeOffset > 0 ? "+${endTimeOffset} min" : "${endTimeOffset} min"
}
break
}
start && finish ? "${start} to ${finish}" : ""
}
//sets complete/not complete for the setup section on the main dynamic page //sets complete/not complete for the setup section on the main dynamic page
def greyedOut(){ def greyedOut(){
def result = "" def result = ""
@@ -369,16 +448,7 @@ def greyedOut(){
//sets complete/not complete for the settings section on the main dynamic page //sets complete/not complete for the settings section on the main dynamic page
def greyedOutSettings(){ def greyedOutSettings(){
def result = "" def result = ""
if (starting || ending || days || falseAlarmThreshold) { if (people || days || falseAlarmThreshold ) {
result = "complete"
}
result
}
//sets complete/not complete for time restriction section in settings
def greyedOutTime(starting, ending){
def result = ""
if (starting || ending) {
result = "complete" result = "complete"
} }
result result