I am using the universal media player integration to control an AmpliPi. I have defined the state attribute of the ump with a template sensor.
When I click on “play” or “stop”, the state of the ump changes (as does the template sensor). However, when I select a different source, although the template sensor reflects the change, the state of the ump is not updated.
Is there a service that I should be calling to update the state of the ump?
sensory.yaml
- platform: template
sensors:
amplipi_state:
value_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 %}
media_player.yaml
- platform: universal
name: Test
children:
- media_player.office
- media_player.source_2
commands:
select_source:
service: script.amplipi_change_source
data_template:
source: "{{ source }}"
attributes:
is_volume_muted: media_player.office|is_volume_muted
state: sensor.amplipi_state
source: input_select.amplipi_sources
source_list: input_select.amplipi_sources|options
volume_level: media_player.office|volume_level
scripts.yaml
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: media_player.office
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' }}