Actually:
I have a dimmer. When I swith on, it goes automatically to 100%.
What I wish:
Between 20h00 and 22h30, at a certain day, when i switch on, it goes automatically to 35%
I try to programm (UI4), when dimmer event is ‘on’ go to 35% and it works well but when I switch a second time the dimmer it can go to 100% because the first event was dimmer is on and the state doent change …
How can I programm in Lula Code: whenn dimmer >35% then go to 35% and include the condition of the time?
My setup is based on a camera on my son’s crib that picks up his movement in the middle of the night and turns on lamp connected to a GE45602 for 10 minutes than turns it back off. I check to see if the time is between 6am and 10pm and if so then turn on the lamp and set the brightness to 100% else set the brightness to 30%.
To get this to work I use the Motion sensor on the Camera that triggers the “Baby Light On” Scene where the code below is in, Countdown Timer that starts when the light is turned on and the complete triggers the “Baby Off Light” Scene. At the end I reset the Motion Sensor tripped flag so that if my wife is still changing the baby or putting him down it resets the 10 minute timer.
-- Find the status of the light
local service_id = "urn:upnp-org:serviceId:Dimming1"
local light_status = luup.variable_get(service_id,"LoadLevelStatus", 26)
-- Get the current hour and delay time
local t = os.date('*t')
local current_hour = t.hour
-- Set Hour for Hight Light Levels
local light_high_min = 6
local light_high_max = 20
-- Reset Motion Senson on Baby Camera
function ResetMotionSensor()
luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1","Tripped","0",12)
end
-- Check time to see if we should turn the lights on to 100%
if (current_hour >= light_high_min) and (current_hour <= light_high_max) then
luup.call_action(service_id, "SetLoadLevelTarget", {newLoadlevelTarget = "100"}, 26)
-- Check to make sure the light was not manually turned on before dimming to 30%
elseif (tonumber(light_status) < 30) then
luup.call_action(service_id, "SetLoadLevelTarget", {newLoadlevelTarget = "30"}, 26)
end
-- luup.call_delay("ResetMotionSensor", 30)
return true
Make note that depending on the dimmer, this will not work well when the switch is pressed manually. Meaning if the dimmer does not report instand status, the dimmer will not dim to the proper level defined in your scene.
1/ Is it possible to activate the scene every second, or always (every 0,1s)?
The luup internal timer can schedule at a 1 second interval ... But that eats up a lot of processing time! That's probably why MCV did not bring this out to the user interface.
2/ How is it possible to create an event in a scene like this:
Actually your LUUP code does not create an event. An event happens (timer or trigger).
You can put code in the LUUP tab for the scene that causes the timer or trigger to be ignored.
If the code returns TRUE or does not return anything than it proceeds to execute the commands (and delayed commands) for your scene.