Hello everyone.
I am trying to prepare a blueprint that I could reuse in my home automations. The goal is to announce things on my Sonos speakers, pausing and resuming playback if necessary and adjusting volume, so the announcement is not missed.
Here is my blueprint:
blueprint:
name: Voice announcement
domain: automation
input:
automation_trigger:
selector:
trigger:
automation_condition:
selector:
condition:
default:
player:
selector:
entity:
filter:
domain: media_player
announcement_language:
selector:
language:
announcement_text:
selector:
text:
multiline: true
type: text
triggers:
- triggers: !input automation_trigger
conditions: !input automation_condition
actions:
- variables:
player_entity: !input player
was_media_playing: "{{ is_state(player_entity, 'playing') }}"
player_volume_level: "{{ state_attr(player_entity, 'volume_level') }}"
- if:
- condition: template
value_template: '{{ was_media_playing }}'
then:
- target:
entity_id: !input player
action: media_player.media_pause
data: { }
- service: media_player.volume_set
target:
entity_id: !input player
data:
volume_level: 0.5 # Set volume to 50%
- wait_template: "{{ (state_attr(player_entity, 'volume_level') | float) | round(2) == 0.5 }}"
timeout: '00:00:05'
- delay: '00:00:02'
- action: tts.speak
metadata: { }
data:
cache: true
media_player_entity_id: !input player
message: !input announcement_text
language: !input announcement_language
target:
entity_id: tts.google_translate_en_com
- wait_template: "{{ is_state(player_entity, 'idle') }}"
timeout: '00:00:05'
- action: media_player.volume_set
target:
entity_id: !input player
data:
volume_level: "{{ player_volume_level | float }}"
- if:
- condition: template
value_template: '{{ was_media_playing }}'
then:
- target:
entity_id: !input player
action: media_player.media_play
data: { }
Which is run with the following configuration:
id: '1758630370323'
alias: Test
description: ''
use_blueprint:
path: oskar/announcement.yaml
input:
automation_trigger:
- type: occupied
device_id: 58e05c7b7d5df099a0e1f4a43190937c
entity_id: 4d9088878345b58844ae2d1599d223af
domain: binary_sensor
trigger: device
player: media_player.salon
announcement_language: pl
announcement_text: Testowy komunikat
However, no matter what I try I cannot get the volume setting to work.
Tracing shows the action being run, delays, even templated one, too but the resulting volume remains unchanged.
The action in development tools works perfectly though.
Am I missing something obvious here? Is there something specific to automations based on blueprint?