Tag Archives: script

DMX LogicMachine Lights user library

I have been optimizing my DMX scripts for the LogicMachine. The following is a set of functions that will enable you to turn a set of DMX channels on/off.


-- set of variables for zones in the apartment
 alllights = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24}

 bathroomlights = {7,8,20}
 livinglights = {5,6,9,10,11,12,14,15,16,17,18,19}
 kitchenlights = {13}
 bedroomlights = {1,2}
 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
 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)
 else
  DMX.set(channel, 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
function dmxlooptoggle(lights, state)
 for index, value in ipairs(lights) do
  dmxtoggle(value, state)
 end
end

--Loops through an array of channels and sets them to a value
function dmxloopset(lights, value)
 for index, channel in ipairs(lights) do
  DMX.set(channel, value)
 end
end

To use it, create a user library, I called it mydmx. Then copy/paste the above code and change the variables to the light groups you want to switch together.

To then run it use the following code. The first line enables the above user library. Then the dmxlooptoggle is called to change the bathroom light to the value of the group (on/off). the last code updates a group that holds the status object (on/off).


require('user.mydmx')
dmxlooptoggle(bathroomlights, event.getvalue())
grp.write('5/7/24', event.getvalue())

Batch change color of SVG icon set

CC-SA 3.0
Iconset in LM3

I ran across this cool set of icons that can be used in home automation projects. The latest firmware from openrb allows me to use SVGs as Icons in the logic machine re:actor. Only drawback is that for each state I would like to change the color of the icon. The iconset is set in white as default color.

When you open any of the SVGs from the KNX User Forum you will find that the color is set as a standard #000000 HTML color value for white. All we would need to do is switch these from that to for example #FFFFFF for them to be black. To do this on one file the code would be:
sed -i -e's/\"#.\{6\}/\"#000000/g' -e 's/#.*;/#FFFFFF;/g' icon.svg

where icon.svg is the file we want to turn into black lines.

If we then want to change all, we need a small bash script to loop all the files in a directory and apply the change. That would look like this:
for f in *.svg;
do
echo "Changing color of $f ..."
sed -i -e's/\"#.\{6\}/\"#000000/g' -e 's/#.*;/#FFFFFF;/g' "$f";
done

It is a good Idea to rename the files with a prefix that describes the color. That way you will have them sorted by color in the logic machine. Just change Black to any color you have chosen.
for f in *.svg ; do mv "$f" "Black $f" ; done

The logic machine likes the files to be zipped if you are going to upload a batch. I used this command to generate it:
zip black.zip *

Now you can go into the logic machine and upload black.zip.

DMX dimming using the Logic Machine

The following script enables you to dim all channels monitoring a KNX group. The code assumes you have created dummy objects (starting 10/0/1) in the Logic Machine for each DMX dimmer channel. That way we can visualize the status of the dimmer and recall the values from other scripts.

Depending on the group value of the dimming group the DMX full on value gets edited accordingly.

I have commented out the logging of each dimming step, but if you are debugging, that might be helpful.

-- This software may be used and distributed according to the terms of the -- GNU General Public License version 3, incorporated herein by reference. -- config variables dmxchan = 12 -- number of max DMX channels to change dimprefix = '10/0/' -- for dummy groups dimgroup = '1/0/1' -- group that dims all dmxon = 255 dmxoff = 0 -- end config variables -- percentage up/down values of the 03.007 KNX value local percentages = {1,1,0.5,0.25,0.12,0.06,0.03,0.01,1,1,0.5,0.25,0.12,0.06,0.03,0.01} -- read value as of moment of change value = grp.getvalue(dimgroup) -- define the up down as a percentage of the full on value dimstep = math.floor(dmxon * percentages[value]) while (value >= 9 and value < =15) do -- Dimming UP for i = 1, dmxchan, 1 do -- I have created dummy objects in the LM to store the dimming value of each channel. 10/0/x DMXvalue = grp.getvalue(dimprefix .. i) if (DMXvalue >= 0 and DMXvalue < = 255) then DMXvalue = DMXvalue + dimstep if (DMXvalue > 255) then DMXvalue = dmxon end else DMXvalue = dmxon end DMX.set(i, DMXvalue) -- update the dimmer status group for specific channel grp.update(dimprefix .. i, DMXvalue) end -- update the Status group for all Dimmers, helps for visualizations grp.update(dimprefix .. 0, DMXvalue) -- give the device enough time to process os.sleep(0.1) value = grp.getvalue(dimgroup) --log('Dimm up ' .. DMXvalue) end while (value >= 1 and value < = 7) do -- Dimming Down for i = 1, dmxchan, 1 do DMXvalue = grp.getvalue(dimprefix .. i) if (DMXvalue >= 0 and DMXvalue < = 255) then DMXvalue = DMXvalue - dimstep if (DMXvalue < 0) then DMXvalue = dmxoff end else DMXvalue = dmxoff end DMX.set(i, DMXvalue) -- update the dimmer status group for specific channel grp.update(dimprefix .. i, DMXvalue) end -- update the Status group for all Dimmers grp.update(dimprefix .. 0, DMXvalue) -- give the device enough time to process os.sleep(0.1) value = grp.getvalue(dimgroup) --log('Dimm down ' .. DMXvalue) end [/prettify]

The screenshot shows you how I added the status into my visualization.
Logic Machine DMX Dimming visualization object

Here you see the dummy objects I created.
Logic Machine DMX Dimming dummy objects

CONTROL DIMMING (4-bit)
9 10 11 12 13 14 15 8 0 7 6 5 4 3 2 1
100% Increase 50% Increase 25% Increase 12% Increase 6% Increase 3% Increase 1% Increase Stop Stop 1% Decrease 3% Increase 6% Increase 12% Increase 25% Increase 50% Increase 100% Increase