Could use some direction on time-based dimmer

I have a dimmer in my upstairs hallway with a motion sensor which triggers the light to come on 24x7 (as it’s always dark in there.) I’d like the light to come on at 10% brightness during the hours where we’re sleeping. (So the brightness doesn’t wake us up too much while checking on the kids, etc.) This could be based on a fixed time range. During all other times I’d like it to come on at 100%.

In general I find myself wanting to set dimmer levels to different strengths based on the time of day and I don’t see a good way to do that. It looks like I could set the dimmer levels of lights I turn on using actions, but I don’t want to turn them on, just set the dimmer level for when they do turn on. If this doesn’t exist in an easily configurable form, then I think it’d make a great feature request.

I’m a developer so if this requires a smart app I can probably figure it out. That said, I could use some direction for where to start.

Thank you all for your time!

I’ve pursued exactly this course with my lighting, where the dimmer level is set according to the mode (Day, Evening, Night), and sometimes with specific time constraints on when they fire. You are correct that there is no straight forward method to just set the dimmer level without the lights coming on. What I’ve found is that by using motion to turn on lights, and by having my app handle the motion-on events, and by using device.setLevel(levelForThisMode) – so to speak – that when they do turn on they will be at the correct level. For lights that are not turned on by motion it’s trickier. What my app does is to check each light at mode change: if it’s on, great, simply adjust the level. If it’s off in a room without motion detection, I set the level and then immediately turn it back off. This results in a brief flicker of the light. But when next you turn it on, it will be at the proper level. I found this some rather tricky code that I’ve struggled with. Once in a while a light that is adjusted this way stays on when it should turn right back off. I think I found that bug yesterday, but I won’t know for sure for a bit.

The way my app works now, after about a dozen iterations of it, is that it knows about the modes (rather than asking for which modes – it’s hardwired, not good coding practice generally, but easier on me as the admin), and I enter a number at installation that specifies the three levels, eg. 903010, for 90% during Day, 30% Evening, 10% Night. It also allows the usual conditions to apply for motion activation, namely time of day, days of week, and modes.

PM me if you want further assistance…

1 Like

I use the “turn on bright” shared app to set the dim level for each mode. works great!

1 Like

@bravenel Which app are you using ? Is it in the shared apps?

No it’s one I hacked together. Inelegant work in progress. PM if you want the source.

Thanks, Bruce. I appreciate the thorough response.

I’d love to try out your source if you’re okay with sharing it. As I said I’m a developer myself so I’m sure I could work with it (regarding the hard-coded stuff.) I’m new to the community so I’m not sure how you go about sharing code on here. If you have a GitHub repo I could work with that, or you can just PM it (assuming that’s possible.) I’d definitely share any improvements I make on my end. With kids and a wife, my non-work-related programming time is extremely limited. Any head start I can get is helpful.

Thanks again, and have a great day!

Mike,

I understand your situation very well – as in, just got my 18 yr old out of the house so I have lots of time.

Here’s the source, with lots of comments. Even if the app isn’t what you need, it has examples of basic ST things that are useful in any app.

Enjoy, and any feedback is very welcome.

Bruce
https://github.com/bravenel/SmartThings/blob/master/ModeLighting

There is a bug in the app that has to do with a slave dimmer changing the dimmer level. If the master changes the dimmer level, no problem. I’ll figure out the slave situation and update.

Haha! Thanks again, Bruce. I’ll give it a go in the next day or two and let you know how it works out.

@bravenel
Bruce, I have a question for you - Am I correct in saying that I need to customize your code in my case to have the modes match my personal modes (home day, home evening, home night)? If so, can you help me a little here with an example of what I need to change? Do I just replace the texts with your modes with my modes?

I’m sorry, I’m just learning!

You are correct. There are a few places in the code where it has the modes in double quoted text, one right after the other on three successive lines. They are “Day”, “Evening” and “Night”. As long as you have three modes, all will work. Just edit those quotes to be your modes. I believe it may be case sensitive, so follow the case exactly as the modes appear in your mobile app.

There are four places in the code, in initialize(), switchOnHandler, switchOffHandler, and modeChangeHandler.

Just zap those to fit your modes, Save, Publish to Me, and you should be good to go.

BTW, It’s using the quoted text form of the modes that makes it “hard wired”. The proper way to do is to prompt at install for which modes you want to be the three modes. I could whip up a variant that does that for you. But like I said, it just makes for extra work when (a) you always use the same modes, and (b) you have to do it over and over again.

The lines of code you want look like this:

    if     (location.mode == "Day") state.lastdimLevel = state.DayLevel  
    else if(location.mode == "Evening") state.lastdimLevel = state.EveningLevel
    else if(location.mode == "Night") state.lastdimLevel = state.NightLevel

This might be best to make it more user friendly for the masses. I see what you’re saying though.

@bravenel

So did I do this right, or do I need to change text after the state.lastdimlevel? If so, do I leave the spaces or take them out?

def modeChangeHandler(evt) {
if (location.mode == “Home Day”) state.lastdimLevel = state.DayLevel
else if(location.mode == “Home Evening”) state.lastdimLevel = state.EveningLevel
else if(location.mode == “Night”) state.lastdimLevel = state.NightLevel

Thanks for your help.