AV receiver state condition

Hi all,
just a simple question , i try to add in the mini media player card some buttons in order to change source , but i need to add a condition which state : if the av is on change the source to the one selected otherwise wait 10 sec(the av is turning on) and then change the source.
The following is working great , but i would avoid to wait always 10 sec to change source if the av is already on

entity: media_player.denon
hide_when_off: false
hide: name
shortcuts:
  buttons:
    - icon: 'mdi:kodi'
      id: script.denon1_kodi
      type: script
    - icon: 'mdi:bluetooth'
      id: script.denon1_bluetooth
      type: script
    - data:
        entity_id: switch.TV_Audio
      icon: 'mdi:television'
      id: script.denon1_tv
      type: script
    - data:
        entity_id: switch.internet_radio
      icon: 'mdi:radio-tower'
      id: script.denon1_internet_radio
      type: script
  columns: 4
type: 'custom:mini-media-player'


and the script

  denon1_internet_radio:
    sequence:
      - service: media_player.turn_on
        data:
          entity_id: media_player.denon  
      - delay: '00:00:10'           
      - service: media_player.select_source
        data:
          entity_id: media_player.denon
          source: 'Internet Radio'      

thanks

Except Home Assistant currently doesn’t know when the av is truly on. For example, if it is off and you use this to turn it on:

      - service: media_player.turn_on
        data:
          entity_id: media_player.denon  

The state of media_player.denon will now be on but, as you know, the physical device is not truly on and requires several seconds (10) before it’s fully operational and ready to accept commands.

What I suggest is to create an input_boolean that represents the true state of the Denon player.

input_boolean:
   denon_status:
     name: Denon Status

Create two automations. The first one turns on input_boolean.denon_status when media_player.denon is on for at least 10 seconds.

- alias: 'Denon player on'
  trigger:
    - platform: state
      entity_id: media_player.denon
      to: 'on'
      for: '00:00:10'
  action:
    service: input_boolean.turn_on
    entity_id: input_boolean.denon_status

The second automation simply turns off input_boolean.denon_status when media_player.denon is off

- alias: 'Denon player off'
  trigger:
    - platform: state
      entity_id: media_player.denon
      to: 'off'
  action:
    service: input_boolean.turn_off
    entity_id: input_boolean.denon_status

Now your script can use wait_template instead of delay.

  denon1_internet_radio:
    sequence:
      - service: media_player.turn_on
        data:
          entity_id: media_player.denon  
      - wait_template: "{{ is_state('input_boolean.denon_status', 'on') }}"     
      - service: media_player.select_source
        data:
          entity_id: media_player.denon
          source: 'Internet Radio'