Motion Lighting Dim option (instead of turning off)

This is a feature request. I love Motion Lighting App but it would be great if it had an option to dim the lights instead of turning them off. For example, you may have dark hallways where you want to maintain small amount of light at all times and increase as people walk through.

I know this can be achieved with RM but RM is much slower than ML and therefore not really suitable for hallways etc.

Thanks.

This has been requested a few times but I'm not sure staff have ever commented on whether they're interested.

I did wrote a custom app that can do this plus a few other things I was looking for: [RELEASE] Lights on Motion Plus (dim before off, remember individual bulb states, etc.). Maybe you'll find it useful for you too. (Edit: I just realized the this isn't quite what you want--it will still turn them off, though if you code you could probably modify it.)

Another thing you could consider is using Motion Lighting or even Simple Lighting to turn on your lights and use your rule to handle dimming with inactivity. You likely won't notice the extra milliseconds in that case, but you'll still get the speedier "on"/level change actions.

2 Likes

Perfect! I just tried Lights on Motion Plus this morning and it worked exactly how I wanted it. I added a Boolean switch for “turn off lights after dim” and now I can configure it to turn off completely or just dim to a specific value! This was a huge gripe for my family ever since we got Hubitat and I can now happily report to them that it’s solved. I also love the other features of your app. Very flexible.

BTW this was just 2 lines of code. Add the switch and then add an if condition.

Just an update. Saving state wasn’t really working reliably (I think it would just end up saving the dimmed state). I simplified the code and removed the saving state logic and just substituted static values for on/dim. It works very well and it’s actually much faster now (even faster than Motion Lighting). I think the speed improved even more because it doesn’t poll devices for state. I may add features I need in the future but for now it does exactly what I want. I will migrate all my motion lights to it. I’m super happy with it. You really made my day, thanks!!!

2 Likes

Glad to hear it! I originally save the states because I had multi-bulb fixtures on a single switch and only usually turned on one bulb at a time, and unlike most motion apps, I didn't want them all to turn on when motion was sensed (but did want them to all turn off). Hubitat can do some of this now (this was back on ST).

I also think the code to do that is a bit messy and I should probably move it to the parent app so it can work with the same bulbs controlled by multiple child apps, a problem I'm noticing now when I try that (unless Hubitat adds level prestaging to all bulbs and then I won't have to worry about this at all!).

In any case, happy to help!

Never heard of this one.
Where do you find that?
Thanks.

Bert posted a link up above.

1 Like

Ah. OK. Because it was crossed out I didn't bother to read it as I thought it was not valid.
My mistake, sorry.

Mind sharing your altered code? This is exactly what i need and have been doing with RM4, but am not comfortable with messing with the code myself yet.

Cool!
@CrazyIvan Could you share the code that you tweeked, pretty please?

RogerThat

Here you go. As I said, it's a very stripped down version, so don't expect any advanced features. But it's very consistent and very fast. You can turn on lights to specific level, and dim to specific level (or completely off). You also have an option to disable during certain modes (e.g. night), and you have an override switch option (I use it with a presence virtual switch). Most of the credit should go to Bert who wrote the original app. Hope it helps.

Parent App:

definition(
    name: "Simple Motion Lighting",
    namespace: "1234",
    author: "",
    singleInstance: true,
    description: "Allows motion lighting with dimming option.",
    category: "Convenience",        
    iconUrl: "",
    iconX2Url: "",
    iconX3Url: "",
)   

preferences {
  section ("") {
    paragraph title: "Simple Motion Lighting", ""
  }
  section {
    app(name: "childApps", appName: "Simple Motion Lighting (child app)", namespace: "1234", title: "Add simple motion automation", multiple: true)
  }
}

def installed() {
    initialize()
}

def updated() {
    initialize()
}

def initialize() {
    unsubscribe()
}

Child App:

definition(
        name: "Simple Motion Lighting (child app)",
        namespace: "1234",        
        parent: "1234:Simple Motion Lighting",
        author: "",
        description: "",
        iconUrl: "",
        iconX2Url: "",
        iconX3Url: ""
)

preferences {
    page(name: "pageMain", title: "Simple Motion Lighting", install: true, uninstall: true) {
        section("Select Options") {
            label title: "Assign a name", required: false
            input "motionSensors", "capability.motionSensor", title: "When motion is detected on sensor(s)", multiple: true
            input "switches", "capability.switch", title: "Turn on these lights (if none already on)", multiple: true, required: true
            input "offDelay", "number", title: "Turn off or dim after this many minutes", required: true
            input "boolDim", "bool", defaultValue: true, title: "Dim instead of turning off"
            input "turnOnToLevel", "number", defaultValue: 100, required: true, description: "0-100", title: "Turn on to this level"
            input "dimToLevel", "number", defaultValue: 10, required: true, description: "0-100", title: "Dim to this level"
            input "nightModes", "mode", title: 'Do not turn lights on during these modes."', multiple: true, required: false
            input "killSwitch", "capability.switch", title: "Do not turn lights on or off for this switch."
            input "killSwitchOn", "bool", defaultValue: true, title: "Disable for switch OFF/ON"
        }
    }
}


def installed() {
	initialize()
}

def updated() {
	unsubscribe()
	unschedule()
	initialize()
}

def initialize() {
	state.switchStates = [:]
    subscribe(motionSensors, "motion", motionHandler)
    state.isDimmed = false
}

def isNightMode() {
    def retVal = nightModes && nightModes.contains(location.mode)
    return retVal
}

def isKillSwitchActive() {
    if(!killSwitch){
        return false;
    }
    killValue = killSwitchOn ? "on" : "off";
    def retVal = false
    killSwitch.each{
        if(it.currentSwitch == killValue){
            retVal = true
        }
    }
    return retVal
}

def setDimmerLevel(sw, lvl) {
    try{
        sw.setLevel(lvl)
    }catch(Exception e){ }
    try{
        if (lvl > 0) {
            sw.on()
        } else {
            sw.off()
        }
    }catch(Exception e){ }
}

def isEverySensorInactive() {
	def allInactive = true
	motionSensors.each {
		if(it.latestValue("motion") == "active") {
			allInactive = false
		}
	}
	return allInactive
}
def motionHandler(evt) {
    if (evt.value == "active") {
        if(isNightMode() || isKillSwitchActive()){
            return
        }
        unschedule(turnOffLights)
        TurnOnLights()
        
    } else if (evt.value == "inactive") {
		if (!isEverySensorInactive()) {
			return
		}
        unschedule(TurnOffLights)
        runIn((offDelay * 60), TurnOffLights)
    }
}
def TurnOnLights() {
    switches.each 
    {
        setDimmerLevel(it, turnOnToLevel)
    }
}

def TurnOffLights() {
    switches.each 
    {
        setDimmerLevel(it, dimToLevel)
    }
}
2 Likes


Thank you so much, Its on your name now.. :slight_smile: Hehe
RogerThat

@CrazyIvan Thank You! It works great, decreased my total time from motion detect to light on by over 130ms on average, can no longer sense any delay when entering rooms!

Now all i have to do is figure out how to hack a fade setting into it for granny. (I moved her in with me when her health and mind started to slip)

On her bad days she forgets the lights are automatic and the sudden shift in brightness can startle her. :scream: Its funny but at the same time not :confused:

1 Like

Does turn off timer turns off the switch after no motion detected for that amount of time? Or is it just a hard time limit?

The timer will keep resetting every time motion is detected. So effectively the lights will not dim or turn off until after there is no motion for the amount of time you specify. I’ve had this running in every room and hallway for many months now and it’s been super consistent.

1 Like

Thanks! Yeah the app is super responsive, thank you for your work this

Is it possible to dim the lights after inactivity and then turn lights completely off after further inactivity?