Hi, I am trying to find a way to create a scene that will turn on lights when my z wave door lock is unlocked. The trick is that I only want to turn on the lights during the night, during the day I do not want to turn on the lights. I’ve been playing around with creating a scene, however I have had no luck. I am using the door unlock as the trigger…however, adding a schedule does not seem to control the time of day. I could try to use a 3 in 1 motion sensor, using the luminance setting, however I do not know how to incorporate this into the scene.
Any ideas?
Look into PLEG. Scenes use logical ORs, not ANDs (I believe), that is why the schedule has no affect (actually, it might as it might turn on the light during the schedule, I haven’t messed with them much).
You can also look into using LUA for the scene execution. Here is a thread that should be of great interest to you:
http://forum.micasaverde.com/index.php/topic,18679.0.html
(the second option would probably be easier if you are only looking to do this one thing. Eventually though I feel as though PLEG offers a lot more flexibility as your system grows)
I know PLEG is a great way to go but haven’t had the time to learn it. I ended up achieving the same thing with the Combination Switch plugin as well as the Day or Night one. My combination switch looks for two conditions: “daytime status is night” + “door sensor is tripped”. I then referenced it as a trigger in a scene that turns porch lights on at 50%. Then there’s a 2 minute delay and turns them off.
In the LUUP section of the scene you can just add code similar to this:
if (luup.is_night()) then
return true
else
return false
end
If it is night true will make the scene run, otherwise false tells the scene to not run.
You can search the forum for some fancier code if you want to have more control of what night means to you.
(I always name such scenes something like “Porch Light ON If Night” to differentiate it from just “Porch Light On”.)
As @SirMeili described scenes can use OR conditions like door open OR schedule, but they can’t do schedule AND door open. He’s right, you need PLEG for AND conditions.
There are other options. @CyberGuyPR suggested a workable solution using another plugin. But there is still a way to get what you have requested without any plugins.
You simply need to create your scenes and use the door open/unlock as the trigger. Then on the scene’s luup tab you need to add this line of
return luup.is_night() == true
With this the scene will only run between sunset and sunrise. It will never run between sunrise and sunset.
If you need more specific time schedules, you’ll need one of the mentioned plugins.
Edit: Sorry @AEBogdan, I did not see your post when I composed mine.
In LUUP, what time range is night in? would it be from say 6pm to 6am? Do I still need a 3 in 1 sensor on luminance for this to work or just into the scene is all I need?
[quote=“AEBogdan”]In the LUUP section of the scene you can just add code similar to this:
if (luup.is_night()) then
return true
else
return false
end
If it is night true will make the scene run, otherwise false tells the scene to not run.
You can search the forum for some fancier code if you want to have more control of what night means to you.
(I always name such scenes something like “Porch Light ON If Night” to differentiate it from just “Porch Light On”.)[/quote]
This is what I did and it’s been working for several months. It’s about the only thing my wife likes about HA. When she comes home at night and keys in the code at the deadbolt several internal lights ramp up and the alarm system is disabled.
Sent from my iPad using Tapatalk
Sunrise/sunset times are calculated by Vera for your precise location and date. That’s why Vera needs to know your specific location during initial setup. The precise sunrise/sunset time changes daily and is location dependent.
You would not use the luminance sensor for the luup.is_night() method. The “downside” of not using the luminance sensor is that if you have an overcast or rainy late afternoon, you may perceive darkness for some time before the actual sunset time for that day.
If you prefer to rely on the luminance sensor, you’ll need to use a plugin or write some LUA/LUUP code.
To use an actual luminance value from a device the code will be similar to the following:
local lightLevel = luup.variable_get("urn:micasaverde-com:serviceId:LightSensor1","CurrentLevel", {deviceID})
if (lightLevel and (tonumber(lightLevel) < 100)) then
return true
else
return false
end
Place the code in the LUUP area of your scene. You’ll need to change {deviceID} to the device id number of the device you are grabbing the light level from. Change the 100 to a level that you feel requires the light to be on.
You can search the forum to find plenty of code snippets like this.
I’ve tried the plugin Daytime and the LUUA code:
local dID = 23 – Device ID of your DayTime plugin
local allow = true – true runs scene during daytime, false runs it at night
local status = luup.variable_get(“urn:rts-services-com:serviceId:DayTime”,“Status”,dID)
return ((status == “1”) == allow)
works awesome, with this plugin and code, I can adjust to a couple hrs before sunset and a couple hrs after sunrise.
Thanks for all the ideas guys.