Turn lights on based on any custom luminance intensity

(Arik) #1

Would like to see an app that will turn on lights based on any custom luminance intensity depending on the mode and/or day of the week and/or and time of the day .

(Barry) #2

This might do the trick. It’s also available in the Shared SmartApps section of the IDE.

 *  Smart Pet Light
 *  Copyright 2014 Barry A. Burke
 *  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.
    name: "Smart Pet Lights",
    namespace: "Convenience",
    author: "Barry A. Burke",
    description: "Turn on a light if it gets dark outside and everyone is Away except the pets. Turn it off if it gets light again while everyone is still away. Cats can see in the dark, so they don't really need this. But the wife insists :o)",
    category: "My Apps",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/light_motion-outlet-luminance.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/light_motion-outlet-luminance@2x.png"

preferences {
    section("When it gets dark") {
        input "luxSensor", "capability.illuminanceMeasurement", title: "At which Lux sensor?", multi: false, required: true
        input "luxLevel", "number", title: "Darkness Lux level?", default: "400"
    section("And mode is \"Away\" except these pets are home") {
        input "daCatz", "capability.presenceSensor", title: "Pet presence sensor?", multi: true, required: true
    section("OR, pets are home and this door is closed") {
        input "catDoor", "capability.contactSensor", title: "Door to pet room?", multi: false, required: true
    section("Turn on") {
        input "lights", "capability.switch", title: "Which switches?", multi: true, required: true

def installed() {
    log.debug "Installed with settings: ${settings}"


def updated() {
    log.debug "Updated with settings: ${settings}"

//    unschedule()

def initialize() {
    log.debug "Initializing - subscribing to $luxSensor"
    subscribe(luxSensor, "illuminance", illuminanceHandler, [filterEvents: false])

def illuminanceHandler(evt) {
    log.debug "$evt.name: $evt.value, pets: $daCatz.presence, lastStatus: $state.lastStatus, mode: $location.mode, door: $catDoor.contact"
    if (daCatz.presence == "present") {             // Only when the cats are at home
                                                    // And everyone else is away, OR they're Home and the door is closed
        if ((location.mode=="Away") || ((location.mode=="Home") && (catDoor.contact == "closed"))) {
            def lastStatus = state.lastStatus
            if (lastStatus != "off" && evt.integerValue > luxLevel) {
                state.lastStatus = "off"
            else if (lastStatus != "on" && evt.integerValue <= luxLevel){
                state.lastStatus = "on"

(Arik) #3

Thank you. I’m afraid I am a newbie here.Could you give me please a kick-start and explain how I can use it? Am I allowed to copy your script?How do I then add it to my Android dashboard?Via My Smartapps?Thank you!.

(Barry) #4

Use the IDE, Luke. Use the IDE.

(You’ll need to sign up as a SmartThings Developer, then you’ll be able to create your own apps such as the one above).

(Arik) #5

Ok. Did it. This works perfectly. Exactly the app I was looking for! Thanks mate!

(Jason Apple) #6

Is there a way to use this to tell a motion sensor to then control the lights. like is there is zero light outside then the motion sensor can turn the lights on and if there is light then it will not.

(Barry) #7

Use the Smart Nightlight SmartApp in the “Kids” section of the “More (Actions)” Add menu on your mobile app - does exactly what you want…it uses Sunrise/Sunset to figure when it is dark.

FYI - if you use this app (or any other that asks for a Zip Code to use in determining your location), you can also specify your City/State name instead of the Zip code. This feature uses Weather Underground, so if you’d like to link to a specific Personal Weather Station (I have my own), simply enter “pws:” instead of the Zip code (e.g., mine is “pws:KMATYNGS02”).