Hi,
Just installed my first batch of Z-Wave components & Vera3.
So far I’m quite happy with my choice! installation is going smoothly.
UI5 is not what we can call “user friendly”… however, I really appreciate the fact that you can develop/script + root access + that it can run without depending on central servers (these were the selling points).
I have just completed my first LUUP scene to control lightning in my corridor. As I’m really new to this stuff, I would really appreciate a quick review/comments/suggestions! ![]()
Goal:
- corridor lights can be controlled with two mono-stable switches (one at each end of the corridor) and can be dimmed (wiring done using a Fibaro FGD221 module)
- a motion sensor (Aeotech 4-in-1) will turn the lights on + adjust dimming intensity according to outside luminosity (currently based on luup.is_night(), may change this later for an outside sensor) and intensity of the dimmer in my living room (in order to balance relative luminosity)
. when living room lights are OFF during night, set corridor lights to 15% (night time case)
. when living room lights are OFF during daytime, don’t turn corridor lights ON (day time case)
. when living room lights are ON during night, set corridor lights to 2/3 of the living room dimming intensity & no less than 15% (evening case)
. when living room lights are ON during day, set corridor lights to the same intensity as the living room (end of day case)
. lights will stay ON for at least 30 seconds and as long as motion is detected (Aeotech sensor timeout is also set to 30 seconds)
. when someone manually changes the dimming intensity in the corridor, don’t turn lights ON/OFF automatically (manual override case)
Those rules are just a starting point and will be probably adjusted.
Here goes the corresponding working LUUP code for the single scene that manages all of this:
[tt]
local dimmer_device = 18 – corridor dimmer
local sensor_device = 19 – corridor motion sensor
local reference_dimmer_device = 11 – living room dimmer
local target_dimming = 20 – dimming %
local min_timeout = 30 – seconds
local retry_timeout = 3 – seconds
function calc_dynamic_dimming()
local reference_dimmer_state = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, reference_dimmer_device)
if (reference_dimmer_state == “0”) then
if (luup.is_night()) then
target_dimming = 15 – 15% during night
else
target_dimming = 0 – stay off during daytime when reference dimmer is off
end
else
local reference_dimmer_load = luup.variable_get(“urn:upnp-org:serviceId:Dimming1”, “LoadLevelStatus”, reference_dimmer_device)
reference_dimmer_load = tonumber(reference_dimmer_load)
if (luup.is_night()) then
target_dimming = math.floor(reference_dimmer_load * 2 / 3) – 2/3rd of reference dimmer during night
if (target_dimming < 15) then
target_dimming = 15 – but no less than 15%
end
else
target_dimming = reference_dimmer_load – copy reference dimmer value during day
end
end
end
function switch_on()
luup.log("Switching dimmer ON to " … target_dimming)
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, { newLoadlevelTarget = “” … target_dimming }, dimmer_device)
luup.call_delay(‘switch_off’, min_timeout)
end
function switch_off()
local current_dimmer_load = luup.variable_get(“urn:upnp-org:serviceId:Dimming1”, “LoadLevelStatus”, dimmer_device)
if (current_dimmer_load == (“” … target_dimming)) then
if (luup.variable_get(“urn:micasaverde-com:serviceId:SecuritySensor1”, “Tripped”, sensor_device) == “1”) then
luup.log(“Not switching dimmer off yet, sensor is still tripped. Retrying in " … retry_timeout … " seconds”)
luup.call_delay(‘switch_off’, retry_timeout)
else
luup.log(“Switching dimmer OFF”)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, { newTargetValue = “0” }, dimmer_device)
end
else
luup.log("Not switching dimmer off, load level has changed from " … target_dimming … " to " … current_dimmer_load)
end
end
if (reference_dimmer_device) then
calc_dynamic_dimming()
end
if (target_dimming > 0) then
switch_on()
return true
else
return false
end
[/tt]