You may have noticed that the fibaro dimmer “memorize” their level. So when you do a push of the switch, the light returns to its saved position and to force 100% level, we have to do a quick double press.
Ok but howto force 100% level when we use the switch ? (without not completely disable the dimmer function).
Well I have the solution ;D
We need to create a scene that will be triggered each time you turn on the light in question. If you have multiple lights (dimmer modules) you can either create a scene by light (but it’s not pretty) or create a trigger by light in your scene. This is the solution I will explain here. Once you have created the scene and all triggers, you need to go every Trigger “luup event” and simply write the following line:
-- replace the number by the associated device id.
lul_device = 69
This manipulation is to know what device call the scene. Now go to the tab “Luup” of the scene and write the code that will force a 100% light when using the switch.
if (lul_device == nil) then
luup.log("Not triggered from a device")
return false
end
local dim = luup.variable_get("urn:upnp-org:serviceId:Dimming1", "LoadLevelStatus", lul_device)
local bin = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", lul_device)
if dim == nil then dim = -1 end
if bin == nil then bin = -1 end
dim = tonumber(dim)
bin = tonumber(bin)
if (dim == 0 and bin == 1) then -- cette condition n'est vraie que si on allume la lumière depuis l'inter.
luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = 100}, lul_device)
end
Et voila
It works as follow :
- You turn on the light from the switch
- The light goes to “the saved position”
- The scene is triggered and the luup code is executed
- It forces the light to 100%
Note: If you remove the progressive dimming function (parameter 10 = 0), you will see the light go to the “temporary” position a very short time before the scene is executed. If you left the default ramps, it will be invisible.
Now we can do things even more fun such as changing light level according to the time.
I do not like the light in the morning (or night when I get up to pee), so I completed the scene as follows:
local limit = 40
if (lul_device == nil) then
luup.log("Not triggered from a device")
return false
end
local dim = luup.variable_get("urn:upnp-org:serviceId:Dimming1", "LoadLevelStatus", lul_device)
local bin = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", lul_device)
if dim == nil then dim = -1 end
if bin == nil then bin = -1 end
dim = tonumber(dim)
bin = tonumber(bin)
if (dim == 0 and bin == 1) then
if (inTime("02:00", "08:30") == 1) then -- between 2 am and 8.30 am I limit the level
luup.log("C'est la nuit. Brrrr")
luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = limit}, lul_device)
else
luup.log("C'est le jour")
luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = 100}, lul_device)
end
end
The magic function “inTime(startTime, endTime)” returns 1 if the current time is between startTime and endTime and 0 otherwise.
Put in “Develop apps”> “edit lua startup”
function inTime(startTime, endTime)
local hour = tonumber(startTime:sub( startTime:find("%d+")))
local minute = tonumber(startTime:sub(-2))
if hour and minute then
startTime = hour * 100 + minute
else
luup.log("inTime: ERROR: invalid start time")
return 0
end
hour = tonumber( endTime:sub( endTime:find("%d+") ) )
minute = tonumber(endTime:sub(-2))
if hour and minute then
endTime = hour * 100 + minute
else
luup.log("inTime: ERROR: invalid end time")
return 0
end
local currentTime = os.date("*t")
currentTime = currentTime.hour * 100 + currentTime.min
local intervalTime = (endTime - startTime) % 2400
if (((currentTime - startTime) % 2400) < intervalTime) then
-- I'm in
return 1
end
-- I'm out
return 0
end
Have fun