Can anyone advise on how to interact with the Spotifyd daemon via Dbus / Mpris? Let me first explain the context.
I have a headless RPi4 running audio processing very successfully (Roon Bridge, Spotifyd, CamillaDSP via RME ADI-2 DAC FS connected by USB). Node-red plays a big part in control, for including swapping CamillaDSP configs depending on the audio source (including CD SPDIF input to the RME) and adjusting volume inputs from a Logitech Harmony through CamillaDSP's websocket.
However, there are control aspects I'm currently missing when using Spotifyd. This is a great daemon that acts as a Spotify Connect device. It applies the Spotify auth credentials from whichever Spotify client connects to it, allowing visitors to play their playlists. That flexibility is really important because the users are mostly our three daughters! It's also a problem since, as far as I understand things, it rules out options for control which require the Spotify auth credentials to communicate with Spotify directly since those credentials will vary depending on who is streaming. So the control aspects I'm missing have to operate via Spotifyd.
The core control aspects I need are firstly, to detect that the Spotifyd Spotify Connect device has started playing, and then subsequently to be able to start and stop playback. From what I've read of Dbus / Mpris, they can do this and Spotifyd supports them. However, despite lots of Googling I still don't understand how to establish a connection to those protocols using my setup. I don't program or use Python - my current toolset extends only to Node-red, OpenHAB, MQTT and Docker on a separate networked machine.
If you've already got something like this up and running, I'd love to hear. Alternatively, any pointers would be welcome.
Well, I've been making some progress on this. The first element was discovering that spotifyd supports this as an option:
—-onevent curl http://192.168.11.97:1880/Spotify
With some help from @Colin I can now trigger a Node-RED flow whenever there's a change in what spotifyd is playing or pausing.
I have also discovered Spotimaster but this seems a very heavy solution to what I'm after, and I wasn't sure I fully understood how to implement it. Looking through the dependencies highlighted dbus-send so I decided to investigate that a bit further.
dbus-send is a standard part of Ubuntu, so if I can figure out how to use it to address the spotifyd daemon, I should be able to make this work without installing anything else. I found an excellent guide which I'm slowly working through. I've already found the spotifyd device on the dbus:
ubuntu@ubuntu:~$ dbus-send --system --print-reply --dest=org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager.ListUnits
method return time=1662102778.773997 sender=:1.3 -> destination=:1.52 serial=2743738 reply_serial=2
string "Spotify Daemon"
object path "/org/freedesktop/systemd1/unit/spotifyd_2eservice"
object path "/"
Now I just need to work what methods (?) are supported by the spotifyd unit, how to send them from and get the reply into Node-RED and I'll be almost there ...
What you found is not the dbus interface for spotifyd. It is the Systemd interface for the spotifyd service...
Unfortunately, spotifyd does not currently connect to a system dbus daemon, only a user-specific dbus session.
See add config option for bus type for MPRIS · Spotifyd/spotifyd@4c6664b · GitHub for a pull request to change that.