[RELEASE] Lights on Motion Plus (dim before off, remember individual bulb states, etc.)

I have a question / feature request (actually two). I love the app so far. But I'm missing two things to be perfect (for me, that is :slight_smile:) :

  1. Don't turn off lights that were already on before motion was detected.
  2. Instead of a switch for "on" a dimmer level for "on".

Would that be possible? And can I help writing it (learning Groovy while doing it)?

I'm going to be honest: I have no interest in developing feature #1 since it does not represent how I use any of my lights. But if I get enough free time, I might look into it sometime. Feature #2 sound like what it already does: I know it presents a list of "switches" (or more specifically, things that implement the "Switch" capability), but that's because it needs the device to support on/off at a minimum. It should also show dimmers (specifically, "Switch Level" devices) because I'm fairly positive all dimmers/bulbs that implement this also implement Switch. If you have the "Remember states..." option enabled (as it is by default), then this app will turn those dimmers back on to their previous state when motion is detected again. If you want to always go on to a certain level regardless of what you had before, this app can't do this, and I can't think of a time when I'd want to, either (except in specific modes, which is why the "night mode" feature was added), so it's also unlikely. :slight_smile: (The main reason I wrote this app was because stock apps like another platform's Smart Lighting app would blindly turn on all selected lights even if one was already on and that's all you wanted; I added the "dim before off" warning to emulate what the Hue network eventually became capable of doing because it sounded neat. Part of both of these features is remembering the "real" previous state of the lights, since a simple "on" will just put them on back to the bulb's "dimmed" level.)

The code is open-source and you are certainly welcome to take a crack at either of these. The first would probably be pretty simple (store a list of bulbs that were already on when motion was detected, then check that same list before turning off--if the option to do so, which I'd definitely not enable by default, were enabled). I'm honestly not exactly sure what you want with the second, but it sounds either possible already or something unlikely to fit in with the original goals of the app (if you want the bulbs to come on to a certain level, set them that way--it will remember :slight_smile: ).

I think I will have to learn Groovy then. To explain my 2 desires a little more:

  1. I have a scene running with a couple of lights in it. One of those lights I want to up the brightness when I move inside that area, when I move away I want it to go back to the dim level it was.
  2. I want to control the dim level when triggered because of what I explained above, bit also because my Philips hue lights are in different scenes and it is not desired to have them go on on the level they last had.

New to HE and loving it, playing around with using motion detection to turn lights on in night mode, instead of turning the light off completely after the off timer, is there a way to just dim it instead of turning completely off?

You could modify my code to do that, but my goal is to turn my lights off (dimming is the part in this app that's optional), so I'm unlikely to do that myself. You could certainly accomplish what you want using Rule Machine, if you're comfortable using that.

I have made a small update to the child app (version 4.2), which adds a second option for "night mode." Instead of setting lights to specific settings, you can now choose a Hue Bridge scene instead if you're using CoCoHue and have a device created for that scene. (Since a Hue scene cannot be "turned off," you will need to have the same lights/groups selected elsewhere in the app for "normal" on/off actions. I'm not sure why you wouldn't anyway, but I guess I should mention it. This group also needs to be considered "on" if any member lights are on, which CoCoHue groups do. Mileage may vary with others.)

Note for upgrading: if you're using night-mode settings, go into the app and in the "Night Mode" section, choose the "Turn lights on to specific settings" for the new "In night mode..." option. This will make it work as it did before. (If you didn't use night-mode settings, you do not need to change anything.) Or you could be like me and use this as an opportunity to activate a Hue Bridge scene instead. :slight_smile:

3 Likes

Hi.

A great app! Thank you soo much!

In the standard app that is included, one can choose color temperature and level when motion is detected, if you select by mode. Is there a way to select what level is to be used, when motion is detected in the different modes? I have the bedroom using Motion Lighning app and have different levels for different modes. Is that a huge task to implement? You are on the way there by the night mode selection, so it would be great to be able to do this for more than one mode. Just a wet dream, since I do not code myselves. Maybe the ambassadors can provide you with the source code for the included included standard app that comes with the HE? Then it should be easy peasy, I guess... hihi
Here is an excample of the bedroom floor lamp i use in the included app:

RogerThat
Oslo, Norway

Unfortunately, no. Right now, "night mode" (which can really be any mode or modes you choose) is the only "special" mode. The idea behind my app was for the app to remember what light settings you used the last time the app was run (in a mode where it would turn on the lights, except any "night modes") and then restore them to that state. Even with night mode, it doesn't remember your settings there--it just always turns them on to what you specify. The rest of the time, if it turns the lights on at all, it goes to what you had them turned on to last. I'm not sure how different modes would fit in here (would it remember your settings per mode? what if mode changes while the lights are on? should it not remember the "new" settings if they're from the "old" mode? or should it change them with mode if they're on? what if you manually changed them at some point? this gets complicated fast).

I may consider adding an option to specify one or two more "special" modes, with the idea being that it might be used for some sort of "early morning" or "late evening"-type mode. You also might be able to combine my app with a rule: if X light turns on in Y mode and this is the first time it turned on in that mode today, set it to Z color temperature. My app should be able to handle the rest if you take care of changing the color temperature based on time/mode/whatever some other way when the lights turn on the first time under those conditions (and you can take care of the remaining logic, too--e.g., what if the lights are already on then?). No guarantees, but I'll consider the idea. :slight_smile:

Thanks for the feedback!

They have provided a few example drivers (and possibly an app?) for the community, but the majority of the source is closed. This is definitely a dream. :slight_smile:

1 Like

I wish I had searched for this app before spending hours setting up a rule that would do the same thing!!! I am quite glad I found it though! It works great and is so easy to setup! Great work!

Feature Request: Would it be possible to set an option that, like "Hubitat Simple Lighting" would only turn the lamp off? Alternatively, some lamps could be selected that would only turn off?

I really love how it dims before turning off, and have a lot of my lamps setup in the "Hubitat Simple Lighting" to only turn off. I think if this app could do this, I would migrate most of them to it.

Really great app! Thanks!

It might work that way if you just select no modes, but that might make it work in all modes. I honestly don't remember how I wrote that section of the code because I never intended it to be used in that way. I do know it would work if you chose a mode you don't really use, which is what I'm doing in one "off only" room of mine with "Away" mode, which I don't use but still kept (for inside lights, I guess this would be pretty harmless for most people even if you did use it).

I certainly understand this need and have plans to re-do big parts of the app and will definitely include something like this in a much cleaner fashion if I do. The other alternative would be to use the "don't turn on lights if this switch is on" option and just create an always-on virtual switch you can use for this or other instances where you only want the automatic off. Again, something I understand now but didn't need in the apartment I originally wrote this app for. :slight_smile:

I tried that. It works in all modes. :slight_smile:

I like your future plans! Here's hoping you get to it one day. For now, I just made a copy of your code in a new app & child and commented out the parts that turn the lights on. It seems to work, but it would be nice to have it all in one! :blush:

The "don't turn on" switch coupled with the "always turn lights off" option should still work. :slight_smile:

So essentially, There are two options for this.

The first is to setup a switch that will tell it not to turn on lights when the switch is on.
The second is to not select a sensor in: "When motion is detected on sensor(s)", but only select one from "Select additional motion sensors to keep lights on (but not turn them on)".

Tried out the second one and it works! Thanks!

Ooo, good find--never thought of that second idea! (Honesty would have thought I'd make that first sensor required rather than optional...definitely been a while since I looked at the code that does the core functionality of this app!)

I'm glad you didn't! Saves me from having to create a virtual switch... :wink:

I am finding that the app shows me debug information even though I have debug turned off... Is there something else I need to do to not see those in my logs?

app:9322020-04-03 22:31:17.322 debugMotion detected; cancelling dim/off timers and deciding what to do
app:9322020-04-03 22:22:50.448 debugMotion detected; cancelling dim/off timers and deciding what to do

No, some logging remains even with "debug" logging turned off; when turned on, it just shows you greater detail (useful if you are actually debugging why something isn't working how it's expected). I'm working on some changes that will make this more consistent--this was one of the first things I did on Hubitat and I wasn't as familiar with the conventions (which really still aren't as established for apps as they are for drivers) then, nor did people care as much then when "Past Logs" wasn't a thing.

In the meantime, if you do want them all gone, you can comment out any lines with log.debug (or log.anything, I guess).

Sounds good. Thanks @bertabcd1234!

BTW, great app, even more considering it was one of your firs ones on Hubitat!

Is it possible to set the brightness level, color temp, or color per mode triggered by motion with this?

Not exactly. In general, it remembers the last level and color/color temperature (from before the app last dimmed the bulbs and turned them off), then restores those the next time motion becomes active. There is a special exception: the app allows you to specify one or more modes to consider an in-app "night mode," where you can specify specifc settings (a specific level/color/CT or a CoCoHue scene--I use this setting only in the bathroom and hallway and it goes to a saturated red at a very low level, enough to see at night without appearing jarring to the eyes). Nothing gets "remembered" from night mode: the app will use your night mode settings any time motion goes active when your "night mode" criteria are met, otherwise it will recall the "regular mode" settings.

I'm not sure how it would handle multiple modes. Because it dims, it has to remember the last level (this is all "faked"/remembered at the app level--I wish devices supported dimming and remembering their "old" levels when they get turned back on again), and because of the "night mode" setting, I made it remember the color/color temperature too (since night settings may disturb those). I could add one or two more "special" modes like night but that allow even more different settings if that would be helpful, but then it seems a lot like you just want Hubitat's own Mode Lighting/Motion Lighting, except they can't dim before off. I'm open to ideas on how to handle this (remember settings per mode? forget about remembering anything and just use your settings all the time when motion becomes active? preferences for behavior if the lights are already on?) and can't guarantee anything but would consider it for a future version.

2 Likes