Light on when motion AND luminance at lux value?


(Tuffcalc) #1

Hey everyone - trying to find an app for the following scenario.

If there is motion AND luminance is at a certain level (say lux around 100) then turn on lights.

Pretty much the same as the stock lights on motion app, but with the addition of a luminance test. Can’t seem to find anything out there. Has anyone made something similar?

My kitchen receives lots of light during the day, but around noon when the sun ends up at the other side of the house it is quite dark. The regular sunset / sunrise timer doesn’t really work well because of the orientation of my home.

Hopefully someone has the same problem.

Thanks


(Dan) #2

I’ve been looking for the exact same thing. Hopefully someone will chime in. Seems strange for ST to support a device capability (ie. Light Level) but not have an option to use it in native lighting applications.


(Dave N) #3

You want Smart Nightlight. I use it in 2 custom iterations; one with a high LUX value and one with a low LUX value. I have less light downstairs than I do upstairs so I use 2 different settings. I tried the sunrise/sunset values with offset but they never worked properly after 24 hours. The LUX settings work perfectly. I have an Aeon Multi pointed toward the back yard (for the LUX reading) so I get a good reading of how bright it is outside.


(Tuffcalc) #4

@daven - I saw Smart NightLight, but in the description it says it will also shut off the lights when it becomes bright. My concern is that once the lights fire, the luminance sensor will see it is now bright in the room and shut the lights off.

I’m looking at the code and I don’t see where it would do that (but I am not a coder - so I can’t really tell). Is that how it works in your experience?


(Mike Maxwell) #5

I wrote a auto dimmer smart app, You use your normal smart apps to turn your lights on and off, this app modifies the dimmer level(s) up or down when it sees a dimmer turn on.
It has three selectable LUX levels, and 4 selectable dimmer levels. Each dimmer also has an override should you not want to use the default values for a specific dimmer.

Updated this link to the latest version


(Bruce) #6

@Mike_Maxwell, Very cool! I have to try this…


(Alyson Boote) #7

I have the same question as the original poster, but I don’t see an answer posted here. I’m using Hub2.0, and the built in “Smart Lights” app isn’t exactly what I’m looking for. I’d like the lights to automatically turn on with motion AND a certain lux level. I don’t want them to automatically turn off either. Any ideas out there? Thanks!


(Tuffcalc) #8

Continuing the discussion from Light on when motion AND luminance at lux value?:

I made an app for just this application…

/**
 *  Turn light on with motion for x minutes if it is dark based on light sensor
 *
 *   Written by Tuffcalc
 *
 *  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: "Dimmer (Motion, Contact & Lux)",
    namespace: "tuffcalc",
    author: "tuffcalc",
    description: "Turn on lights temporarily when there is motion but only if it is dark according to light sensor, turn light off if above lux setpoint.",
    category: "My Apps",
    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")
    //todo:  replace icon with something appropriate.  


preferences {
	section("Select Motion Sensor(s) you want to Use") {
        input "motions", "capability.motionSensor", title: "Motion Detector", required: true, multiple: true
	}
    section("Select Contact Sensor(s) you want to use") {
        input "contacts", "capability.contactSensor", title: "Contact Sensor", required: false, multiple: true
        }
    section("Select Dimmers you want to Use") {
        input "switches", "capability.switchLevel", title: "Dimmer Switches", required: true, multiple: true
	}
    section ("Set Brightness for motion-triggered light and on time after motion stops") {

        input "BrightLevelStr", "number", title: "Motion-Sensed Level %", required: true, 
        	defaultValue: "100"

        input "DelayMinStr", "number", title: "Bright Delay After Motion Stops, minutes", required: true, 
        	defaultValue: "5"
        	}
    section ("Ignore motion if lux is above this value") {
    	input "LightMeter", "capability.illuminanceMeasurement", title: "Light Meters", required: true, multiple: false
		input "LuxSetPointStr", "number", title: "Lux level", required: true, 
        	defaultValue: "200"
           	}

// start light meter on code
	section ("Turn lights off on lux event if lux is above this value (optional)") {
    	input "LuxSetPoint1Str", "number", title: "Lux level", required: false, 
        	defaultValue: ""
           	}         
// end light meter on code
}
def installed() {
	log.debug "Installed with settings: ${settings}"

	initialize()
}

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

	unsubscribe()
	initialize()
}

def initialize() {
	log.debug "initialize()"

    state.BrightLevel = BrightLevelStr as Integer
   	if (state.BrightLevel == 100) {
    	state.BrightLevel = 99
    }
    
    state.DelayMin = DelayMinStr
    state.LuxSetPoint = LuxSetPointStr
	state.LuxSetPoint1 = LuxSetPoint1Str
    
    state.LuxOverSetpoint=false

    subscribe(motions, "motion.active", handleMotionEvent)
    subscribe(motions, "motion.inactive", handleEndMotionEvent)
    subscribe(contacts, "contact.open", contactopen)
    subscribe(contacts, "contact.closed", contactclosed)
    subscribe(location, "mode", modeChangeHandler)
    subscribe(LightMeter, "illuminance", LuxChange)

}

///// end of subscriptions


def LuxChange(evt) {
log.debug "LuxChange(evt)"

def currentLux1=LightMeter.currentIlluminance

log.debug "Current Lux is ($currentLux1)"

        if(state.LuxSetPoint1 == null) {
        	log.debug "Luxmeter not used, do nothing." 
        }
        
         else {
        	if(state.LuxOverSetpoint == true) {
            log.debug "Lights already turned off due to Lux over setpoint, do nothing."
            }
                         
        else {
        	log.debug "Current Lux: ($currentLux1) Lux_Over_Setpoint: ($state.LuxSetPoint1)"
            if(currentLux1 > state.LuxSetPoint1) {
        	log.debug "It is too bright in the room, turning lights off."
            
            turnLightsOffLux()
        	
        }
        
         else {
        	log.debug "Current Lux ($currentLux1) below required Lux_Over_Setpoint ($state.LuxSetPoint1), doing nothing."

        }}}



// end lightmeter subscription
}

def contactopen(evt) {
log.debug "Contact Open"
handleMotionEvent()
}

def contactclosed(evt) {
log.debug "Contact Closed"
handleEndMotionEvent()
}

def handleMotionEvent(evt) {
	log.debug "Motion detected."

    unschedule(turnLightsOff)
    log.debug "Stopping OFF timer."
    
    if (state.lightIsOn) {
        log.debug "The light is already on, do nothing."
        }
        
    else {
    	def currentLux=LightMeter.currentIlluminance
        log.debug "Current Lux: ($currentLux), Setpoint: ($state.LuxSetPoint)"
        if(currentLux < state.LuxSetPoint) {
        	log.debug "Current lux ($currentLux) below Setpoint ($state.LuxSetPoint), turing lights on."
            switches?.setLevel(state.BrightLevel)
        	state.lightIsOn=true
            state.LuxOverSetpoint=false
        	
        }
        else {
        	log.debug "Current lux ($currentLux) above Setpoint ($state.LuxSetPoint), so doing nothing."
        }
	}
}

def handleEndMotionEvent(evt) {
	log.debug "Motion stopped."
	
    unschedule(turnLightsOff)
    
    if (state.lightIsOn) {
    	runIn((state.DelayMin*60), turnLightsOff)
        log.debug "Starting OFF timer."
        }

}

def turnLightsOff() {   

	log.debug "turnLightsOff()" 

    switches?.setLevel(0)
    state.lightIsOn=false
}

def turnLightsOffLux() {   

	log.debug "turnLightsOffLux()" 

    switches?.setLevel(0)
    state.lightIsOn=false
    state.LuxOverSetpoint=true

}


def modeChangeHandler(evt) {
	log.debug "Mode Changed... (state.lightIsOn=false, state.LuxOverSetpoint=false, runIn((state.DelayMin*60), turnLightsOff)"

    	state.lightIsOn=false
        state.LuxOverSetpoint=false
        runIn((state.DelayMin*60), turnLightsOff)


}

(Alyson Boote) #9

Thanks. Still not quite what I’m looking for. I don’t want the light to turn off at all; I want it to stay on indefinitely. (Hate to be picky…beggars can’t be choosers and all. But not sure what else to do here aside from learning to code. smile)


#10

Use “Bright When Dark and/or Bright After Sunset” app. I think this will do exactly what you’re looking for. If you want your lights to stay on indefinitely then set the “turn off” option to 0 minutes and I’m pretty sure that will keep it on until something else triggers your lights to turn off or you manually turn it off.


(Joe) #11

I believe this will turn them off immediately after motion stops.


#12

Nope, not according to my test, with this app it stays on indefinitely.


(Joe) #13

Interesting. When I used it on my V1 hub it turned it off immediately. I’m using the wizard now.


#14

What other Things out there that works with ST (aside from the Aeon Multi) that reports lux value?


(Mike Maxwell) #15

Fibaro multi, hands down the best LUX sensor, also huge selection of configuration options.
The aeon taps out at about 1K lux, making it suitable for indoor measurements only, Fibaro max is about 32K lux


(Chuckles) #16

The Ubi reports lux.


(Ray) #17

The weather tile also reports local lux.


#18

Thanks, I’m interested in using it for indoors. The winter months make the interior of the living room very gloomy but in the summer it’s baking!


(Mike Maxwell) #19

For those interested in lux management of dimmer lighting levels, give this a shot.


(Lloyd Williams) #20

Just wanted to say thanks for this, it’s exactly what I was after.

Sorry for the bump :slight_smile: