#Lower Volume on tv upon Wake Word Detection

1 messages · Page 1 of 1 (latest)

ashen thorn
#

I have a box3 in the LR and the majority of the time when i speak to it, it will gather words from the tv aswell. Is there a way to lower the volume on the tv when the wake word is detected for however many seconds? This is one area alexa has figured out pretty good and i haven't gone really deep in voice assistant as some others have so i am sure there has to be a way to make it more accurate to my voice or if anyone knows how to do this via a script. I tried finding ways online but not really getting anywhere.

hearty grove
upbeat spear
#

here are the 2 automations I use for that

alias: Lower Volume When Echo_1 is Listening
triggers:
  - entity_id: assist_satellite.echo_1_assist_satellite
    to: listening
    trigger: state
actions:
  - target:
      entity_id: input_number.saved_volume
    data:
      value: |
        {{ state_attr('media_player.hifiberry_2', 'volume_level') }}
    action: input_number.set_value
  - target:
      entity_id: media_player.hifiberry_2
    data:
      volume_level: 0.3
    action: media_player.volume_set
mode: single
alias: Restore Volume When Echo_1 Stops Listening
description: ""
triggers:
  - entity_id:
      - assist_satellite.echo_1_assist_satellite
    to: idle
    trigger: state
actions:
  - target:
      entity_id: media_player.hifiberry_2
    data:
      volume_level: |
        {{ states('input_number.saved_volume') | float }}
    action: media_player.volume_set
mode: single

In this case I have a input_number called saved_volume

ashen thorn
#

Ty I'm going to try that!

olive drift
hearty grove
#

I vent a bit further and made it working for all players that are playing in corresponding area. Unfortunately, there's no way to define universal trigger, but everything else works great:

alias: Adjust area players volume while assist in progress
description: ""
triggers:
  - trigger: state
    entity_id:
      - assist_satellite.respeaker_satellite_1_assist_satellite
      - assist_satellite.respeaker_satellite_2_assist_satellite
      - assist_satellite.respeaker_satellite_3_assist_satellite
      - assist_satellite.respeaker_satellite_4_assist_satellite
      - assist_satellite.s3_box_assist_satellite
    to: listening
actions:
  - variables:
      v_players: |-
        {{ states.media_player|selectattr('state', '==', 'playing')
        |selectattr('attributes.volume_level', 'defined')
        |map(attribute='entity_id')
        |select('in', area_entities(area_id(trigger.entity_id)))
        |reject('in', device_entities(device_id(trigger.entity_id)))
        |list }}
      v_volumes: |-
        {% set vol = namespace(umes = []) %}
        {% for i in v_players %}
          {% set vol.umes = vol.umes + [{'id':i, 'volume':state_attr(i, 'volume_level') }] %}
        {% endfor %}
        {{ vol.umes }}
  - action: media_player.volume_set
    metadata: {}
    data:
      volume_level: 0.2
    target:
      entity_id: "{{ v_players }}"
  - wait_for_trigger:
      - trigger: template
        value_template: "{{ is_state(trigger.entity_id, 'idle') }}"
    timeout:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - repeat:
      sequence:
        - action: media_player.volume_set
          metadata: {}
          data:
            volume_level: "{{ repeat.item.volume }}"
          target:
            entity_id: "{{ repeat.item.id }}"
      for_each: "{{ v_volumes }}"
mode: parallel
max: 10
olive drift
#

Does this new one replace the two previous ones?

hearty grove
#

@olive drift It's two different approaches from two different people. 🙂

upbeat spear
#

That's very cool @hearty grove I thought about doing the are thing. But I only have one media_player on mine 😂
I usually avoid using complex templates, I just find they so hard to ready
I like the usage of the wait_for_trigger instead of 2 automations... I will think about how to incorporate that!!
great stuff

hearty grove
ashen thorn
#

Works like a charm. So now that it works, i'm thinking about something more complex ofc. So i have a sonos speaker i use for tts for automations. Is there a way to have the same thing happen when a tts is played or would i have to enter this for each automation that uses it

hearty grove
# ashen thorn Works like a charm. So now that it works, i'm thinking about something more comp...

You can create script, that has this logic and sends TTS. Then use it everywhere...

Because unless there's difference in state of media_player during TTS, you can't determine if it's TTS (so lower volume) or other type of sound...

Check the Dev tools while TTS is speaking - probably there's current URL or something similar in media_player, that will help you distinguish between TTS and music..

ashen thorn
#

thats what i was afraid of lol.