New Binding: Music Assistant

Hello all-

I’ve put together a binding for https://www.music-assistant.io (MA), a popular music library management system with wide support for a number of music player protocols (like airplay, chrome cast and sendspin). This binding provides support for basic functionality (not all of the Music Assistant constructs make sense when exposed to openHAB) and also provides a mechanism for easily performing advanced interactions with the MA server.

MA server discovery is automatic, and once you’ve added an access token for your MA server, Players of all kinds are automatically discovered. The MA Player thing provides access to basic transport control, now playing media info (as well as last played and next up), as well as the ability to start playing a playlist, the names of which are automatically discovered.

I don’t really use the out-of-the-box openhab UIs, so I don’t have any widgets to offer, but the channels are reasonably well thought out, so it shouldn’t be difficult to set something up (which I’d be happy to include in the binding repository for future users!)

Additionally, as I mentioned, there’s a channel that provides a direct API interface with the MA server so someone could use a little javascript and easily add more advanced functionality to widgets and such. I’d also be happy to consider adding additional features where there’s a reasonable way to make it fit into openHAB’s data model.

You can pick up a copy of the binding and drop it in your openhab addons directory. If there’s interest, I can try to get it set up in the marketplace once things mature a bit.

https://bill.welliver.org/dist/openhab/org.openhab.binding.musicassistant-5.2.0.jar

The source code for the current version is at the following repository. Note, though, that this is a mirror of the original repository and I’ve made a typo, so get in touch with me directly if you’ve got bugs or code to share, at least util I figure out a better mechanism for doing that.

I’ve been using this binding for a few weeks and so far, it’s been reliable for me. I’d be glad to hear feedback from folks. I’ve included a capture of a bit of a custom dashboard I set up that uses this binding to control a MA player streaming to a smart speaker in order for folks to see what’s possible.

I look forward to hearing your comments and suggestions!

Best-

Bill

If you post this to the marketplace, users can install it like any other add-on from the add-on store in MainUI.

I recently discovered this player, its playback device synchronization and number of bindings is impressive, it would also be cool to output playback devices for sending voice messages

Hi-

I spent quite a bit of time trying to figure out a good solution for this, and ended up sort of unsatisfied. I’m not sure how much you know about the openhab audio/voice/dialog system, so I’ll just share what I figured out (it’s not really well documented). openHAB has the concept of audio sinks that you can use to play audio files or the results of a text-to-speech operation. Out of the box, there are only a few bindings that provide audio sinks (there are also sources that let you send audio to openhab for, say, voice recognition). You’re basically limited to the speaker on your openhab server and web audio, which works surprisingly well, but it’s a broadcast mechanism, so you can’t send audio to just one browser that’s connected. I think there’s also one for chrome cast devices, and I wrote one for AppleTV/HomePod devices, but that wasn’t very reliable. Someone has taken on the task of writing a new binding for Apple devices, so that might also be an option in the future.

There is also a relatively recent development called the “PCM audio sink” (and source), which is kind of an open mechanism for giving us the ability to announce to arbitrary devices. I wrote an application for android devices that provides a sink (as well as a source if you wanted to play with talking to openhab) so that you can route voice announcements to a device running this app. If you’re running, say, sendspin on the device, it will temporarily duck the music playing during the announcement. The app has also sort of morphed into a dashboard viewer meant to be the ‘default’ app in android. I haven’t published that anywhere, but if there’s interest, I could put that up somewhere for folks to play with (just be aware that there are some rough edges.

I’ve been using a docker container of pocket-tts and a custom version of the open ai text to speech binding to produce announcements; this, coupled with the pcm audio sink app works pretty well. I could also share this if there’s interest. I think the customizations I made probably ought to be submitted for inclusion with the open tts binding that’s already part of openhab.

Having said all of that, Music Assistant has a “play announcement” command that is associated with a given player. It might be possible to get this binding to register each player as an openhab audio sink, which would let you send, say, text-to-speech results to a given player. I’m not sure if there’d be a good way to send an announcement to more than one player simultaneously, unless you set those up as a group in music assistant and then played the announcement to a group. No promises that it would actually work, so I’d need to play around a bit, but does that sound useful?

I’ll be happy to try everything you have, I have a copy of OpenHАB and an Arilic device for experiments, I’m not much of a programmer in OpenHub, I understand it more as a user.I still haven’t found the right multimedia and voice assistant option for me.

I’m not familiar with Arilic… they have some interesting looking stuff!

I will work on typing up an explanation of what I put together, what works and what doesn’t. I’ll also try to put together a basic explainer of what the various parts of the puzzle that openhab provides and how they can be used (as far as I’ve pieced together!). That might take a week or so, but I’ll at least report back on this thread when that’s done. Feel free to remind me if it’s gone much longer than that! I’ll also work on making the other software I mentioned a bit more usable for the wider audience.

Oh, also wanted to mention that I put together a new version that adds the ability to send announcements from openhab to a MA player. Just take the latest version of the add-on above and install it in your openhab. What should happen is that any player things you add will automatically register themselves and an “Audio Sink”. You can then route Text-to-speech and other audio clips to the player of your choice.

The easiest way to demonstrate this is to go into your settings and choose “Audio” and then under “Default Audio Sink” select the player thing of your choice. Then start up the openhab command line tool and run

audio play “doorbell.mp3”

And you should get audio output on the MA player you selected as the default audio sink. Once you have that working, you might want to set up a Text-to-Speech service to get openhab to read announcements. Doing this might involve rules or scripts; I’m working on some of this myself and can probably share some examples.

There are some knobs that you can adjust under the MA bridge device (the thing that represents the actual MA server) if you have an unusual or complicated network setup, like an openhab server with multiple network connections and you need to specify the url you want music assistant to use to fetch the announcements. If you run into problems getting this much to work, just drop a note back here and I can try to help you work through the problems.

Anyway, feel free to give it a try and let me know if you run into any problems or have suggestions!

Hello, I tried your binding today, even checked sending voice messages when music is playing, everything works very well, all the playback devices that were in the assistant are now in OpenHAB. Now we can send voice messages via TTS without stopping the music that is playing, it’s really cool

Thanks you VERY much ! I’m in the process of switching from Lyrion to Music Assistant, and I really missed the openHAB integration for my automations.

I put some hours in starting a Music Assistant binding one month ago, and I’m very glad you beat me to it !!! :+1:
This works very well (I got ony one very small issue : music doesn’t go on after an announcement, not very important though).

So great work, I hope you will put it on the marketplace, or, even better, make a PR to integrate it in the official repository.

Thanks again

I’m glad it’s (more or less) working for you. I’ve got a fair collection of digitized music that I’ve struggled to find a good way to use (in addition to an Apple Music subscription and some items in Bandcamp). MA isn’t perfect, but there are a bunch of nice features there. I’d be interested in hearing your thoughts on the problems you’re trying to solve and the various things you’ve tried!

I haven’t done a lot of testing of the announcement function yet, however when I was testing, the audio did resume following the announcement. I’m inclined to think this may be a problem on the Music Assistant side, as we just send a command to play an announcement… there’s no real control beyond telling it to play.

If you looked at the Music Assistant control interface for your player, what does it indicate during and after the announcement? Since we’re just telling MA to play the audio from a URL that openHAB hosts, it’s possible that there’s something wrong with that audio stream that makes MA think the announcement is continuing, even though there’s no audio. We’re dependent on whatever is generating that audio to provide a well behaved audio file, and I’ve seen some TTS services generate audio with artifacts (but never one with extended silence).

If you let us know what you’re using to generate the announcement, that would be helpful, too.

I’m definitely open to making the binding available through some more automatic means. I have limited time to work on this, so we’ll need to balance the effort against the benefit. Once the development activity has settled down a bit, I’ll take a look at what will be involved.