This is my first Blueprint, but I found this automation simple but very helpful.
What does it do?
Whenever any Assist_satellite entity changes to “listening”, the volume of a different media_player in that same room will be lowered.
When the satellite returns to the idle state (or after 30 seconds) the volume level will be restored on the media_player.
How to set it up?
Just add the blueprint to your installation. No further setup or settings are required.
How does it work?
- The trigger is a template looking for any assist_satellite entity with the state ‘listening’. When the amount changes above 0, the automation triggers.
- HA delivers the entity_id, which will be used to search for other media_players in the entity’s room that are in the playing state. If the satellite has a media_player entity (like the HA Voice PE), it will exclude that media_player.
- The found media_player’s volume level will be lowered with a fixed amount (volume_level / 1.5).
- The automation will wait until the satellite changes back to idle (or time-out of 30 seconds).
- The volume will return back to its previous state (volume_level * 1.5).
Why won’t it work?
This only works for one (other) media_player in the room, besides the satellite (if that device has a media_player entity). So, when there are multiple media_players with the playing state in the same room, the automation will fail.
Updates
Version 1.1: Added condition so when a satellite and media_player are the same device, the volume won’t be ducked. This prevents assist response to be ducked.
The actual code:
---
blueprint:
name: Satellite Media Player volume ducking
description: >
This blueprint will duck the volume by a fixed percentage of a playing media_player entity when a Assist Satellite is activated in the same room.
The volume will be restored the volume to the previous level after the satellite returns to the idle state.
Version: 1.1
domain: automation
mode: single
trigger:
- alias: Assist Satellite listening
trigger: template
value_template: >-
{{ states.assist_satellite | selectattr('state','eq','listening') | map(attribute='entity_id') | join(', ') | count > 0}}
condition:
action:
- variables:
media_player: >-
{% set entities_in_area = area_entities(area_name(trigger.entity_id)) %}
{% set media_players = entities_in_area | select('search',
'media_player.') | list %} {% for entity_id in media_players %}
{% if states(entity_id) == "playing" and device_id(trigger.entity_id) != device_id(entity_id) %}
{{ entity_id }}
{% endif %}
{% endfor %}
- choose:
- conditions:
- condition: template
value_template: "{{ media_player != '' }}"
- condition: template
value_template: "{{ device_id(trigger.entity_id) != device_id(media_player) }}"
sequence:
- action: media_player.volume_set
metadata: {}
data:
volume_level: "{{ state_attr(media_player, 'volume_level') / 1.5}}"
target:
entity_id: "{{ media_player }}"
enabled: true
alias: Duck volume
- wait_template: "{{ states(trigger.entity_id) == 'idle' }}"
continue_on_timeout: true
timeout: "00:30:00"
alias: Wait for Satellite
- action: media_player.volume_set
metadata: {}
data:
volume_level: "{{ state_attr(media_player, 'volume_level') * 1.5}}"
target:
entity_id: "{{ media_player }}"
enabled: true
alias: Lift volume
alias: Media_player found
default:
- stop: No media_player found playing in the area