Media Player platform for Mopidy

This is not an add-on, this is an integration to use existing mopidy players with Home Assistant.

2 Likes

@currest2620
This platform (not add-on) only allows interaction with Mopidy Servers (or player if you prefer). To use multi-room, you need (in this case) snapcast.
Mopidy can be configured to stream to remote devices, but it is limited to (usually) a couple of (open) protocols (gstreamer, pulseaudio).

Knowing Apple, they will not support anything they do not control.

1 Like

Thanks for the answers guys. I was hoping I could use the mopidy server to stream to airplay devices using say forked-daapd and/or shairport-sync and have that controlled via homeassistant using your integration.

forked-daapd plays spotify but not soundcloud, whereas mopidy plays soundcloud but without airplay!

Also thanks for pointing out the difference between an integration and an add-on.

Thanks again.

@bushvin Thanks for this! Just got it up and running. Works perfectly and is exactly what I was looking for!

1 Like
Logger: homeassistant.components.media_player
Source: custom_components/mopidy/media_player.py:189
Integration: Media player (documentation, issues)
First occurred: 9:47:56 PM (1 occurrences)
Last logged: 9:47:56 PM

mopidy: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 358, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 466, in async_device_update
    await task
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/mopidy/media_player.py", line 514, in update
    self._fetch_status()
  File "/config/custom_components/mopidy/media_player.py", line 189, in _fetch_status
    self._volume = float(self.client.mixer.get_volume() / 100)
TypeError: unsupported operand type(s) for /: 'NoneType' and 'int'

Getting this error here, seems to be due to not using a mixer with my Mopidy server. Could I request support for having the mixer set to ‘none’? (I use Snapcast for my volume control)

Thanks, the integration works fantastic otherwise! :slight_smile:

Hi @Aaron_Lloyd

Thank you for reporting this.

I will definitely have a look at this.
Can you provide me with your mopidy configuration, or at least the relevant part? /etc/mopidy/mopidy.conf so I can reproduce the issue myself?

Make sure to remark all sensitive informatiin.

The audio section is where you define the mixer, here’s what mine looks line:

[audio]
mixer = none
output = audioresample ! audioconvert ! audio/x-raw,rate=192000,channels=2,format=S32LE ! pulsesink server=127.0.0.1

The default mixer is ‘software’, so my setup works if I comment out the mixer line. There are other potential mixers that can be added via extensions to Mopidy to my understanding. You might also want to test those at some point as well for compatibility.

Hey @Aaron_Lloyd
Can you pull and test?

I can confirm it’s working now with the mixer set to ‘none’. :ok_hand:

Thanks again for all your hard work on this!

1 Like

@bushvin Thank you so much for your effort! This was the integration I was always looking for.
I can confirm that it works like a charm here.
If there is anything I can do, e.g. further testing, documentation etc. just drop me a line I am happy to help!

By the way:
image
This is how it looks like in my lovelace dashboard. Grouped with the snapcast entities for multiroom (mini-media-player card)

1 Like

I installed and liked it a lot, congratulations, I also use a youtube extension on my Mopidy, but it does not appear automatically in the media browser, is there any additional configuration to be done or would it be necessary to add this feature in this integration?

@dikt
Thank you for your kind words. If I ever need such things I will keep you in the loop.

@Felipe_Messias
To be honest, I haven’t tested all Mopidy extensions, but you just put the YouTube extension on the priority list of the roadmap :wink:

1 Like

@elle2, @pav, I have found a way to proxy the thumbnails through hass.
If you’re up to it, can you pull and test?

@bushvin, I will try, but you have to note that I don’t expose my home assistant server to internet and therefore I access only via lan.
I don’t know if it could be a valid test for you.

@bushvin, with last version I have an “unknown error” when I’m trying to browse local library. I see some thumbnails but it’s not possible to open the related album directory.
Instead the tracks of the same album are accessible via playlist and show the album art into media player card.
IMHO there is a regression. If I return to the prevoius version, all it’s ok

I’m using HA core 2021.2.0

You’re, right something’s not good. I reverted the commit, so it should work as it once did

Back to the drawing board…

Hey @Felipe_Messias

I’ve had a look at the Mopidy YouTube Extension, and as far as I understand, it does not provide a tree in the library with pre-populated items it finds on YouTube. It allows you to specify a YT url, prefixed with yt: in a player (usage).

Unfortunately, the Home Assistant Library (Which is used by all media player platforms) offers no such functionality.
The only way I see to use this, is for instance in a playlist.

Example playlist:

yt:https://www.youtube.com/watch?v=gfbJCzaEdps

Save it into your “playlist” directory of your Mopidy Server. Reload your library/restart Mopidy.
Then you can play that playlist through the sources of the media player widget.

Let me know if am missing anything.

1 Like

@bushvin Thank you for your attention, I honestly never tried this possibility, I always search for the music I want to hear through the search bar of my web client (Iris), I think this possibility of the url would be only for some MDP client.

Just now i added the ytmusic extension (youtube music) to my mopidy and it works well with its integration, with that i think the question of compatibility with youtube would be “solved”.

1 Like

No, this behaviour is Iris, as I cannot see anything like that on the MPD API.
My guess is, Iris detects it’s a youtube URL, prepends it with yt: and then plays it.

Hi @Felipe_Messias
the Hass front end is in no way the Iris interface, but I have attempted to provide similar functionality in the platform.
the play_media service will now attempt to guess what type it is and act accordingly if it is not properly formatted the way Mopidy expects it to be.
So if your media_content_id is ‘https://www.youtube.com/watch?v=iVvXB-Vwnco’ it will automatically prepend it with yt:

example:
You have an empty input_text called media_uri, and a mopidy player called test

automation:

- alias: play_music
  mode: single
  trigger:
  - platform: state
    entity_id: input_text.media_uri
  condition:
  - condition: template
    value_template: '{{ states("input_text.media_uri") != "" }}'
  action:
  - service: media_player.play_media
    entity_id: media_player.test
    data:
      media_content_id: '{{ states("input_text.media_uri") }}'
      media_content_type: music
  - service: input_text.set_value
    entity_id: input_text.media_uri
    data:
      value: ''

Create a entity card linked to input_text.media_uri

When changing the state of input_text.media_uri (to a YouTube url) you will trigger the Mopidy platform to play that music video.

Obviously, when entering a valid Mopidy URI, this will also be played correctly.

Pull the latest version of my git project to get this change.

Have a great week-end!

1 Like