Say goodnight when you turn off your night stand light

(Dan) #1

When we started our Smart Home, we were looking for a reliable trigger to set the home into night mode. I came up with the idea embodied in the smart app below. It will monitor the power consumption on a power meter switch, e.g. the SmartThings Smart Outlet. When the power goes to zero in a user selected time window, it will run the user selected routine (previously known as “hello home” phrase).

We’ve been using it since last year and it works great for us. The night stand light is always the last thing to be turned off before we go to sleep. This will trigger the app to “Say Goodnight” to ST. That, in turn, will run all the automated tasks you have associated with the routine. In our case it will turn off all the lights and set the thermostat temperatures cooler.

Say Goodnight smart app

Smart lamp control.. very advanced rule
Store previous Hue color values
(Keith Croshaw) #2

How do you get it to monitor power within a time window?

(Dan) #3

I subscribe to the power event and when the event fires, I check if I’m in the time window. The event seems to fire on every power level change. After turning off the nightstand light, the “Good Night!” routine typically runs within 3 seconds.

The first version of the app actually had a complicated arrangement of schedules and runIn() calls to start monitoring the power when the time window starts and then poll frequently. At the time I did not realize that one can subscribe to power events. That version often stopped working due to the ST scheduler woes. After the re-write to use power events, the app has been rock solid and very responsive.

(jhoff80) #4

Oh wow, I like this idea a lot… not just for goodnight mode (which I will probably use as well), but for power changes (such as turning on the TV or projector) triggering other actions. The idea hadn’t even crossed my mind until seeing this.

(Keith Croshaw) #5

I tried subscribing to power for my application and that attribute took forever to update from my Aeon Smart Power Outlet. I’ve heard the ST model is instant. I no longer need this application as the situation surrounding it has changed but it bothers me that I still never found a perfect solution. My last solution was to fire the smartapp based off of any event in the house just so I could see if the timebetween was satisfied.

(Dan) #6

When you look at the device page for the Aeon outlet, does it also lag with updating the power? The ST one is quick enough that it captures the transition. E.g. turning off an incandescent light will often result in a few updates as the power drops to zero. I’ve been very happy with it.

Now if only someone can come up with a device type that allows me to turn off the indicator light :smile:.

(jhoff80) #7

Unfortunately, as neat of an idea as this is, it doesn’t appear to work for me.

With the SmartThings branded outlet I do see in the live log that the power usage drops nearly immediately… but then nothing is triggered in this SmartApp.

(Dan) #10

I fixed a small problem with the code. Please try the updated code in GitHub. I never deleted and re-installed my app, so I didn’t find this issue. Sorry about that.

(jhoff80) #11

Apologies, only now got some time to try again or else I’d have sent the log, but yeah it looks like you figured it out.

Definitely working now, thank you.

(LimboMan) #12

Has anyone figured out a way to do something like this with my wemo power monitor switch? Love the idea!

(Brandon) #13

I’ve been using this for about a week now and it has been great, thank you!

Have you considered a variation on this that would set the home into night mode when, for example, you dock your phone on the charger at night? Then similarly in the morning, once you undock the phone, the house would ‘wake up’ (triggering within a selectable time window).

(Bobby) #14

I am currently doing that with an NFC tag and SharpTools, works great…

(Dan) #15

I did something similar by using Tasker and coding an endpoint to charge my tablet when docked. It’s pretty easy with Tasker. So Tasker would have a task to invoke turning on a switch through an endpoint when the tablet gets docked. It’s powerful, but gets like a rube goldberg machine very quickly, with lots of moving parts to keep working.

(Larry) #16

Thanks I’m looking at your code… it seems to fire if light is off anytime in the time window. I want it to fire only if light was previously on and the turned off… I would also like to add a certain presence sensor that has to be home.

(Dan) #17

The code will only fire if the lamp was turned on first. If the lamp is off when the time window starts, it will not fire until the lamp is turned on and then off. If you’ve actually tried it, and that was not the behavior, please let me know.

In terms of the presence sensor, I have not coded that specifically, as I use the presence sensors to change modes from away to home. I then set this app to only run in home mode. So effectively it will only run when somebody is home. If you want finer grained control, it should be relatively simple to add the presence sensor.