Consuming switch from configuration.yaml in front end

I have been beating my head against the wall trying to figure this out today. Goes without saying that Iā€™m extremely new to this and appreciate any help :sweat_smile:

Coming from Change and highlight input source on AV Receiver - #3 by AdmiralRaccoon I have been trying to get a button to switch sources on my Lovelace dashboard. So far I have the following in configuration.yaml:

media_player:
  - platform: yamaha_musiccast
    host: 192.168.0.44
    source_names:
        HDMI1: "Chromecast"
        AUDIO1: "TV Audio"

switch:
- platform: template
  switches:
      # TV Audio Source
      tv_audio_source:
        value_template: "{{ is_state_attr('media_player.yamaha_receiver', 'source', 'TV Audio') }}"
        turn_on:
          - service: media_player.select_source
            data:
              entity_id: media_player.yamaha_receiver
              source: TV Audio
        turn_off:
          - service: media_player.select_source
            data:
              entity_id: media_player.yamaha_receiver
              source: TV Audio

I cannot for the life of me figure out how to call this on the front end via a button on my dashboard.

As a completely separate attempt to do the exact same thing I have also tried the following with no success.

Getting discouraged that something that seems so simple just does not seem to work no matter what I do. Is there something obvious that I am missing? Is there a better way to be doing this? Thanks all!

Are you sure the source is called AUDIO1? Take a look at the attributes in the states portion in developer tools. Works for me with this yaml defining the button

type: button
tap_action:
  action: call-service
  service: media_player.select_source
  service_data:
    source: TV Audio
  target:
    entity_id: media_player.family_room_amp
entity: media_player.family_room_amp
icon_height: 50px

This did it for me! I had it as uppercase, but according to developer tools => states, it needed to be lower case. Thanks @nickrout this is a real confidence booster :fist_right: :fist_left:

1 Like