Motion light only at night...

I have a DSC Security panel with a motion detector. I have some outdoor flood lights on a z-wave controlled switch. I have the lights programed to come on when motion is detected and shut off after 10 minutes. My problem is that it does this all day and night long. How can I set it up to ONLY activate at night?

Use the Day or Night Plugin to indicate when you consider day or night relative to sunrise/sunset. Do not forget to do the Vera setup for location and timezone for this to work.

Then use Program Logic Event Generator Plugin to generate an on Event for your Scene.
PLEG Trigger Night = Day or Night device Indicates Night
Motion = Motion Detector device indicates motion.

Condition ActivateLightScene = Night and Motion

or if you just want it at a fixed time, you do not need the Day or Night plugin.

Use the following condition:
ActivateLightScene = Motion and (18:00:00; Now; 23:00:00)

Modify your scene so that it triggers when PLEG has satisfied ActivateLightScene

I have already posted an example of On at sunset, auto off at a fixed time later, and then auto on/off for motion outside that interval at night.

In addition to the Day or Night plugin, you can do it with scenes in combination with the Smart Switch plugin or the Countdown Timer plugin.

(Note: less scenes with the Smart Switch plugin most likely)

If you have some sunrise/sunset (or similar timing based scenes) already, adding the Smart Switch plugin is easy.

I did it on another way. I put a little code on the LUUP tab of the scene

[code]local t = os.date(‘*t’)
local current_second = t.hour * 3600 + t.min * 60 + t.sec – number of seconds since midnight

if (current_second > 0) and (current_second < 21600) then
return true
else
return false
end[/code]

This one returns true between 0:00 and 06:00 so the scene will only work between midnight and 6 o’clock

Thanks guys for all your suggestions! I will look into this and report back!

RichardTSchaefer:

I get this error when entering the “condition”

[size=14pt]Program Logic : ActivateLightScene = Motion and (17:30:00; Now; 23:59:00): Invalid Value token: MOTION[/size]

Where is this example at so I can see it?

Nevermind the last post, I found it…

Can I change this to work from say, 5:30pm to 6:00am? Or is the midnight the earliest this will work?

[quote=“rpleever, post:4, topic:173894”]I did it on another way. I put a little code on the LUUP tab of the scene

[code]local t = os.date(‘*t’)
local current_second = t.hour * 3600 + t.min * 60 + t.sec – number of seconds since midnight

if (current_second > 0) and (current_second < 21600) then
return true
else
return false
end[/code]

This one returns true between 0:00 and 06:00 so the scene will only work between midnight and 6 o’clock[/quote]

then the code would be

5:30pm = 17:30 = 17,53600secs=63000
6am=6
3600=21600

[code]local t = os.date(‘*t’)
local current_second = t.hour * 3600 + t.min * 60 + t.sec – number of seconds since midnight

if (current_second > 63000) or (current_second < 21600) then
return true
else
return false
end[/code]

BTW i notice that > 0 is not even necessary in my own code. The number will be reset to 0 at midnight.

…and if you want it to be even neater, note that:

if logical_condition then return true else return false end

can always be written:

return logical_condition

For some reason, this ugly if-x-then-true-else-false construct appears widely in MCV example code and on the forum. Seems to be embedded in the MiOS psyche ? let’s stamp it out!

let's stamp it out!
Just like some like to talk ... some like to write code! As long as it's correct ... it's just a style issue. It's the ones that write: [code] if logical_condition then return true end [/code] with no other return that you have to worry about! And I see way to much of that. Most of this community are NOT software developers and do not even know why you would care about this. The design principals of initializing all variables, checking all code paths, single return statement, ..., are not concepts for the type of programmers here. In the hands of a skilled user LUUP is sharp knife that gets the job done cleanly ... for the rest ... they have bloody hands.
Program Logic : ActivateLightScene = Motion and (17:30:00; Now; 23:59:00): Invalid Value token: MOTION

A patch was sent out yesterday to fix this … see the PLEG thread.
After you actually triggered the Motion condition … the message would disappear.
Despite this warning the plugin would still work!
The following condition would have addressed the new scenario:

ActivateLightScene = Motion and (not (06:00:00; Motion; 17:30:00)) 

Which should be read as motion when the motion is not between 6AM and 5:30 PM

[quote=“akbooer, post:11, topic:173894”]…and if you want it to be even neater, note that:

if logical_condition then return true else return false end

can always be written:

return logical_condition

For some reason, this ugly if-x-then-true-else-false construct appears widely in MCV example code and on the forum. Seems to be embedded in the MiOS psyche ? let’s stamp it out![/quote]
Actually I have been at different company’s that have style guides dictating one way while disallowing the other.

Some demand 1 and only 1 “return statement” so you have to use variables.
Others demand a boolean return not be a conditional statement.

It goes along the same lines of “{}” being on the same line as the while/for/if statement or not. If it works and you can read/maintain it, I’m fine with that.

I had a similar issue… I had an outdoor motion sensor light that never thought it got dark because one of the night landscape lights were too bright (was a wall wash unit). Since it’s on a zwave controlled switch, I clipped the light sensor inside (now it always thinks it is dark) and then just used a sunrise sunset schedule.

In UI 5, it’s easy. Just create the on scene and then go to schedules tab.

Select a days of the week schedule.
Put a checkmark beside every day of the week.
For the time, I put 1 hour after sunset.

Create an Off scene and just used sunrise for the trigger.

As long as you have your timezone and location set, it will trigger the scene on that schedule.

Works like a champ for me, and no LUUP code, all from the gui.

-G

Hi, I’m a newbie at this so please be patient with me. :).
I have a similar setup but instead of a motion sensor I’m
Using a wired door sensor to turn on a light which is on a
GE dimmer switch. Can some assist me in getting this to work
In pleg or a luup code. I need the light to turn on for 15 mins if
The door is open between the hours of 12 midnight to 6 am. Thx.