georgezhao2010 / apple_airplayer

Make your AirPlay devices as TTS speakers
MIT License
130 stars 17 forks source link

I can’t turn up the volume of Homepod #20

Open tylerd006 opened 2 years ago

tylerd006 commented 2 years ago

My homepod is far away from my room and I can’t turn up the volume. Is there a solution?

mate-b commented 2 years ago

Hi Tyler,

I found a workaround to turn up the volume on my HomePod mini. Just insert this script into Scripts.yaml which waits until the HomePod starts playing and it sets the desired volume (in this case 0.6 -> 60%).

script_set_homepod_volume:
  alias: Script - Set HomePod volume async
  sequence:
  - wait_for_trigger:
    - platform: device
      domain: media_player
      entity_id: media_player.living_room
      type: playing
    timeout: 00:01:00
    continue_on_timeout: false
  - service: media_player.volume_set
    target:
      entity_id: media_player.living_room
    data:
      volume_level: 0.6
  mode: single

Then you can call the script from any other automation or script using script.turn_on service right before you broadcast music or TTS to your device. For instance if you want to set the volume before TTS:

script_tts_on_homepod:
  alias: Script - Play TTS on HomePod
  sequence:
  - service: script.turn_on
    target:
      entity_id: script.script_set_homepod_volume
  - service: tts.google_translate_say
    data:
      entity_id: media_player.living_room
      language: en
      message: "my homepod is loud"
  mode: single

The key here is that you can only set the volume while the HomePod is playing. Scripts called from other automations or scripts are run asynchronous so this way you can do actions in parallel. Hope it can help.

gretel commented 2 years ago

@mate-b thanks!

Then you can call the script from any other automation or script using script.turn_on service right before you broadcast music or TTS to your device. For instance if you want to set the volume before TTS:

had to add device_id to make it work using recent hass:

alias: Script - Set HomePod volume async
sequence:
  - wait_for_trigger:
      - platform: device
        device_id: BedPod # <--
        domain: media_player
        entity_id: media_player.bedpod
        type: playing
    timeout: '00:01:00'
    continue_on_timeout: false
  - service: media_player.volume_set
    target:
      entity_id: media_player.bedpod
    data:
      volume_level: 0.6
mode: single