Media Player platform for Mopidy

Damn! I’m stuck at the very first step
My purpose is to install MOPIDY on an HAOS instance on RPI3 in order to play some mp3 files on event trigger.

The real problem is that I failed to find instruction on the installing process.

What I did so far:

I went on the github repository where I found some install instruction:

  1. Install HACS
  2. Go to any of the sections (integrations, frontend, automation).
  3. Click on the 3 dots in the top right corner.
  4. Select “Custom repositories”
  5. Add the URL to the repository.
  6. Select the correct category.
  7. Click the “ADD” button.
  8. Go to Home Assistaat settings → Integrations and add Mopidy
  9. Restart HA

But when at the step #8 i can’t find the Mopidy integration. When I go to “HACS - integrations - custom repositories” the “Mopidy Media Playes component” is there. But when I go to “Settings - Devices and Services” and try add the Mopidy integration I get this answer: " No integrations matched your search, the integration you want to set up might not be available to set up via the UI yet. "

What’s wrong? What’s my mistake?

Does anyone know where to find a detailed tutorial on how to install Mopidy?

Thanks a lot.

Can you check through a terminal or filebrowser if /config/custom_components/mopidy exists?

If it is not there, it was’t properly installed. If it is, it’s worth a shot restarting you HA completely.

1 Like

Have a look at the personal repositories list to check if the URL in point #5 was correct.
(“bushvin/hass-integrations”)

1 Like

Hi Bushvin. Thanks for your hint. Yes, the component is there:
image
Indeed, after some attempts, now I have the component installed. But I can’t succeed in configuring it. A configuration dialog appears, asking for name and address of a server:
image
Seems that I just installed a client. Should I install also a server? How?
Let me stress that my purpose is to play some mp3 file though the 3.5mm audio port.

Apologies for my late reply. Life got in the way.

Yes, this integration is the “client” part to the Mopidy Server. You do indeed need to install a mopidy server, either on another machine, or using @frenck 's awesome mopidy addon

1 Like

Thank you @bushvin , I’ll try with it. Meanwhile I used TTS messages to Alexa to have alerts.

Hey @pklemy
I have recently come across your issue, I believe: mopidy resuming normal play before your notification tone is played.
I believe it has to do with the speed at which the automation is executed compared to mopidy actually playing the tune.
adding a static wait resolved it for me.

I have discovered mopidy is not the only one to actually have this issue…

I believe

- wait_template: "{{ not is_state('media_player.ha_player', 'playing') }}"

is the real culprit, as the media_player doesn’t start playing (or report it is playing) immediately. It needs to perform whatever protocol/app handshake before reporting it is playing, so your wait_template actually sees the player is not playing and does what it needs to do: continue.

So my advice is to add a 5 second wait before your wait_template:

- delay: 5
- wait_template: "{{ not is_state('media_player.ha_player', 'playing') }}"

this way your media player gets the time to actually start playing.

1 Like

I installed it yesterday but I dont have the link - if I remember correctly since you might be having the same issue from the website tutorial im thinking of - I didn’t copy/paste the full text box from that site you might be on. I split the sudo commands in separate lines but once I copied the entire text box and pasted - it ended up working.

1 Like

Hi,

I installed the integration via HACS, but when I try to add it via the “add integrations” it shows an error when I try to config it. “Cannot Connect to Mopidy host” I used my IP 192.168.1.xx for the hostname. Do I have to start the server first? I already restarted Home Assistant.

Hey there,

This component needs a working mopidy server, which can be installed in your HA server as an addon if you wish.

Check in the thread, there have been people here before you with similar questions.

Hello,

First off, thank you all for using my integration, and providing feedback for the past 3 years!

I am currently re-factoring the integration to take advantage of features introduced in Home assistant (queueing, …), replacing some code that is deprecated, try to make it better, and a bit more future proof in general.

I would really appreciate it if anyone is willing to test my new integration before I release it out into the wild.

Testing it does require knowledge on basic git usage and how to manually install custom components, so you need to be comfortable with that. It is currently not (yet) available in HACS.

I am using it myself, and am happy with the performance and stability. I do not expect it to break your setup. But in the event it does, it is just a matter or putting back your original files.

There is no need to remove your mopidy entities in HA, replacing the files and restarting your ha instance is all that is needed.

Git repo

Branch name feature/compat

Howto

  1. Download and extract or clone the repo to your HA instance or computer
  2. make a backup of your existing mopidy component on your HA instance (just in case)
  3. copy the files to the custom component directory (custom_components/mopidy/)
  4. restart HA

Unfortunately, I cannot offer any compensation for helping out other than making you immortal in the acknowledgements section in the README.

After a Home Assistant upgrade, my Mopidy didn’t work anymore, so I upgraded to the latest version of your integration using HACS.

Now I’m getting this error in my Home Assistant logs:

2023-11-22 12:10:14.586 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up mopidy platform for media_player
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/entity_platform.py", line 359, in _async_setup_platform
    await asyncio.shield(task)
  File "/home/homeassistant/.homeassistant/custom_components/mopidy/media_player.py", line 117, in async_setup_entry
    speaker = MopidySpeaker(hass, hostname, port)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.homeassistant/custom_components/mopidy/speaker.py", line 555, in __init__
    self.__connect()
  File "/home/homeassistant/.homeassistant/custom_components/mopidy/speaker.py", line 587, in __connect
    self.api.add_callback('options_changed', self.__ws_options_changed)
    ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'MopidyAPI' object has no attribute 'add_callback'

Could it be that I am missing a python library that should be installed with pip?

Hey,
Would you mind telling me the version of your Mopidy player?
I’m guessing the integration you installed is v2.2.1?

Hi @bushvin
Thank you very much for your afford and great work! Your integration brings a lot of joy in our daily life, given that we use it to play audio books and music in all rooms :slight_smile:
Would you please add information on how to support your work on your GitHub page? Thank you!

@dikt, you are too kind!
While I do not mind receiving your precious gift, please consider a couple of my favorite charities in stead of donating to me:

But if you only want to donate to me, I now have a ko-fi page, thanks to you :wink:
Cheers!

Thank you! This is excellent, simple install and very easy to link to my Mopidy+Snapcast set up.

I couldn’t follow the directions for search, it was all a little over my head, but being able to search and add to the playlist from HA would certainly be the icing on the cake.

1 Like

Thanks for sharing this, and continuing to develop it @bushvin!

I’ve just installed it and really enjoying it so far!

I was wondering if anyone has been able to interrupt a stream with e.g., TTS, wrapped with a snapshot and resume? My initial attempts were not successful.

According to what I have been reading, the way this works is a bit different with each integration, device, etc. so I thought I might ask here for starters.

In the meantime, I’ll keep plugging away trying to figure it out.

Details (thank you for looking!)

I am piping the output of Mopidy into snapserver, via a named pipe on the same machine, bog standard per the (Snapcast) docs. I can hear music (and/or TTS) on the snapclient(s), and can pause, resume, etc. from HA, just not the way I want/expect from a script (yet). The Mopidy source is SomaFM if that matters (and maybe I will try some other sources as well).

EDIT:

I got it working. For some reason, it wouldn’t work from the ‘Run script’ option inside the 3 dot menu in the scrip edit UI. But it did work once I saved it and called it as a service. And then I had to play with the timing a bit, while watching ‘States’ in ‘Developer tools’.

Next steps will be to parameterize it, possibly set volume of various snapclients (still need to install that integration), etc.

Cheers! :beers:

That is awesome!
Would you mind sharing how you did it (code and stuff), and if you’re ok with it, I can add it to the wiki of the repo

Thanks!

I started writing out a reply here and it became pretty long. Then the power went out here. :scream:

Luckily when I came back the forum software still had a draft copy. :relieved:

But I decided it might be better to start a new thread, so that’s what I did:

DIY F/LOSS “Sonos-alike” (with Snapcast, Mopidy), and dad jokes via TTS (with ducking/restore)

Feel free to copy or post a link to the thread!

Cheers! :beers:

That’s a bummer… fortunately the site kept a draft.

The how to looks awesome, I’m not home for a couple of weeks, so won’t be able to test it myself.