Let me first outline the situation and tell you that I’m rather new to HA. I have 5 Sonos devices where I want to select some to join them and send a broadcast message to. This broadcast message is an attention sound (mp3) and a text to speech message after the attention. After this is played the grouped Sonos devices should unjoin, and if they were playing some music, continue to play music.
I encounter several issues in my script (the script is executed by pressing a button card)
- The script only runs once
- The text to speech message does not play (that piece of code is working when running on its own)
- The sonos speakers are not unjoined
- Is it possible to have no master Sonos or just use the first one from the array {{ players[0] }}
Could someone please point me in the right direction, I think there is something wrong with the wait trigger, but if I’m not using it the mp3 is not played till the end. I also think the text to speech could not handle grouped devices.
testcombine:
alias: testCombine
sequence:
- variables:
players: >
{{ [] + (['media_player.badkamer'] if is_state('input_boolean.bsonosbadkamer', 'on') else []) +
(['media_player.studeerkamer'] if is_state('input_boolean.bsonosstudeerkamer', 'on') else []) +
(['media_player.sonoskeuken'] if is_state('input_boolean.bsonoskeuken', 'on') else []) +
(['media_player.draagbaar'] if is_state('input_boolean.bsonosdraagbaar', 'on') else []) +
(['media_player.woonkamer_2'] if is_state('input_boolean.bsonosliving', 'on') else []) }}
- condition: "{{ players | count > 0 }}"
# save state and join
- service: sonos.snapshot
data_template:
entity_id: "{{ players }}"
- service: media_player.join
data:
group_members: "{{ players }}"
target:
entity_id: media_player.draagbaar
# set volume
- service: media_player.volume_set
data_template:
entity_id: "{{ players }}"
volume_level: '0.10'
# play attetion sound
- service: media_player.play_media
data_template:
entity_id: '{{ players }}'
media_content_id: 'http://192.168.0.221:8123/local/Airport.mp3'
media_content_type: music
# added this trigger otherwise it doesn't play the whole mp3
- wait_for_trigger:
- platform: state
entity_id: media_player.draagbaar #could not use the players array here or the first one?
from: playing
to: idle
# text to speech message - not executed works on its own
- service: tts.google_say
data_template:
entity_id: '{{ players }}'
message: 'This is a test to check if the grouping is working'
# wait 5 seconds to ungroup
- delay: 00:00:05
# unjoin and go to orioginal state - not executed/working
- service: media_player.unjoin
data:
group_members: "{{ players }}"
- service: sonos.restore
data_template:
entity_id: '{{ players }}'
mode: single