imbrianj / nobody_home

If all presence are away, change mode to "Away", and set thermostats to "Away" - and turn off all thermostats and switches
10 stars 7 forks source link

Mode Changes to sunset mode anytime someone returns home during the day #1

Open walkeritgtech opened 9 years ago

walkeritgtech commented 9 years ago

Hi There,

Thanks for this SmartApp it's been very helpful. I've noticed one issue we seem to be having, v2 Hub here.

If everyone leaves either day or night, the app correctly changes mode to Away. We use two modes for when we are present. Home for daytime (triggered at Sunrise) and at sunset we switch into Evening.

If one or both presence sensors leave during the day (while mode is Home) and the sensor returns before sunset, the app switches to Evening, but it should instead be switching back to Home. This holds true even if one person remains home and the other person leaves and returns

Any thoughts on what may be causing this? I looked at the code but I'm still getting up to speed on Groovy syntax. Thanks for any suggestions you can offer.

imbrianj commented 9 years ago

Is your mode named "Evening" - or is it "Night"? SmartThings has three default modes: "Home", "Night" and "Away" - which this app had been most thoroughly tested with. The app subscribes to the actual sunrise / sunset events per the location defined by your hub during setup. I have heard of issues with subscriptions to these events - but haven't been able to reproduce them myself.

There is an older version of this app that does not require the location - but instead polls for the weather data (which includes sunset / sunrise info) every day. It's not suggested for most since it unnecessarily polls for a dynamic API instead of calculating from known times - but you're welcomed to try this to at least troubleshoot if this is the cause to your problems: https://github.com/imbrianj/nobody_home/blob/85d6c683bd4bf2abf4884cd18f289b2b424a50a8/nobody_home.groovy

Please let me know if you have any questions or additional information. I'll do my best to help.

Thanks,

Brian

imbrianj commented 9 years ago

[Leaving ticket open for feedback]

walkeritgtech commented 9 years ago

Sorry for the delay, work got in the way. I have the "Home" mode, a separate "Evening" mode I created, and a "Night" mode.

I'm not sure it's a subscription issue per se, it's just that whenever a presence sensor leaves the house and then returns, the mode goes to Evening, which is what we have set as the mode to return to at nightfall. It's almost as if it ignores the whole "At least one person home and sunrise" setting on the app.

I can try the old version, give me a day or two to see what type of results I see. Thanks!

imbrianj commented 9 years ago

The code has remained unchanged for...quite a while. I've gotten a few reports lately of it acting up, so it's possible something had been changed on the platform - or if there's intermittent issues with the platform - that could be causing issue. I've gone through the code and nothing is jumping out at me.

I appreciate the feedback!

walkeritgtech commented 9 years ago

That's always a possibility, maybe the underpinnings have been moved around. I have the older version in place, I will let you know what I see over the next few days. I have to at least wait until morning to truly test it. Have a nice weekend and thanks again!

walkeritgtech commented 9 years ago

Thanks for the patience, I did some testing with the older version over the holiday weekend. It worked perfectly. During the day when someone would arrive the mode would switch to Home. After sunset if someone would arrive home the mode would switch to Evening. With the older version I could not reproduce the problem I was having. Hopefully this adds a little more data for troubleshooting, let me know if I can provide any details about my setup or config.

imbrianj commented 9 years ago

The newer version is "cleaner" - and suggested by SmartThings to subscribe to the newer sunrise/sunset events. I know they have intermittent issues firing the events - and it sounds like maybe you're stuck with continued issues. It's probably easiest to just keep using the older version for right now. @ai7 has been making a fork of this that may also be worth looking at: https://github.com/ai7/nobody_home

ai7 commented 9 years ago

You can try my forked version listed above. After you install, it'll immediately set the system mode depending on presence sensors. It'll also remember current sun state when you reconfigure the app, so you can configure it while away and it'll behave correctly when you return. The notification message also contains location name, triggering device, and optional delay information to help you figure out what's going. For example:

Home changed to 'Away' mode because XXX left [5 minutes ago] Home2 changed to 'Night' mode because it is sunset

It is not published yet, so you'll have to copy/paste the code and install it as your own app.

I plan to add an arrival-delay setting, as sometimes when I drive past my home area the mode switches to home then away. So being able to set an arrival delay (in addition to the departure delay) will reduce some of these switches.

walkeritgtech commented 9 years ago

Thanks, I'll try the new version and see what happens. The older code has been working great, just FYI.

walkeritgtech commented 8 years ago

Hi there,

So after a few days of testing with the latest code it looks like I'm having the issue again. This time though instead of always going into Evening when someone arrives home it's now going into the Daytime "Home" mode. I had live logging up, here are the entries I see for the App. Let me know if you need more detail and I would be glad to run through scenarios.

Sunset here was around 4:30PM today.

6:34:33 PM: debug sendPushMessage set to true 6:34:33 PM: debug arrivalThreshold set to 60 second(s) 6:34:33 PM: debug awayThreshold set to 600 second(s) 6:34:33 PM: debug Subscribing to events ... 6:34:33 PM: debug updated() @Home: [people:[Rick's iPhone], newAwayMode:Away, newSunriseMode:Home, newSunsetMode:Evening, awayThreshold:10, arrivalThreshold:1, sendPushMessage:true] 6:33:52 PM: info Home changed mode from 'Away' to 'Home' because Rick's iPhone arrived 60s ago 6:33:52 PM: debug Sending push notification 6:33:52 PM: debug arrive timer elapsed: someone is home 6:32:52 PM: info Scheduling Home mode in 60s 6:32:52 PM: info Rick's iPhone arrived at Home

imbrianj commented 8 years ago

Has this error been repeatable and consistent? I'm still suspicious of the ST platform in failing to correctly fire sun phase events.

walkeritgtech commented 8 years ago

I uninstalled my instance and then reinstalled, prior to this I was just overwriting and republishing the code, and it wasn't firing away events for a few days. I was going to let it run for a few days to see how if that the uninstall/reinstall made a difference. We have a few holiday events coming up this weekend so I can give it a good workout and let you know if that works.

EDIT: I am seeing a lot of hub disconnecting events for some reason this evening, so it's probably best to give it a few days so we get some stability.

walkeritgtech commented 8 years ago

So after letting this run for a while I'm still seeing the same behavior from the newer code with a slight difference. The original problem was when someone would return the mode would be set to the sunset mode, even before sunset. Now it's reversed, when someone returns the mode is set to the Sunrise mode, even after sunset. I'm not having any problems with any other sunrise/sunset event not working correctly. It happens every single time without fail. I'm going to revert to the older code you mentioned previously, that seemed to work well.

imbrianj commented 8 years ago

The only major distinction between the old code and new was how the sunrise/sunset was derived (polled from weather data vs calculated). I'm still leaning toward this being an issue with the platform itself. I won't have time right away - but it'd be interesting to whip up an app that will send you a notification when it hits sunrise/sunset events calculated from both methods (so 4 notification per day) to better understand the disparity.

walkeritgtech commented 8 years ago

Be glad to run the code and provide data when you have the chance, I'm happy to help.

ai7 commented 8 years ago

The app currently have a limitation in that right after you install the app, it does not yet know what the sun state is (whether it's daytime or night time). So it assumes daytime. At the next sunrise/sunset event, the app would've gained the correct/actual sun state knowledge, and everything would be correct afterwards.

What this means is that before the app gains the actual sunrise/sunset knowledge, it may trigger the wrong mode because it assumes its daytime.

If you install the app during the day (which I assumes have more chance of happening than night, hence the default), everything would be ok. However, if you install the app at night (after sunset), the app will think it's daytime when in fact its night time. Incorrect mode will be triggered if you leave/arrive until the next sunrise event.

Note that this only happens when you 'install' the app. When you reconfigure the app, the existing sun state, if any, is remembered. This was one of the improvements made.

walkeritgtech commented 8 years ago

This hasn't been my experience. After several days of testing it always wanted to go into the Sunrise mode, it appeared to ignore the actual sun state. This was constant, every time an arrival event triggered a mode change.

ai7 commented 8 years ago

Do you see the normal sunrise/sunset mode change notification on your phone when you are home? ie:

Home changed mode from 'Night' to 'Home' because it is sunrise. Home changed mode from 'Home' to 'Night' because it's sunset.

This won't happen if everyone's away, the mode will stay at Away mode, but you should be able to see some events in the log when the sunrise/sunset event hits.

This will give you some idea of what the app think is the current sun mode.

walkeritgtech commented 8 years ago

As explained above, all other sunrise/sunset events have been firing normally. The July code Brian posted also works flawlessly. All newer code exhibits the same problem. Our setup isn't terribly complicated: At sunrise go into Home mode. At sunset go into Evening mode. Pretty straightforward.

ai7 commented 8 years ago

Hmm, what mode are you using when everyone's away?

walkeritgtech commented 8 years ago

Away.

ai7 commented 8 years ago

More logs would be helpful to see what's going on. Can you provide the log of when the app sets the incorrect mode when you arrive? ie

In particular I am looking for this msg: log.info("Scheduling ${state.modeIfHome} mode in " + state.arrivalDelay + "s")

state.modeIfHome gets updated when sunrise/sunset is triggered. so I want to see if this contains the correct value or not.

Also, does setting the delay timer to 0 makes any difference? It shouldn't, even if you arrive 2 min before sunset with a delay of 10 minutes, it should set night mode when timer is up, but let's just remove the timer while we are narrowing down the problem.

walkeritgtech commented 8 years ago

Delay doesn't matter, same outcome with or without. I'm not sure how many more logs I can provide that are going to show anything different than what I've already sent, and there's the not so little matter of irritating the rest of the household with continuous testing, considering we just did several weeks of it.

That being said, if you'd like to provide some code similar to what Brian mentioned above for testing purposes, or modify the existing code to provide more detailed debug information so we don't have to wait days to recreate all scenarios (I'm self-employed and often work from my home office, so it can sometimes be several days before all presence sensors are absent simultaneously), I'm more than happy to try it out when I get a free moment.

ai7 commented 8 years ago

I looked at the code again yesterday and didn't spot anything obvious. I am not experiencing any problems with the code and it's been running fine for weeks with everything firing correctly.

If you ever get around to try it again, make sure

1) publish the code. 2) uninstall the app from the hub 3) restart the hub (just in case, so we start off a clean state) 4) start the log window so we can capture install logs 5) install the app on using the phone (when it is daytime not after sunset) 6) configure, using no delay timer (so the test cases are simpler) 7) let it run until

at this point, we should be able to see whether it is working correctly or not. If you install the app say 15 minutes before sunset (and perhaps simply configure one presence sensor in configuration), you should be able to trigger leave/return events without affecting others in the house and the entire end-to-end test should take no more than an hour or so (install before sunset, then wait until sunset, then leave/arrive and observe what mode is triggered).