Does this exist yet?

There’s a smartapp built into ST for “Light Turn On Open/Close” (that can be found under “lights & switches.”

(The smartapp basically turns on a light for a configured length of time when a door is opened or closed.)

I’m wondering if something similar, but with more intelligence, exists (yet.) In particular:

  • I’d like the times to be based on sunset/sunrise (not on hard-coded times.)

  • The smartapp shouldn’t “turn on” the light (and then turn it off again after the duration) if the light was already on before the door was opened. (This really annoys my wife. She has a light on already for some other purpose, but if anyone comes through the door, the light turns off after 3 minutes.)

  • The portion of the smartapp that turns the light off after a duration should be canceled if the light/switch is messed with externally. (Worst case would be to have to turn the light off and back on again to cancel the timer. Better would be that the smartapp catches “on” commands from a switch to cancel the turn-off timer.)

Writing the above should be fairly simple for me, but I really hate re-inventing the wheel. I can’t FIND anything that does these things, but if someone else knows of one, please let me know…

Thanks
Gary

1 Like

Gary, This is a recurring question, with variations on the theme. You would need a SmartApp, not one of the built-in ones to do what you want, but this would be pretty simple. One common request is for a light not to turn off after x minutes if it was already turned on (presumably by someone turning on the switch). There is an example of this on at least two other threads. These apps, as you suggest, do “catch” the on commands, or discover the state of the switch to make the decisions.

I had a house guest who wanted to disable motion turning on a hall light so as not to wake toddlers. I wrote a very small app that disabled motion turning on the light if someone had turned it off with a switch.

If you need help getting this to work, PM me. There are several folks here willing to help you get going.

already about 90% of the way done. I’m just fighting with the various “time” mechanisms and different ways of getting sunrise/sunset times.

That leads to a question, though. This is probably something that would be trivial if I was actually familiar with “groovy.”

I’m able to convert a “Date” object to a unix timestamp via:

objectName.time
(or the more proper objectName.getTime())

I’m able to get the “current” timestamp using “now()”

How can I convert a unix timestamp to a “Date” object? (in Java, I’d do something like “new Date(now())”)

Gary

I’ll reply to myself: I was surprised to find out I can actually create new objects in ST’s groovy. This works:

def justTryIt = new Date (now()) log.debug "when I tried, I got this: $justTryIt"

1 Like

Gary, You just hit on the key to success in ST. Just try it. You’ll be amazed what you can do once you get past the puzzle nature of the beast. That, and read other people’s code…

1 Like

Hi garyd9

How would you use this code in a Device Handler, so the time/date
in $justTryIt could be shown on a ValueTile/StandardTile?

From a very noobee

Thanks

Ben