#Voice PE automations (sometimes!) don't play sound effects at the correct volume

1 messages · Page 1 of 1 (latest)

vivid plaza
#

I've tried searching every combination of keywords I could think of online and in this forum, so forgive me if this is a trivial or already solved issue:

I am using my Voice PE to give me notifications for various events (when trash collection starts, when the laundry is finished, when the front door is opened, etc). For this purpose, I have set up two scripts, one to play an attention-grabbing sound effect and the other to announce the TTS message.

I often want to play these sounds at a different volume than what the Voice PE is usually set to, so in each of those scripts, I have an optional field that allows me to choose a volume to play at. The script will save the current media player's volume, set it to the volume I chose, play the sound effect/message, then set the volume back to its previous value.

Annoyingly, the volume that comes out of the Voice PE is not always the volume I set in the script. For example, I frequently set the sound effect to 100% and the announcement to 80%. When the automation runs, a few things could happen:

  1. Most of the time, the sound effect and announcement run at the correct volume.
  2. Sometimes, the sound effect will be pretty quiet, but the announcement is at the correct volume.
  3. Rarely, both the sound effect and the announcement play pretty quiet. Certainly quieter than what they're set to!

I added delays after the volume_set commands, thinking that maybe the WiFi communication between my HA instance and the Voice PE was a bit slow, but that didn't seem to fix it, even when I increased the delay to a massive two seconds.

What's also interesting is if I manually trigger the automation actions multiple times in a row, the first one usually has the bugged volume, but then the subsequent ones run fine.

This isn't the worst pain point in existence, but it is annoying that I can't rely on the notifications to do their job properly at all times. What am I missing to get this to work? I'll attach my scripts below.

#

Script: Play sound effect

sequence:
  - variables:
      prev_volume: >-
        {{ state_attr('media_player.home_assistant_voice_0944ca_media_player',
        'volume_level') }}
      volume_set_delay:
        milliseconds: 250
  - if:
      - condition: template
        value_template: "{{ volume is defined }}"
    then:
      - action: media_player.volume_set
        metadata: {}
        data:
          volume_level: "{{ volume }}"
        target:
          entity_id: media_player.home_assistant_voice_0944ca_media_player
      - delay: "{{ volume_set_delay }}"
  - action: media_player.play_media
    target:
      entity_id: media_player.home_assistant_voice_0944ca_media_player
    data:
      media_content_id: "{{ sound_effect.media_content_id }}"
      media_content_type: "{{ sound_effect.media_content_type }}"
  - wait_for_trigger:
      - trigger: state
        entity_id:
          - media_player.home_assistant_voice_0944ca_media_player
        to: idle
    timeout:
      hours: 0
      minutes: 0
      seconds: "{{ maximum_play_time }}"
      milliseconds: 0
  - action: media_player.media_stop
    metadata: {}
    data: {}
    target:
      entity_id: media_player.home_assistant_voice_0944ca_media_player
  - action: media_player.volume_set
    metadata: {}
    data:
      volume_level: "{{ prev_volume }}"
    target:
      entity_id: media_player.home_assistant_voice_0944ca_media_player
  - delay: "{{ volume_set_delay }}"
fields:
  sound_effect:
    selector:
      media: {}
    required: true
    name: Sound effect
    description: The sound to play.
    default:
      entity_id: media_player.home_assistant_voice_0944ca_media_player
      media_content_id: ""
      media_content_type: ""
  maximum_play_time:
    selector:
      number:
        min: 0.25
        max: 10
        step: 0.25
    name: Maximum play time
    description: The maximum number of seconds to let the sound effect play.
    default: 3
    required: true
  volume:
    selector:
      number:
        min: 0
        max: 1
        step: 0.1
    name: Volume
    description: Volume to play sound effect at.
    default: 0.8
    required: false
alias: Play sound effect
description: ""
icon: mdi:volume-source
#

Script: Have voice assistant say

sequence:
  - variables:
      prev_volume: >-
        {{ state_attr('media_player.home_assistant_voice_0944ca_media_player',
        'volume_level') }}
  - if:
      - condition: template
        value_template: "{{ volume is defined }}"
    then:
      - action: media_player.volume_set
        metadata: {}
        data:
          volume_level: "{{ volume }}"
        target:
          entity_id: media_player.home_assistant_voice_0944ca_media_player
      - delay:
          hours: 0
          minutes: 0
          seconds: 0
          milliseconds: 250
  - action: assist_satellite.announce
    data:
      message: "{{ message }}"
    target:
      device_id: 4b513dc908cbd8d08f04685f130ca640
  - action: media_player.volume_set
    metadata: {}
    data:
      volume_level: "{{ prev_volume }}"
    target:
      entity_id: media_player.home_assistant_voice_0944ca_media_player
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 250
alias: Have voice assistant say
fields:
  message:
    name: Message
    description: Content of the announcement.
    required: true
    selector:
      text: null
  volume:
    selector:
      number:
        min: 0
        max: 1
        step: 0.1
    name: Volume
    description: Volume to play the message at.
    required: false
    default: 0.8
description: ""
icon: mdi:assistant