Ok this seemed like a simple idea

and probably is, but I can’t figure it out.

I want my hall light (z-wave light bulb) to turn on when I unlock my front door one hour before sunset and to stop this one hour after sunrise. Light goes off 20 seconds after fist trigger.

I though adding the sunrise sunset as a trigger with the lock would work but it seems to be a or statement so this never gets picked. Light always comes on when door is unlocked…

I tried using the Restrict the trigger to certain times with no success.

So I’m missing something simple I’m sure. Can someone point me in the right direction

This seems like a simple use case for HA that I figured I’d have had this done last Monday.

I’m using a Veralite all up to date UI7 1.7.649

[quote=“erickpanger, post:1, topic:188480”]and probably is, but I can’t figure it out.

I want my hall light (z-wave light bulb) to turn on when I unlock my front door one hour before sunset and to stop this one hour after sunrise. Light goes off 20 seconds after fist trigger.

I though adding the sunrise sunset as a trigger with the lock would work but it seems to be a or statement so this never gets picked. Light always comes on when door is unlocked…

I tried using the Restrict the trigger to certain times with no success.

So I’m missing something simple I’m sure. Can someone point me in the right direction

This seems like a simple use case for HA that I figured I’d have had this done last Monday.

I’m using a Veralite all up to date UI7 1.7.649[/quote]

Look through this post and that sub forum. Lots of stuff in there. I believe most would say the point and click of scenes in Vera is limited, it’s the code you can add that really allows you to do more. And that generates complaints where things like you want to do aren’t readily available without cherry picking some lua code.

http://forum.micasaverde.com/index.php/topic,18679.0.html

Thanks for the link and for not chewing my ass for asking, what looks to be, the #1 question based on that thread length.

So is it as easy as pasting this into the spot that allows me to add Luup on the trigger

local pStart = 0 – Start of time period, minutes offset from sunset
local pEnd = “06:15” – End of time period
local allow = true – true runs scene during period, false blocks it
local mStart = math.floor( (luup.sunset() % 86400) / 60 ) + pStart
local hE, mE = string.match(pEnd,“(%d+)%:(%d+)”)
local mEnd = (hE * 60) + mE
local tNow = os.date(“*t”)
local mNow = (tNow.hour * 60) + tNow.min
if mEnd >= mStart then
return (((mNow >= mStart) and (mNow <= mEnd)) == allow)
else
return (((mNow >= mStart) or (mNow <= mEnd)) == allow)
end

If not I’ll go back to reading all those pages :-\

[quote=“erickpanger, post:3, topic:188480”]Thanks for the link and for not chewing my ass for asking, what looks to be, the #1 question based on that thread length.

So is it as easy as pasting this into the spot that allows me to add Luup on the trigger

local pStart = 0 – Start of time period, minutes offset from sunset
local pEnd = “06:15” – End of time period
local allow = true – true runs scene during period, false blocks it
local mStart = math.floor( (luup.sunset() % 86400) / 60 ) + pStart
local hE, mE = string.match(pEnd,“(%d+)%:(%d+)”)
local mEnd = (hE * 60) + mE
local tNow = os.date(“*t”)
local mNow = (tNow.hour * 60) + tNow.min
if mEnd >= mStart then
return (((mNow >= mStart) and (mNow <= mEnd)) == allow)
else
return (((mNow >= mStart) or (mNow <= mEnd)) == allow)
end

If not I’ll go back to reading all those pages :-[/quote]

LOL, no problem. I can’t provide much code help though. Good luck.

Set trigger.
There is a time restriction on the device trigger (door unlock). Set it for the time you want it to only activate this trigger. Make sure you check the box and that the days selected stay green. it is kind of confusing.
Then set the delay for the time you want the light on and tell it to turn light off.
Test.
Done.

I tried that all days were green I set the restriction for 7 am - 6 pm. No help. I reversed them and no difference.

I pasted that Luup code from my earlier reply that that did not work

My coworker and I came up with this Lua code. Seems to work so far. The light has not come on today as i’very unlocked the door.

Return luup.sunset()-3600 <= os.time() and os.time() <= luup.sunrise()+3600

Seemed too simple based on what I saw in the other thread. I’ll post back tonight how I’d does.

Didn’t work. Back to the drawing board I guess.

Look into PLEG
http://forum.micasaverde.com/index.php/topic,21603.0.html

You would have an Input Timer:
Dark On is Sunset + 1:00:00 Off is Sunrise - 1:00:00

You would have an Input Trigger:
DoorUnlocked

Condition:
UnlockedWhenDark Dark and DoorUnlocked

Actions:
UnlockedWhenDark - Immediate Turn on Light
Delayed - 30 Seconds … TUrn off Light

PLEG is pretty good for this sort of stuff. But if you like to do stuff the old fashioned way, an easier way to set this up is to use the day / night plugin, or a virtual switch plugin that you switch to On when it’s dark using simple scenes. Then simply check the state of that plugin / switch using Luup code in your light scene, and if the scene is not supposed to run, return false (which prevents the scene to run).

@intveltr - Would you actually want to do it that way?

I understand wanting to do it entirely with Lua/LUUP. Not really easy for non-programmers, but I get it.

I understand wanting to do it with a plugin like PLEG. It’s fairly straightforward and easy for non-programmers, while also opening up countless other possibilities.

But, I don’t understand why I would want to use a limited plugin AND a scene to affect the plugin AND a scene where I still have to write Lua/LUUP code.

In my opinion; PLEG is the best solution. Lua/LUUP is a second best choice for people that are capable of writing Lua/LUUP code or are strongly opposed to PLEG for some reason. But, I don’t see why I would choose another option besides these two.

I have something similar working, albeit with slightly simpler conditions.

Since I leave one of my hall lights on at a 10% dimming level until midnight, and do something along the same lines for 6am, I just needed scene LUUP code to cover the midnight to 6am case:

-- Get current hour (0 to 23)
local current_hour = tonumber(os.date("%H"))

-- Scene will execute if before 6am
if current_hour < 6 then
   return true
else
   return false
end