convert notifications from Logitech Media Server to MQTT messages
Publish Logitech Media Server (LMS) status changes such as "song started playing" or "alarm went off" as MQTT messages, for use by home automation controllers, such as openHAB.
I created this to support my Weather-Mood-Alarm-Light project.
- Logitech Media Server (LMS), obviously, running on the same or a different machine, reachable via servername:9090
- an MQTT broker such as mosquitto.
- a Linux machine (real or virtual) that can run the daemon script
lms2mqtt.py
. I use Debian 10 on a virtual machine - a recent Python 3 version
- the Eclipse MQTT library, say
pip3 install paho-mqtt
-
copy
lms2mqtt.py
to a directory of your choice, mine is in/home/admin/daemons/lms2mqtt
-
configure the name of the machine running the LMS server in
lms2mqtt.py
-
configure the name of the machine running the MQTT broker in
lms2mqtt.py
-
optionally configure portnumber, username and password of the MQTT broker in
lms2mqtt.py
-
when using systemd (all commands as root or via sudo):
- copy file
lms2mqtt.service
to/etc/systemd/system/
- change
User
and ExecStart`lines as needed - reload systemd:
systemctl daemon-reload
- start lms2mqtt:
systemctl start lms2mqtt.service
- make it start at boot:
systemctl enable lms2mqtt.service
- copy file
-
when using init.d (all commands as root or via sudo):
- copy file
bw-lms2mqtt
to/etc/init.d/
and make it executable - in
bw-lms2mqtt
, set the path where you stored thelms2mqtt.py
script - activate the service with
sudo update-rc.d bw-lms2mqtt defaults
- start the service with
sudo service bw-lms2mqtt start
- copy file
I have noticed that the daemon sometimes looses connection with LMS, don't quite understand why. As a dirty fix, I created a script /root/restart-lms2mqtt.sh
that contains
#!/bin/bash
service bw-lms2mqtt stop
sleep 15
service bw-lms2mqtt start
I run this one every night, via this crontab entry
0 1 * * * /root/restart-lms2mqtt.sh
All MQTT messages start with lms/
, then the MAC address of the player, then a path that is the combination of all the notification words sent by LMS. The payload is the last part of the notification.
Notifications related to display updates and navigation through the SqueezeBox menus are suppressed, because I assume that's not relevant for home automation purposes.
Here is an example, a series of MQTT messages as I operate a SqueezeBox player:
Turn on the player
lms/b8:27:eb:fe:f8:9d/prefset/server/power 1
Select a folder and start playing
lms/b8:27:eb:fe:f8:9d/playlistcontrol/cmd:load/folder_id:14186 count:1
lms/b8:27:eb:fe:f8:9d/playlist/load /storage/music/@Classical/Maria Callas/La Divina I
lms/b8:27:eb:fe:f8:9d/playlist stop
lms/b8:27:eb:fe:f8:9d/playlist/jump/0/ 0
lms/b8:27:eb:fe:f8:9d/playlist/open file:///storage/music/@Classical/Maria%20Callas/La%20Divina%20I/01%20Un%20bel%20d%C3%AC,%20vedremo%20(Madama%20Butterfly%20-%20Puccini).mp3
lms/b8:27:eb:fe:f8:9d/playlist/open file:///storage/music/@Classical/Maria%20Callas/La%20Divina%20I/01%20Un%20bel%20d%C3%AC,%20vedremo%20(Madama%20Butterfly%20-%20Puccini).mp3
lms/b8:27:eb:fe:f8:9d/playlist load_done
Turn up the volume 3 times
lms/b8:27:eb:fe:f8:9d/mixer/volume +2
lms/b8:27:eb:fe:f8:9d/prefset/server/volume 50
lms/b8:27:eb:fe:f8:9d/mixer/volume +2
lms/b8:27:eb:fe:f8:9d/prefset/server/volume 52
lms/b8:27:eb:fe:f8:9d/mixer/volume +2
lms/b8:27:eb:fe:f8:9d/prefset/server/volume 54
Pause the player
lms/b8:27:eb:fe:f8:9d pause
lms/b8:27:eb:fe:f8:9d/playlist/pause 1
Play an internet radio station
lms/b8:27:eb:fe:f8:9d/playlist/play/item http://stream.srg-ssr.ch/m/rsj/aacp_96
lms/b8:27:eb:fe:f8:9d/playlist stop
lms/b8:27:eb:fe:f8:9d/playlist/jump/0/ 0
lms/b8:27:eb:fe:f8:9d/playlist load_done
lms/b8:27:eb:fe:f8:9d/playlist/open http://stream.srg-ssr.ch/m/rsj/aacp_96
lms/b8:27:eb:fe:f8:9d/playlist/newsong In Mission Of Tradition - The Pink Panther Theme
Turn off power
lms/b8:27:eb:fe:f8:9d/power 0
lms/b8:27:eb:fe:f8:9d/prefset/server playingAtPowerOff
lms/b8:27:eb:fe:f8:9d/prefset/server/power 0