Media player dropdown list to change sources

I have a Denon AVR and I would like to have dropdown list cards to change the source and sound mode, exactly like you see when you click on the device, except that I want these to be shown directly on the main page without having to click the device. Ideally, I would also like to use “friendly names” for the sound modes, e.g. Multichannel Stereo instead of MCH STEREO. I’d appreciate any tips on how to accomplish this.

I started by creating dropdown list helpers for source and sound mode and added them to an Entities card, so now it looks good but it’s not functional.

I could create 2 separate automatons for each dropdown. One that triggers on the state of the helper, and the other that triggers on the AVR sound mode change. Is this the right way to go? It feels overly complicated, and I’m also not sure how to avoid an endless loop.

I learned a little about templating and I came up with the following 3 automations to make this work. The first 2 automations change the AVR state in response to the changed state of input_select. The third one updates the input_select to show the correct value in case the AVR is changed by the IR remote.

I haven’t yet figured out how to use friendly names.

- id: '1668888197337'
  alias: Denon AVR - change sound mode
  description: in response to input_select
  trigger:
  - platform: state
    entity_id: input_select.denon_avr_sound_modes
  action:
  - service: media_player.select_sound_mode
    data:
      sound_mode: '{{ trigger.to_state.state }}'
    target:
      entity_id: media_player.denon_avr_s750h
  mode: single

- id: '1668891256897'
  alias: Denon AVR - change source
  description: in response to input_select
  trigger:
  - platform: state
    entity_id:
    - input_select.denon_avr_sources
  condition: []
  action:
  - service: media_player.select_source
    data:
      source: '{{ trigger.to_state.state }}'
    target:
      entity_id: media_player.denon_avr_s750h
  mode: single

- id: '1668891405700'
  alias: Denon AVR - respond to changed state
  trigger:
  - platform: state
    entity_id:
    - media_player.denon_avr_s750h
  action:
  - service: input_select.select_option
    data:
      option: '{{trigger.to_state.attributes.source}}'
    target:
      entity_id: input_select.denon_avr_sources
  - service: input_select.select_option
    data:
      option: '{{trigger.to_state.attributes.sound_mode}}'
    target:
      entity_id: input_select.denon_avr_sound_modes
  mode: single
1 Like

I’m using friendly names by configuring the friendly names in the input_select and transforming them in the automation. For example like this where TV and Chromecast are the friendly names:

alias: Denon input
description: ""
trigger:
  - platform: state
    entity_id:
      - input_select.denon_input
condition: []
action:
  - service: media_player.select_source
    data:
      source: >
        {{'MEDIA PLAYER' if is_state('input_select.denon_input', 'Chromecast')}} 
        {{'CBL/SAT' if is_state('input_select.denon_input', 'TV')}}
    target:
      entity_id: media_player.denon_avr_x4000
mode: single

1 Like

Thanks a lot for these automations. My problem is that my Marantz SR6010 sends an input-request without content and the third automations tries to respond the (log)result looks like this:

 params:
   domain: input_select
   service: select_option
   service_data:
     option: ''
     entity_id:
       - input_select.denon_input
   target:
     entity_id:
       - input_select.denon_input
 running_script: false
Error: Invalid option: (possible options: TV, PlayStation, Bluetooth, Platte, Blu-ray, CBL/SAT, Media Player, Media Server, Online Music, Internet Radio, Favorites, Phono, Spotify, Tuner, AUX1, AUX2, iPod/USB, DVD, '', )

In result the AV-Receiver turns off.

As you can see I already tried to include the requested option ( ‘’, ) but this doesn’t work

I also tried to filter the Input

 condition: template
 value_template: '{{ (trigger.to_state.attributes.source) != "''''" }}'

But this doesn’t work ether. Is there somebody with the same problem/a solution?

It is not a string containing quotes, it is an empty string with the quotes only there to indicate that there is a string at all.

I wasn’t sure about this but I already thought this. Do you have a solution? - how can I check if the string is empty and just execute the script if it isn’t?

{{ trigger.to_state.attributes.source != '' }}

or

{{ trigger.to_state.attributes.source | length != 0 }}

or

{{ not trigger.to_state.attributes.source }}

thanks a lot! I there a difference between these solutions?

Semantically, yes. Practically, if the value of source is guaranteed to always be a string, then no there shouldn’t be any difference.

If it were not always a string behavior could differ. If for example none was returned rather than an empty string, then the first and last expression would evaluate as true (which you would not want), while the second would fail with an error as you cannot get a length of none.

thank you so much - I recognized that it would be much elegant to check whether the content of the variable is part of input select options. Is there a way to check this?

Use the in keyword/test. It will match on list items and dict keys. If you need to match on dict values, combine with the values() function.

{{ 'x' in ['x', 'y'] }}
{{ 'x' in {'x': 1, 'y': 2} }}
{{ 'x' in {'a': 'x', 'b': 'y'}.values() }}

https://jinja.palletsprojects.com/en/stable/templates/#jinja-tests.in

Ok, I could figure out that there is a problem when changing the

input_select.denon_avr_sources

by an automation.

This is my automation:

alias: MediaInput-Wohnzimmer
description: ""
triggers:
  - trigger: state
    entity_id:
      - input_select.mediainput
    enabled: true
conditions: []
actions:
  - choose:
      - conditions:
          - condition: state
            entity_id: input_select.mediainput
            state: TV
        sequence:
          - action: script.steckdose_mediainput_wohnzimmer
            data: {}
            enabled: true
          - wait_template: "{{ states.script.steckdose_mediainput_wohnzimmer.state == \"off\"}}"
            continue_on_timeout: true
          - device_id: ba0d5c6827f49928de3cbf896851bc9e
            domain: select
            entity_id: 90e7ad939e9a2915e39391fdfb845bd6
            type: select_option
            option: TV-Ein
          - action: input_select.select_option
            metadata: {}
            data:
              option: TV
            target:
              entity_id: input_select.denon_input
          - wait_for_trigger:
              - entity_id:
                  - switch.tv_pini_screen_state
                to: "on"
                trigger: state
          - delay:
              hours: 0
              minutes: 0
              seconds: 1
              milliseconds: 500
          - action: media_player.play_media
            metadata:
              title: Das Erste HD
              thumbnail: null
              media_class: channel
              children_media_class: null
              navigateIds:
                - {}
                - media_content_type: channels
                  media_content_id: favorite_lists
                - media_content_type: channels
                  media_content_id: favorites/1
            data:
              media_content_id: 1/4641
              media_content_type: channel
            target:
              entity_id: media_player.tv_pini
          - action: script.ps4_herunterfahren
            metadata: {}
            data: {}
      - conditions:
          - condition: state
            entity_id: input_select.mediainput
            state: Bluetooth
        sequence:
          - action: script.steckdose_mediainput_wohnzimmer
            data: {}
            enabled: true
          - wait_template: "{{ states.script.steckdose_mediainput_wohnzimmer.state == \"off\"}}"
            continue_on_timeout: false
          - action: input_select.select_option
            metadata: {}
            data:
              option: Bluetooth
            target:
              entity_id: input_select.denon_input
            enabled: true
          - action: denonavr.get_command
            target:
              entity_id: media_player.marantz_sr6010
            data:
              command: /goform/formiPhoneAppDirect.xml?SIBT
            enabled: false
          - action: denonavr.get_command
            target:
              entity_id: media_player.marantz_sr6010
            data:
              command: /goform/formiPhoneAppDirect.xml?PWON
          - device_id: ba0d5c6827f49928de3cbf896851bc9e
            domain: select
            entity_id: 90e7ad939e9a2915e39391fdfb845bd6
            type: select_option
            option: power_off
          - action: script.ps4_herunterfahren
            metadata: {}
            data: {}
      - conditions:
          - condition: state
            entity_id: input_select.mediainput
            state: PS4
        sequence:
          - action: script.steckdose_mediainput_wohnzimmer
            data: {}
            enabled: true
          - wait_template: "{{ states.script.steckdose_mediainput_wohnzimmer.state == \"off\"}}"
            continue_on_timeout: true
          - action: script.ps4_start
            metadata: {}
            data: {}
          - device_id: ba0d5c6827f49928de3cbf896851bc9e
            domain: select
            entity_id: 90e7ad939e9a2915e39391fdfb845bd6
            type: select_option
            option: TV-Ein
          - action: input_select.select_option
            metadata: {}
            data:
              option: PlayStation
            target:
              entity_id: input_select.denon_input
      - conditions:
          - condition: state
            entity_id: input_select.mediainput
            state: Plattenspieler
        sequence:
          - action: script.steckdose_mediainput_wohnzimmer
            data: {}
            enabled: true
          - wait_template: "{{ states.script.steckdose_mediainput_wohnzimmer.state == \"off\"}}"
            continue_on_timeout: false
          - action: input_select.select_option
            metadata: {}
            data:
              option: Platte
            target:
              entity_id: input_select.denon_input
          - action: script.ps4_herunterfahren
            metadata: {}
            data: {}
          - device_id: ba0d5c6827f49928de3cbf896851bc9e
            domain: select
            entity_id: 90e7ad939e9a2915e39391fdfb845bd6
            type: select_option
            option: power_off
      - conditions:
          - condition: state
            entity_id: input_select.mediainput
            state: Wohnzimmer
        sequence:
          - action: script.ps4_herunterfahren
            metadata: {}
            data: {}
          - device_id: ba0d5c6827f49928de3cbf896851bc9e
            domain: select
            entity_id: 90e7ad939e9a2915e39391fdfb845bd6
            type: select_option
            option: power_off
          - action: media_player.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: media_player.marantz_sr6010
          - alias: Steckdose Fernseher
            if:
              - condition: state
                entity_id: sun.sun
                state: below_horizon
            then:
              - wait_for_trigger:
                  - device_id: a8b43b179a81383a38e6049e8149d1aa
                    domain: media_player
                    entity_id: media_player.tv_pini
                    type: turned_off
                    trigger: device
                enabled: false
              - wait_template: "{{ states.media_player.tv_pini.state == \"off\"}}"
                continue_on_timeout: true
              - wait_template: "{{ states.media_player.marantz_sr6010.state == \"off\"}}"
                continue_on_timeout: true
              - delay:
                  hours: 0
                  minutes: 0
                  seconds: 3
              - type: turn_off
                device_id: f78164215de1ab644eae29c6de83c29e
                entity_id: switch.steckdose_03
                domain: switch
mode: restart

The action

action: input_select.select_option
            metadata: {}
            data:
              option: Bluetooth
            target:
              entity_id: input_select.denon_input

results in these two logs:

The second one is filtered because of the empty option and after this the receiver turns off. This is strange because when I execute this code

action: input_select.select_option
            metadata: {}
            data:
              option: Bluetooth
            target:
              entity_id: input_select.denon_input

within the developer tools it works all fine.

Is there anybody knowing this problem?

Is there noone having the same problem?

Look in the traces for the automation for clues to what is going on, and/or in the logs.

If you need more help, provide whatever your screenshot is supposed to show in English. Not many here who can be arsed to try and feed a screenshot into Google translate I would wager…

Thanks for your reply, next time I’ll try to send the screenshot in English. I tried to get some more information by looking at the trace of the automations named in the log. But I have no idea why the receiver is shutting down. I just user the automation “MediaInput-Wohnzimmer” to set the input select of the receiver and the rest is done by the automation of llamafilm Elliott Balsley. I can’t find any power-off-command. Is there a way to get all information home assistant logs (log, traces…) in a document so that I can search in there? Or does anybody know if the receiver logs incoming commands? - Maybe the receiver is broken?