1 /*************************************************************************************
7 Copyright (c) 2015, Mitch Pond
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
13 1. Redistributions of source code must retain the above copyright notice, this
14 list of conditions and the following disclaimer.
15 2. Redistributions in binary form must reproduce the above copyright notice,
16 this list of conditions and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *************************************************************************************/
33 name: "Hue Party Mode",
34 namespace: "mitchpond",
36 description: "Change the color of your lights randomly at an interval of your choosing.",
37 category: "Fun & Social",
38 iconUrl: "https://s3.amazonaws.com/smartapp-icons/FunAndSocial/App-ItsPartyTime.png",
39 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/FunAndSocial/App-ItsPartyTime@2x.png",
43 section("Choose lights..."){
44 input "lights", "capability.colorControl", title: "Pick your lights", required: false, multiple: true
46 section("Adjust color change speed and timeout"){
47 input "interval", "number", title: "Color change interval (seconds)", required: false, defaultValue: 10
48 input "timeout", "number", title: "How long to run (minutes)", required: false, defaultValue: 60
53 settings.interval = 10 //default value: 10 seconds
54 settings.timeout = 60 //default value: 60 minutes
56 log.debug("Installed with settings: ${settings}")
61 log.debug("Updated with settings: ${settings}")
63 subscribe(app, onAppTouch)
64 for (light in lights) {
65 subscribeToCommand(light, "off", onLightOff)
72 //if one of the lights in our device list is turned off, and we are running, unschedule any pending color changes
74 log.info("${app.name}: One of our lights was turned off.")
80 //if currently running, unschedule any scheduled function calls
81 //if not running, start our scheduling loop
84 log.debug("${app.name} is running.")
87 else if (!state.running) {
88 log.debug("${app.name} is not running.")
95 if (!state.running) return //just return without doing anything in case unschedule() doesn't finish before next function call
97 //calculate a random color, send the setColor command, then schedule our next execution
98 log.info("${app.name}: Running scheduled color change")
99 def nextHue = new Random().nextInt(101)
100 def nextSat = new Random().nextInt(51)+50
101 //def nextColor = Integer.toHexString(new Random().nextInt(0x1000000))
103 lights*.setColor(hue: nextHue, saturation: nextSat)
104 runIn(settings.interval, changeColor)
108 log.debug("${app.name}: Beginning execution...")
112 runIn(settings.timeout*60, stop)
116 log.debug("${app.name}: Stopping execution...")
118 state.running = false