Additional integrations for Home Assistant
This is a platform integration for Mopidy Music Servers
Please look at the Mopidy installation & configuration instructions to set up a Mopidy Server.
- Install HACS
- Go to any of the sections (integrations, frontend, automation).
- Click on the 3 dots in the top right corner.
- Select "Custom repositories"
- Add the URL to the repository.
- Select the correct category.
- Click the "ADD" button.
- Go to Home Assistant settings -> Integrations and add Mopidy
- Restart HA
- Clone this repository
- Copy
custom_components/mopidy
to your Home Assistant instance on<config dir>/custom_components/
Your Mopidy Servers can be detected and added to Home Assistant through zeroconf.
- Go to the Integrations page and click + ADD INTEGRATION
- Select Mopidy in the list of integrations
- Fill out the requested information. Make sure to enter your correct FQDN or IP address. Using
localhost
,127.0.0.1
,::1
or any other loopback address will disable Mopidy-Local artwork. - Click Submit.
Repeat the above steps to add more Mopidy Server instances.
- add a media player to your home assistant configuration (
<config dir>/configuration.yaml
):
media_player:
- name: <mopidy identifier>
host: <FQDN or IP address>
port: <port if different from 6680>
platform: mopidy
- Restart your Home assistant to make changes take effect.
- name: <mopidy name> # The name of your Mopidy server.
host: <fqdn/ip address> # The FQDN or IP address of your Mopidy Server, do not use ::1, localhost or 127.0.0.1
port: <port number> # The port number of the Mopidy Server, default: 6680
platform: mopidy # specify mopidy platform
This service was originally developed by Daniele Ricci
Search media based on keywords and return them for use in a script or automation.
Note: One of the keyword fields must be used: keyword
, keyword_album
, keyword_artist
, keyword_genre
or keyword_track_name
Service data attribute | Optional | Description | Example |
---|---|---|---|
entity_id |
no | String or list of entity_id s to search and return the result to. |
|
exact |
yes | String. Should the search be an exact match | false |
keyword |
yes | String. The keywords to search for. Will search all track fields. | Everlong |
keyword_album |
yes | String. The keywords to search for in album titles. | From Mars to Sirius |
keyword_artist |
yes | String. The keywords to search for in artists. | Queens of the Stoneage |
keyword_genre |
yes | String. The keywords to search for in genres. | rock |
keyword_track_name |
yes | String. The keywords to search for in track names. | Lazarus |
source |
yes | String. URI sources to search. local , spotify and tunein are the only supported options. Make sure to have these extensions enabled on your Mopidy Server! Separate multiple sources with a comma (,). |
local,spotify |
The service is to be used as a normal service returning some data into a variable. The result is actually a dictionary
with keys corresponding to the media player entities used as targets in the service call. Every item has in turn a
result
attribute containing the list of actual media IDs matching the search parameters.
script:
search_and_play_music:
fields:
[...]
sequence:
- action: mopidy.get_search_result
data:
keyword_artist: "Some music artist"
keyword_track_name: "Some song title"
source: local
target:
entity_id: "media_player.music"
response_variable: music_tracks # result will be returned into this variable
- if: "{{ music_tracks['media_player.music'].result|length > 0 }}"
then:
- action: media_player.play_media
data:
media_content_id: "{{ music_tracks['media_player.music'].result[0] }}"
media_content_type: music
target:
entity_id: "media_player.music"
The media_content_id
needs to be formatted according to the Mopidy URI scheme. These can be easily found using the Developer tools.
When using the play_media
service, the Mopidy Media Player platform will attempt to discover your URL when not properly formatted.
Currently supported for:
- Youtube
Restore a previously taken snapshot of one or more Mopidy Servers
The playing queue is snapshotted
Service data attribute | Optional | Description |
---|---|---|
entity_id |
no | String or list of entity_id s that should have their snapshot restored. |
Search media based on keywords and add them to the queue. This service does not replace the queue, nor does it start playing the queue. This can be achieved through the use of media_player.clear_playlist and media_player.media_play
Note: One of the keyword fields must be used: keyword
, keyword_album
, keyword_artist
, keyword_genre
or keyword_track_name
Service data attribute | Optional | Description | Example |
---|---|---|---|
entity_id |
no | String or list of entity_id s to search and return the result to. |
|
exact |
yes | String. Should the search be an exact match | false |
keyword |
yes | String. The keywords to search for. Will search all track fields. | Everlong |
keyword_album |
yes | String. The keywords to search for in album titles. | From Mars to Sirius |
keyword_artist |
yes | String. The keywords to search for in artists. | Queens of the Stoneage |
keyword_genre |
yes | String. The keywords to search for in genres. | rock |
keyword_track_name |
yes | String. The keywords to search for in track names. | Lazarus |
source |
yes | String. URI sources to search. local , spotify and tunein are the only supported options. Make sure to have these extensions enabled on your Mopidy Server! Separate multiple sources with a comma (,). |
local,spotify |
Set the mopidy consume mode for the specified entity
Service data attribute | Optional | Description |
---|---|---|
entity_id |
no | String or list of entity_id s to set the consume mode of. |
consume_mode |
no | True to enable consume mode, False to disable |
Take a snapshot of what is currently playing on one or more Mopidy Servers. This service, and the following one, are useful if you want to play a doorbell or notification sound and resume playback afterwards.
Warning: This service is controlled by the platform, this is not a built-in function of Mopidy Server! Restarting Home Assistant will cause the snapshot to be lost.
Service data attribute | Optional | Description |
---|---|---|
entity_id |
no | String or list of entity_id s ito take a snapshot of. |
Due to the nature of the way Mopidy provides thumbnails of the media, proxying them through Home Assistant is very resource intensive, causing delays. Therefore, I have decided to not proxy the art when using the Media Library for the time being.