03.07.2015, 09:30
This is again a work in progress that might be used as inspiration. I have this as a user script that I include in KNX objects to turn DMX lights on/off or to a specific value. All DMX in my home are eldoleds. The user script I use is called user.mydmx
What I am working on is the dimming part... not really sure why it is not working.
An example of usage:
This turns the lights in the living room on or off depending on the value of the KNX object.
What I am working on is the dimming part... not really sure why it is not working.
Code:
-- set of variables for zones in the apartment
-- these are the DMX channels to be set
alllights = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}
bathroomlights = {7,8}
bathroomheadlight = {7}
bathroomfloor = {20}
livinglights = {5,6,9,10,11,12,14,15,16,17,18,19}
kitchenlights = {13}
bedroomlights = {1,2,3}
entrancelights = {4}
-- turns DMX stripe to full on or off based on two groups
function dmxtoggle(channel, state)
-- group that contains the value for ON. I use a slider to define the intensity of on/off
on = grp.getvalue('5/7/17')
-- group that contains the value for OFF
off = grp.getvalue('5/7/18')
if (state == true) then
DMX.set(channel, on)
return on
else
DMX.set(channel, off)
return off
end
end
-- loops through all lights
-- lights is an array of the channel(s) to be set
-- state is the state of the group
-- stategroup is the group that holds the state of this light
-- slider is the group of a slider for setting the light level
function dmxlooptoggle(lights, state, stategroup, slider)
for index, value in ipairs(lights) do
sliderstate = dmxtoggle(value, state)
end
-- write state to state group (that way pushbuttons know the state)
grp.write(stategroup, state)
-- if a slider object was provided, then update the internal value
-- this helps keep the visualization consistent
grp.update(slider, sliderstate)
end
function dmxloopset(lights, value)
for index, channel in ipairs(lights) do
DMX.set(channel, value)
end
end
-- dimm light up
function dmxdimmup(lights, intencity)
for index, value in ipairs(lights) do
intencity = intencity + 1
DMX.set(value, intencity)
end
end
-- dimm light down
function dmxdimmup(lights, intencity)
for index, value in ipairs(lights) do
intencity = intencity - 1
DMX.set(value, intencity)
end
end
-- make it easy to show if a light is on off when also using sliders
function onoffvisu(onoffgroup, state)
if (state > 0) then
-- set on/off to on
grp.write(onoffgroup, true)
else
-- set on/off to off
grp.write(onoffgroup, false)
end
end
An example of usage:
Code:
require('user.mydmx')
dmxlooptoggle(livinglights, event.getvalue(),'5/7/21','5/1/21')
This turns the lights in the living room on or off depending on the value of the KNX object.