Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:06
Show Gist options
  • Save bflorian/5feb80fa68a9aabc5a5c to your computer and use it in GitHub Desktop.
Save bflorian/5feb80fa68a9aabc5a5c to your computer and use it in GitHub Desktop.
Mode Levels SmartApp
* Mode Levels
* Copyright 2014 Bob Florian
* 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:
* 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.
name: "Mode Levels",
namespace: "bflorian",
author: "Bob Florian",
description: "Set your lights to a different level for each mode.",
category: "Convenience",
iconUrl: "",
iconX2Url: "")
preferences {
page name: "mainPage", title: "Set dimmer levels for each mode", install: true, uninstall: true
def installed() {
log.debug "Installed with settings: ${settings}"
def updated() {
log.debug "Updated with settings: ${settings}"
def initialize() {
subscribe location, modeChange
def mainPage() {
dynamicPage(name: "mainPage") {
section {
input "dimmers", "capability.switchLevel", title: "Select dimmers", multiple: true
section("Specify dimmer level for each mode") {
location.modes.each {mode ->
input "level_${}", "number", title:, required: false
def modeChange(evt) {
log.trace "modeChange($evt.value)"
def level = settings["level_"+ evt.value]
log.trace "level: $level"
if (level) {
state.onOffStates = dimmers.collectEntries{[, it.currentValue("switch")]}
log.trace state.onOffStates
log.trace "scheduling 'restoreStates' to run in 10 sec"
//runIn(10, restoreStates, [overwrite: false])
def restoreStates(delay=0) {
def map = state.onOffStates
dimmers.each {d ->
def value = map[]
if (value == "off") { delay)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment