I wanted to share how I’m using HA’s universal media player (UMP) integration to enable better control of the AmpliPi from a couple of tablets I have around the house.
For background, I have 5 sets of ceiling/outdoor speakers that I have wired as Zones on the AmpliPi. I have created 4 sources: 2 streaming radio (CBC Radio 1 and CBC Music), Airplay and Spotify.
My goal was to create a WAF-friendly front-end player. To do this, I have used the mini-media-player from HACS which I think looks nicer.
Now, on to the code…
lovelace.yaml
In here I have specifically disabled the play_pause, next, previous, and power buttons as they don’t directly map to how AmpliPi works.
type: custom:mini-media-player
entity: media_player.test
artwork: cover
hide:
power: true
next: true
prev: true
play_pause: true
play_stop: false
progress: true
input_select.yaml
Here is where you can create family-friendly names for the sources you have defined through the AmpliPi web-interface. This is what will be displayed on the mini-media-player lovelace and when you select the source.
amplipi_sources:
options:
- CBC Radio 1
- CBC Music
- AirPlay
- Spotify
scripts.yaml
I cannot take credit for this, but reading through the forums of the HA community, I was able to piece this together. Essentially, it translates the family-friendly names of the sources defined above to the sources as listed by the AmpliPi HA integration.
amplipi_change_source:
sequence:
- service: input_select.select_option
data_template:
entity_id: input_select.amplipi_sources
option: "{{ source }}"
- service: media_player.select_source
data_template:
entity_id: "{{ mediaplayer }}"
source: >
{% set mapper = {
'CBC Radio 1': 'Source 1',
'CBC Music': 'Source 2',
'AirPlay': 'Source 3',
'Spotify': 'Source 4' } %}
{{ mapper[source] if source in mapper else 'Source 1' }}
media_player.yaml
Finally, the guts of everything. Here you define how commands are handled and which of the multiple AmpliPi integration media players they are sent to.
- platform: universal
name: Test
state_template: >
{% if is_state_attr('media_player.office', 'source', 'Source 1') %}
{{ states('media_player.source_1') }}
{% elif is_state_attr('media_player.office', 'source', 'Source 2') %}
{{ states('media_player.source_2') }}
{% elif is_state_attr('media_player.office', 'source', 'Source 3') %}
{{ states('media_player.source_3') }}
{% else %}
{{ states('media_player.source_4') }}
{% endif %}
children:
- media_player.office
- media_player.source_1
- media_player.source_2
- media_player.source_3
- media_player.source_4
commands:
media_play:
service: media_player.media_play
target:
entity_id: >
{% if is_state_attr('media_player.office', 'source', 'Source 1') %}
media_player.source_1
{% elif is_state_attr('media_player.office', 'source', 'Source 2') %}
media_player.source_2
{% elif is_state_attr('media_player.office', 'source', 'Source 3') %}
media_player.source_3
{% else %}
media_player.source_4
{% endif %}
media_stop:
service: media_player.media_stop
target:
entity_id: >
{% if is_state_attr('media_player.office', 'source', 'Source 1') %}
media_player.source_1
{% elif is_state_attr('media_player.office', 'source', 'Source 2') %}
media_player.source_2
{% elif is_state_attr('media_player.office', 'source', 'Source 3') %}
media_player.source_3
{% else %}
media_player.source_4
{% endif %}
select_source:
service: script.amplipi_change_source
data:
source: "{{ source }}"
mediaplayer: "media_player.office"
volume_up:
service: media_player.volume_up
target:
entity_id: media_player.office
volume_down:
service: media_player.volume_down
target:
entity_id: media_player.office
volume_mute:
service: media_player.volume_mute
data:
is_volume_muted: >
{% if is_state_attr('media_player.office', 'is_volume_muted', true) %}
false
{% else %}
true
{% endif %}
target:
entity_id: media_player.office
volume_set:
service: media_player.volume_set
data:
volume_level: "{{ volume_level }}"
target:
entity_id: media_player.office
attributes:
is_volume_muted: media_player.office|is_volume_muted
source: input_select.amplipi_sources
source_list: input_select.amplipi_sources|options
volume_level: media_player.office|volume_level
Hopefully this helps someone else…