Tag Archives: KNX

Control of the Logitech Media Server using the LogicMachine

I use the Logitech Media Server to stream multi-room audio in our apartment. Lately I wanted to be able to also control the Spotify Plugin from the KNX buttons at home and automate some tasks.

This is a simple user library to allow you to send commands to a player attached to your LMS.

--Functions for Logitech Media Server integration
squeezboxserverip = '192.168.178.2' -- IP of the Logitech Media Server

function unescape(space)
return string.gsub(space, ':', '%%3A') -- the telnet server returns : as %3A
end

function squeezeboxsendcommand(player,command,value)
socket=require('socket')
local client = socket.connect(squeezboxserverip, 9090)
playercommand = player .. ' ' .. command .. ' '
client:send(playercommand .. value .. '\n')
local result=client:receive()
status = string.sub(result, string.len(unescape(playercommand))) --remove the MAC and command to get to the answer
client:close()
os.sleep(0.2)
return(status)
end

function squeezeboxstatus(player)
socket=require('socket')
local client = socket.connect(squeezboxserverip, 9090)
playercommand = player .. ' status'
client:send(playercommand .. '\n')
local result=client:receive()
status = split(result, ' ')
--status = string.sub(result, string.len(unescape(playercommand))) --remove the MAC and command to get to the answer
client:close()
log(status)
return(status)
end

to play a Spotify Playlist you need to add this code to a KNX object.


require('user.squeezebox') --get the user library to access LMS

local player = 'b8:27:eb:ad:6b:c3' --set witch player to access

if (event.getvalue() == true) then
squeezeboxsendcommand(player, 'playlist', 'clear') -- reset any playlist
squeezeboxsendcommand(player, 'playlist add', 'spotify:user:1175125342:playlist:7yCDwOnYZTXFTYymXZxp0t') --get this command from the logs of the LMS when playing the Spotify playlist
squeezeboxsendcommand(player, 'playlist shuffle', 1) -- shuffle, if you want
squeezeboxsendcommand(player, 'play', '') -- now play the list
grp.write('11/6/1', 'Playing Spotify')
else
squeezeboxsendcommand(player, 'playlist', 'clear')
grp.write('11/4/0', false) --turn off player
end

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.