Media_player.turn_on and media_player.select_source

I want to create a script to turn on my receiver and select input Pandora. I've gotten this far but How/Where do I put        the line for Pandora? Note: this is for a Yamaha Receiver and the page does say "Other functions such as source select are in progress of being developed." but in the available services within home assistant there is a select source option. When/If it ever works I would still like to know how the script would work.
  sequence:
  - service: media_player.turn_on
    data:
      entity_id: media_player.receiver
  - delay:
      seconds: 5
  - service: media_player.select_source
    data:
      entity_id: entity_id: media_player.receiver
1 Like

I just got this to work with an automation, should be the same I think. Devices are a raspberry pi squeezeplayer (hoolio) and a Yamaha AV-Receiver RX-V479 (kitchen_avr)

From the action part at the end of my automation you should be able use this:-

## note - hoolio is the name of my squuezebox media player
alias: Hoolio begins playing 
trigger:
    - platform: state
      entity_id: media_player.hoolio
      to: 'playing'
      from: 'idle'
    - platform: state
      entity_id: media_player.hoolio
      to: 'playing'
      from: 'off'
action:
  - service: media_player.turn_on
    #change this to match your AVR
    entity_id: media_player.kitchen_avr
  - service: media_player.select_source
    data:
      #change this to match your AVR
      entity_id: media_player.kitchen_avr
      source: AV4

ā€œmedia_player.kitchen_avrā€ is the name of my receiver in HASS - the input on the reciever for my squeezeplayer named hoolio is ā€œAV4ā€ - the source. in data:

6 Likes

I canā€™t thank you enough BarryHampants, worked great!

2 Likes

You wouldnā€™t believe how much it pleases me to know I have finally helped someone else here instead of my usual leaching!

I should mention I also have the reverse of this set up in another automation - to turn the AVR off when playback has finished. No input source needed for switching off though.

4 Likes

Hi, I am still learning automation. FOr now I want just to press a switch/button and turn on AVR and put in the correct output.
How would I do that?

This below and then what?

action:
  - service: media_player.turn_on
    #change this to match your AVR
    entity_id: media_player.kitchen_avr
  - service: media_player.select_source
    data:
      #change this to match your AVR
      entity_id: media_player.kitchen_avr
      source: AV4

An automation needs at minimum a trigger and an action. You have the action so now you need a way to trigger it.

What is your switch/button device?

alias: claudio presses the button
    trigger:
      - platform: state
        entity_id: button.claudio_button
        to: 'on'
    action:
      - service: media_player.turn_on
        entity_id: media_player.kitchen_avr
      - service: media_player.select_source
        data:
          entity_id: media_player.kitchen_avr
          source: HDMI1
1 Like

I made a script with a sequence.

I am a newb, and have a long learning curve. Not yet there for triggers and automation

I saw your script, if you can do that you will find automations even easier. Automation is the basis of Home Automation.

Have a read. There are only two necessary parts to an automation, a trigger and an action.

Do you have a button device or switch?

What triggers your script?

You can make an automation now with the action.

action:
  - service: script.its_time_for_lunch

a click on the front-end. I got a amazon dash to test, nothing else as real switch though. I ordered some stuff (PIR sensors) but I donā€™t have them yet.

Ahh I have presence detection but its crap IMO, tried owntracks, gpslogger, netgear, all donā€™t work well. Very unreliable.
Trying to use ibeacon/bluetooth technology, but I am not there yet.

p.s. maybe with the new GPS Galileo system will work better, in Europe.

Ah - OK I misunderstood what you meant by button or switch.

I have the same problem with presence. For now I use an input boolean to prevent my welcome home routine running 10 times a night rather than just on the initial connection. I have given up on GPS.

I think the best is using bluetooth: the question is what to get as transmitter and receiver (and which to put ON you/perons of the family)

Have a similar problem.
I have a script up and running, turning my mediacenter with all components on, incl. correct source, etc.
My plan is to switch it on and of via webui and echo dot for now.
As for the script I just have an activate button.
For the first instance the eco dot that switches a emulated hue needs an on and off switch.
Perfect would be a activate button with if case bolean that switches between on and off for the web interface and a hidden on off switch for the echo dot :slight_smile:

I did see this post yesterday that may be what you are looking for?

Yeah thanks. Thats exactly what I wanted to do, but unfortunately it doesnt work for me. I get no errors and the switches/scripts are working but nothing happens when I change the bolean.

My working sllution is an automation:

input_boolean:
  watch_movie:
    name: Mediacenter
    initial: off

script:
  mediacenter_on:
    alias: mediacenter on
    sequence:
     - service: media_player.turn_on
       entity_id: 
        - media_player.avr_wohnzimmer
     - service: switch.turn_on
       entity_id:
        - switch.htpc
     - service: media_player.select_source
       data:
         entity_id: media_player.avr_wohnzimmer
         source: HTPC

  mediacenter_off:
    alias: mediacenter off
    sequence:
     - service: media_player.turn_off
       entity_id: 
        - media_player.avr_wohnzimmer
     - service: media_player.turn_off
       entity_id: 
        - media_player.kodi

automation:
  - alias: Start Makro Mediacenter
    trigger:
      platform: state
      entity_id: input_boolean.watch_movie
      from: 'off'
      to: 'on'
    action:
      service: script.turn_on
      entity_id: script.mediacenter_on

  - alias: Off Makro Mediacenter
    trigger:
      platform: state
      entity_id: input_boolean.watch_movie
      from: 'on'
      to: 'off'
    action:
      service: script.turn_on
      entity_id: script.mediacenter_off
1 Like

So just starting out myself, and i have found that a good restart of HASS works better than a reload/restart in the GUI.

Also spotted that in your script u have put you entity_id on a new line and stuck a - in front, but only on some of them.

I corrected how i think it should be.

script:
  mediacenter_on:
    alias: mediacenter on
    sequence:
      - service: media_player.turn_on
        entity_id: 
          - media_player.avr_wohnzimmer
      - service: switch.turn_on
         entity_id:
          - switch.htpc
      - service: media_player.select_source
         data:
           entity_id: media_player.avr_wohnzimmer
           source: HTPC
    mediacenter_off:
      alias: mediacenter off
      sequence:
       - service: media_player.turn_off
         entity_id: 
          - media_player.avr_wohnzimmer
       - service: media_player.turn_off
         entity_id: 
          - media_player.kodi

I hope this helps as iā€™ve just spent an age looking at whether i needed to - my

Hmmm that might still not be copy and pasta ready, but if u look iā€™ve not got the entity_id on a new line

I need some helpā€¦ I want to make a script which checks if both TVs are off, if yes it turns on one of them and then check which one is open and changes the source. I have the code below. If I uncomment the commented part of the script it works only when both TVs are off. If one of them is turned on it gives me this error. Any ideas? The code is below

Entity ID is an invalid entity id for dictionary value @ data[ā€˜entity_idā€™]

  netflix:
      alias: Netflix Script
      sequence:
#      - service: media_player.turn_on
#        data_template:
#            entity_id: >-
#                {% if (states('media_player.bedroom_tv') == 'off') and (states('media_player.living_room_tv') == 'off') %}
#                    media_player.living_room_tv
#                {% endif %}
      - service: media_player.select_source
        data_template:
            entity_id: >
                {% if (states('media_player.bedroom_tv') == 'on') %}
                    media_player.bedroom_tv
                {% elif (states('media_player.living_room_tv') == 'on') %}
                    media_player.living_room_tv
                {% endif %}
            source: Netflix```

Hi. You have if and elif but no else.
If both ifs are false thereā€™s no default and so no entity_id thatā€™s valid.
Test it in your template dev tool.

Yes but I donā€™t think that this is the caseā€¦ What I mean, if I have both TVs off and run the script (with the commented part) the TV turns on and then it changes the sourceā€¦ If i run the script second time with one of the TVs already on is when i get the error. I will try what you are saying when i will be at home and i will tell you the results.

Do you know if/how i can put the commented part to run in the ā€œelseā€ statement? So first it will check if any of the TVs are open and then turn on one