Turn light on after trigger for 5min then turn off only specific times of day

I have an aeon labs door/window sensor on my garage door that i wish to use to trigger turning a light on only during a specific time frame and only for 5 minutes and then turning it off. I found this code to use for specifying a specific time frame but, not sure if it will work for me and i do not know how to add the on for 5minutes and turn off? Is there an easier better way to do this? I have had my system up and running for a long time now but i have never needed to do something this complicated. Thanks in advance for any suggestions.

local t = os.date(‘*t’)
local current_second = t.hour * 3600 + t.min * 60 + t.sec – number of seconds since midnight
local min_time_in_seconds = 19 * 3600 + 0 * 60 – 16:00
local max_time_in_seconds = 22 * 3600 + 30 * 60 – 21:15

if (current_second > min_time_in_seconds) and (current_second < max_time_in_seconds) then
– do something
else
return false
end

I do it by:

A scene that arms your sensor during that time period
A scene that disarms your sensor during the other time periods
A scene that triggers by movement a light switch, but only if armed and turns off after 5 minutes, (click on immediate, then manage delays in U15).

You can also incorporate the countdown timer to keep the light on if movement is triggered again, in which case you have another scene just for ‘lights off’ when the timer reaches zero, and no delay of 5 mins, then off in the ‘on’ scene.

[quote=“conchordian, post:2, topic:172579”]I do it by:

A scene that arms your sensor during that time period
A scene that disarms your sensor during the other time periods
A scene that triggers by movement a light switch, but only if armed and turns off after 5 minutes, (click on immediate, then manage delays in U15).

You can also incorporate the countdown timer to keep the light on if movement is triggered again, in which case you have another scene just for ‘lights off’ when the timer reaches zero, and no delay of 5 mins, then off in the ‘on’ scene.[/quote]

Thanks, I guess I should of said that the sensor is always armed. It emails when the door goes up and turns a light on in the entry way which i manually turn off.

Then do it this way.

Then do it this way.[/quote]

Thank you, I will give it a try and let you know how it works…

I think you could also do it with the countdown plugin:

A scene that unmutes countdown during that time period
A scene that mutes countdown during the other time periods
A scene that triggers by movement a light switch, but only if unmuted
A scene to restart countdown if movement is triggered again (optional)
A scene for ‘lights off’ when the timer reaches zero

I’ve been doing some scheduling scenes and it’s exactly how futzle said.

Then do it this way.[/quote]

Not to ask a stupid question but, when you say to “add an action to the schedule to turn off the evening virtual switch” are you saying to go into that event and change the light itself to off? or am i missing something? thanks,

Right idea, wrong device. Change the Virtual Switch to off, the one that you created in an earlier step.

Right idea, wrong device. Change the Virtual Switch to off, the one that you created in an earlier step.[/quote]

I guess the part i am unclear on is where i am telling the virtual switch to turn on or off a device. When I setup the first virtual switch where am i telling it what light to control and whether to be in the on or off state? Also, where how do i set this up so that the light automatically turns off after 5 minutes? thanks,

You are making a scene that reacts to the Combination Switch, and the scene’s actions are to turn the light on or off. That’s the connection.

The linked scenario doesn’t include a 5-minute delay (it wasn’t exactly the scenario you are asking about) but you can add that in later, either with a scene delay or with a Countdown Timer device. Get the simpler case working first.

[quote=“futzle, post:11, topic:172579”]You are making a scene that reacts to the Combination Switch, and the scene’s actions are to turn the light on or off. That’s the connection.

The linked scenario doesn’t include a 5-minute delay (it wasn’t exactly the scenario you are asking about) but you can add that in later, either with a scene delay or with a Countdown Timer device. Get the simpler case working first.[/quote]

I have got it working… thanks for your help…

Hi - just getting started with my own scene and it is similar to your approach (have been reading up on this)

What i would like to do is.

If front door alarm sensor is tripped (irrespecitve of if armed or not)
and
time is between sundown and sunrise (or specific times if the previous part is too difficult)
then
Turn on Hall light.

Pretty simple i guess.

Questions.

  1. is the answer use a combination plugin as provided?

  2. are there reasons (cant see them) not to use a combination plugin and choose a luup code?

  3. how does this scene thing work? is it that a schedule or Trigger activates the scene - then if available the luup code runs - and finaly then the actions defined in the scene happen (ie. device xx = on?)

4.When setting up the scene with luup code do I still need a trigger set up for the door or do i use luup code instead?

5.do i need to use an app of some sort to make the above simpler?

thanks for taking the time ( i am still reading on all this ( alot of info) so i the answer is somewhere specific pls point me in that way.

Alex

@alexk
If you just want to activate a light at night based on a trigger, then the simplest option is to create a scene which turns on the required light when the door sensor is tripped and also paste the following code into the Luup tab of the scene:
return luup.is_night()

wow that simple?

Frasier thanks for taking the time.

could you pls answer the following?

  1. how is night defined by luup?
  2. how does the scene work in terms of serial action? does it check trigger & schedules and then run the luup code before it takes any action?

[quote=“alexk, post:15, topic:172579”]wow that simple?

Frasier thanks for taking the time.

could you pls answer the following?

  1. how is night defined by luup?

  2. how does the scene work in terms of serial action? does it check trigger & schedules and then run the luup code before it takes any action?[/quote]

  3. Night is defined by your sunset. So when you filled in your location under vera, it will use those values to determine sunset and sunrise.

  4. Have a look here: http://wiki.micasaverde.com/index.php/Luup_Scenes_Events

  • Garrett

great link thanks!