Dusk-to-Dawn Light Control with Lux control and Motion Dimming - RC2

smartapp_lighting

(Aaron) #1

The ‘RC1’ thread has become pretty long and hard to follow I have since made considerable changes/enhancements to the code based on what I have learned and a lot of great feedback from the community. So, I’m starting this new thread to ‘finalize’ the app and track the submission process (part of my goal for this project is to see what the submittal process looks like).

The code seems like it is pretty solid now and working well. I have cleaned up the code and added comments for the purposes of documentation. I am not a coder by profession so I’m sure there is still some stuff that is not quite ‘best practices’ and I welcome any and all suggestions along those lines.

Also, if any one cares, I’m open to suggestions regarding wording of dialogs, default values, selection list values, etc.

I’m not going to tackle presence triggering in this version. I think it’s a great idea (and, in the RC1 thread, you will find some work @cl810 did on this already) but I’m just not up for that now and it seems like I see a lot of complaints about problems related to presence functionality which leads me to just put this on the list for later. If someone else wants to give this a go, please help yourself to my code as a starting point. I’m not claiming a copyright in any way. I did make the mistake of unknowingly using some copyrighted code in early versions without permission but I have since cleared this with the author, @pstuart, who has blessed the further downstream use of the code he started. Please just be sure to credit the original authors in the comments of your code if you start with this as a base.

I don’t know how many members are actually using this app (not many, I suspect), but, if you are, please share your experience/suggestions, positive or negative, here. Also, if you are using it, check to make sure you have the latest. There have been MANY changes.

If after a little while there is no inspiration for further changes, I will go ahead and start the submittal process and see how that goes.

Here the code… . enjoy.


Lights & Motion Sensor in Bathroom?
Sunrise events didn't fire today?
Dusk-to-Dawn Dimming Motion Light - RC1
Getting started with Core (for Dummies)
Turn on at sunrise or sunset not working
Outdoor Lights - turn on dimmed at dusk, full brightness for X minutes when motion detected
Peer Review Requested - Problems with Schedule()
Solaredge Device Type?
Smart Lights source code?
(Ray) #2

Keep up the good work. Not sure how many people using this but I sure like your app a lot. Unfortunately ST was not really up to par the last couple of weeks for schedule apps. Most of my outdoor lights are running your app. Will give that a go tonight.


(Aaron) #3

Super, @Navat604! I’m not sure which version you are running but the current code should be much more robust. I have not had a scheduled event fail since I made a fundamental change to the way I was scheduling the rise and set handlers a couple weeks ago. If you are interested, look in the code you are running and see if there is a scheduleSunEvents() method. If not, the latest version should improve reliability significantly.


#4

Not sure I want the Dim mode on from Sunset to Sunrise. It would be great to add either a “0” Dim for off… or I’d love a separate Dim Time frame, while still leaving motion on while dark?

Thanks, just installed this smartApp, looking forward to seeing it in action


(Ray) #5

I was running the latest rc1. ST was flaky after the update 3 weeks ago. I think you should implement presence in this app. I know the presence in phone is not reliable but the ST one is rock solid with me.
Pwertypo : there is an official app for lighting up the night if you don’t need the dim mode. As for the time frame. You can adjust the sunset/sunrise offset.


#6

I want it to light up at night, or by LUX, when there is movement. But otherwise be off. I haven’t seen that in ST. I also like the idea of it being on DIM, but maybe only for a few hours a night.

EDIT:
I added “0” to the list of Dim options and that seems to turn them off.

I’d love to to see the App pole the current dim level, so if I adjust the bulb brightness myself, it will except that as my new setting. Usually a 40% dim is perfect for me for motion, but sometimes I am working in the yard area, and I like to brighten the lights to 100%, motion events would fight me and keep putting them down to the level determined in the app. I could see it resuming back to the app setting after the motion timeout expires. Would this suit this app or should be setting this up another way?


(Brad B.) #8

thanks for your work on this. I’m having one issue with the RC1, but I’ll try your RC2 tonight to see how it works.

Could you build this into the RC2? I know that it isn’t really the point of your app, but in my case, I wanted to have one light stop going to a dim state but didn’t want to go through the hassle of Uninstalling your app just to try that particular light on an “Off” setting.

EDIT: I see that RC2 was released on 1/26/15, and that’s the version that I was already using. My issue may be related to my motion sensor or the GE Link bulbs, but I thought I’d ask here. Currently, my dim and bright phases get swapped. Also, sometimes, if I walk into a room just as the lights turn off (due to no motion being detected), the lights will not turn back on - even if I do jumping jacks in front of the motion sensor. The ST app shows motion, but the lights/this app do not trigger…

Any ideas? Maybe that delay setting isn’t set right? The motion sensors have a 4 minute delay before reporting no motion. I’m thinking of setting the sensor into Test mode so that they register no motion right away.


(Aaron) #9

Thanks for all the great feedback. Sorry for the slow response. . . busy weekend for me.

The point of this app is to have some light on always during dark times outside. However, as you found, adding a “0” to the list of dim options should result in the lights being turned completely off after motion stops and after the selected delay.

I think the way to deal with this is by adding an ‘on-off’ switch. This is beyond my capabilities at the moment but I think what is possible is to have a virtual switch that the app watches. When the switch is on, the app runs as expected. When the switch is off, the app would stop and unschedule all the events and unsubscribe to everything except the on-off switch. Then, once the switch is turned back on, the app would start up again as if it had just been installed. In order to keep it simple, I think I would want the app itself to instantiate the virtual switch. Again, I think this is possible but beyond my capabilities right now. If someone wanted to help me with the instantiation of the switch part, I think I can handle the logic for how to respond to the switch.

3 weeks ago was before the latest revision. It is certainly possible that the latest code would have been OK during the flaky time you mentioned. In fact, I think it was this flakiness that got me looking at the code and lead me to the improvements in the latest version.

hmmm. . . not sure about this. If you can capture the log from the app during this behavior, I could try to figurre it out. The app is going to ‘bright’ based on a motion event from the motion sensor. Then, once the motion sensor sends a motion stopped event, the app schedules the dim mode to fire after the delay period. I’m having trouble figuring out what might be causing the behavior you’re seeing. The logs should be able to shed some light on this. I’m using the SmartThings motion sensor and there is no built-in delay for the end-motion event. Maybe the events your sensor is logging is somehow confusing the app. Looking at the log for just the motion sensor might also be helpful in sorting this out. EDIT: I looked into the motion capability in the docs and there are only ‘active’ and ‘inactive’ states supported so it really shouldn’t matter how the device was managing this as long as the capability was implemented as intended with only ‘active’ and ‘inactive’ states and events declaring changes.

Also, I noticed that the dimmer I am using seems to be interpreting a setLevel(0) as a off() command. The reason why I think this is that when I look at the dimmer state after a setLevel(0) is sent, it seems to be remembering the last level and reporting this but also reporting an ‘off’ state. So, if it was at level=10 and ‘on’, after sending a setLevel(0), it is level=10 and ‘off’. I’m not sure if this has to do with anything, however.


#10

Not sure how to diagnose this, but I had a motion event turn on my lights during the day. I double checked my zip code settings, everything settings wise looks fine. Let me know if I can find any other info for you to help figure out what happened.

Thanks


(Aaron) #11

@qwertypo Show me your scheduled events status:

In the IDE, goto My Locations>SmartApps>[whatever you named the SmartApp in the Other section], then the Scheduled Events table is at the bottom of the status screen that comes up.

I know there some some sort of glitch today in the platform but I checked my house and all seems to be well

EDIT: The other thing that would be super helpful would be - that is, if you can get this to repeat - is to turn on live logging, make the app misbehave, filter the log for just that SmartApp, and send me that (either a screen shot or copy/paste of the text)


(Aaron) #12

I started to investigate this here Spawn or Instantiate a Virtual Device in SmartApp?. It seems that this is definitely do-able but it may be more that I am able/willing to take on right now. Maybe this is a V2.0 feature . . . .


(Ray) #13

So far rc2 is working really well. Even got the approval from the wife.


#14

The issue hasn’t happened again, so I will see if it becomes a repeatable issue and try to grab he live logging.


(Aaron) #15

@qwertypo, any more issues?

What about you, @DITPL? Did you uninstall and move on or are you still working with this?

The latest code has been rock-solid for me. I’m anxious to move on to the submittal process so I can see what this looks like.

There are 2 features which I would like add but defer to Version 2 (or let someone else pick it up and run with it). That is, presence functionality and a virtual on-off switch for the SmartApp.

I will wait a little while for updates from Brad and qwertypo and then proceed unless there is more work to do.


#16

I haven’t had a repeat of that last issue, no.

I did have it completely stop responding to motion, but when I looked in my events, it looked like motion events where not firing, so I repaired my Aeon multisensor and it started working again.

I did have a different issue with it, not sure what happened, but I turned the lights on myself via the smart app, and set them to 100%. I have a process running to turn them off when there is no motion for 20 minutes, and that failed, and walking in front of the motion sensor after that window did not dim them down to 40% which is what I have in your app for motion events. I turned the lights off in the smart app, and then triggered motion again and they resumed normal function. I really need to be able to switch lights on to different levels sometimes, so I might have to go back to a simple on-off method for motion events, its just unfortunate that the default app won’t look at sunrise sunset for motion events. Maybe Magic Home will be a better option for me until you add virtual on-off down the road.

I’ll leave it running for now and report back if I see any other issues, I’d say so far it seems pretty solid as an app


(Brad B.) #17

Real life got in the way this last week :stuck_out_tongue: but I’m happy to say that your app has been more reliable than SmartThing’s own “Turn Light On With Motion” app. In fact, I REALLY wish that your app offered a dimming value of 0 so that I could replace the SmartThings app entirely. That would also let me have one app control several lights rather than have two “Turn Light On With Motion” apps running.

I currently have 3 GE Link bulbs in one ceiling fixture. At night, I like for all three to trigger at 100% with motion but 2 to turn off w/o motion. The third bulb goes to 10% as a nightlight. Right now, your app controls the nightlight/10% bulb, but I have the ST app run the other two.

EDIT: I saw your edit on GitHub, I’ll test tonight and let you know!


(Aaron) #18

OK! OK! It’s done ;-). GIT is updated. Please test and let me know if it works for you. I have just the slightest concern that this will cause issues since the dimmer I have seems to interpret level=0 as off . . . which shouldn’t be any issue but I don’t know.

This is a little troublesome. Can you show me the app you are using for the 20 minute off-delay? Also, what dimmer are you using?

My app does not use on() and off() methods, only setLevel(). I don’t know why it would, but I wonder if some dimmers and/or lights are confused by getting only setLevel() calls and never on() or off(). Or, if another process is using on()/off() whilst mine is using only setLevel(), does that confuse the dimmer/bulb? @Mike_Maxwell, you seem to be an expert on dimmers. . . do you know?


(Brad B.) #19

OFF is what I’m aiming for :wink:


(Aaron) #20

Ha! yea, that sentence wasn’t well constructed :slight_smile:

Particularly in light of the issues @qwertypo is having, I’m a little worried about the dimmer or bulb getting confused. You do want the light to come back on . . . don’t you? :wink:


#21

I am using Linear dimmers with the app.

I an using the built in app to turn off the lights if they are on with no motion for 20 minutes. I’ll see if I can repeat the issue and get some event logs around it