so i got time and a dimmer to test on which makes it a lot easier debugging
-- code for multiple dimmers to make a top-notch christmas tree
-- Enter the device ID's here in the array_dimmers comma-separated
local array_dimmers = {34,47}
local original_status= {}
local counter = 10
local delay = 1
local dimmin = 0
local dimmax = 100
local a = 0
function set_switch(device)
for a = 1, dimmin do luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget=a}, device)
end
for a = dimmax, 1, -1 do luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget=a}, device)
end
end
function tree_on()
for i, device in ipairs(array_dimmers) do
set_switch(device)
end
luup.call_delay( 'tree_off', delay )
end
function tree_off()
counter = counter-1
if counter > 0 then
for i, device in ipairs(array_dimmers) do set_switch(device, "0")
end
luup.call_delay( 'tree_on', delay )
else
--Set to original status
for i, device in ipairs(array_dimmers) do set_switch(device,original_status[i])
end
end
end
--Save Original status
for i, device in ipairs(array_dimmers) do original_status[i] = luup.variable_get("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget=status}, device)
end
luup.call_delay( 'tree_off', "0" )
still give me error, probably messed up some arguments…
if i use luup.call_action i get an error in lua , but if i use luup.call_delay it can run a function … ehh, can someone explain ? by design or bug or ?
the following works and makes the fibaro dimmer blink 1 time or if u press the run scene button multiple times it turns it into a disco light.
here is how :
click on AUTOMATION
click on New scene
click on LUUP
On the left top you see : “New scene” , call it whatever you want (it is the name of the scene) or just: “blink light”
in the field which says “Code” you place the code :
-change the device nr 34 into the device you want to blink, has to be appliance switch or light or dimmer
-find the device number :
on device in dashboard click on the wrench on device and in the window that pops up click on settings tab, top left it says :
Device #
<device_number> is the number you need.
-- set variable device to the dimmer device number you want to blink and the delay in seconds for how long you want the device to be turned on
local device = 34
local adelay = 1
-- call function with delay to execute it, note there is no END as nothing started here it just triggers.
luup.call_delay( 'switch_on', 0)
luup.call_delay( 'switch_off', adelay)
-- the function itself doing the switchwork
function switch_on()
luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{newTargetValue="1"},device)
end
function switch_off()
luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{newTargetValue="0"},device)
end
click on SAVE LUA below the inputfield
click on CONFIRM CHANGES green button on right top
click on red SAVE button on right top
saving data press CONTINU
now u have a scene which you can put in a schedule to make it blink on certain time interval
for the Fibaro FGD211 v1.6 dimmer in combination with dummy load , dimmable led and a in-wall on/off switch i used this parameters:
VariablesSet 10,1d,255,13,1d,1,14,1d,1,16,1d,0,19,1d,1,20,1d,110,9,1d,255
to set these :
click wrench on fibaro dimmer device and go to device options
click on add configuration settings and type in the new field:
variable 10 , data size 1 byte dec, desired value 255
close the window and press on red SAVE button and continu
click wrench on Fibaro FGD211 v1.6 dimmer again and go to Advanced
now look for “VariablesSet” in the box next to it paste this
10,1d,255,13,1d,1,14,1d,1,16,1d,0,19,1d,1,20,1d,110,9,1d,255
close window and press red SAVE on right top
the variables set the dimmer to use a bi-stabile switch (on/off, mono-stabile is pulse) , dim leds of 0,5-25 watt (dummy load AND dimmable led light required), adds more stability by lowering and extending the dimming-range of the dimmer so the dimmable-led lights work better and fluctuate less.
Warning: Do not use this variableset for non-dimmable lights or for normal dimmable lights or for cfl or normal led lights.they might overload.
you could use the code also to:
- trigger a mono-stabile switch
- make a hourly chime using the sirene or a light or a doorbell/horn connected to a switch (end of workday horn for on work)
- change the delay to 3 minutes and put a old radio set to the news broadcast on a switch for hourly news
- send a pulse to a water pump so it gives just a little ammount of water for a second or longer if you change the delay
explanation:
luup.call_delay( ‘switch_off’, 1) < the 1 here is the delay in seconds
so 3 seconds would be: luup.call_delay( ‘switch_off’, 3)
5 seconds would be: luup.call_delay( ‘switch_off’, 5)
after that i put the delay in a variable: local delay =
making it : luup.call_delay(‘switch_off’, delay)
edit: something happens which keeps on rebooting vera because of failing lua… maybe the variable delay is used for something else… lets change it.
figuring out what gone wrong with the more complicated script, but documentation is lacking (beside that i wrote half of it i think, from what i know… not that much alas) . i take it the device and dimming value get mixed up .
also found out that if you have 1 scene with an lua error, the rest of the scenes aint working anymore … at least not with the device you are using in the faulty code.