I have Music Assistant playing music and an automation to use “Text-To Speech (TTS) on piper” to send an announcement to the speaker on an event. That works.
However, Music Assistant doesn’t resume playing after the announcement and I can’t find the appropriate setting for this.
I’m using a Pi Zero with MPD installed. I get the impression, by the behaviour, that the playlist may have somehow been offloaded to the PI, because I had cause to reset HA and it not only kept playing, but it actually moved on to the next song.
OK … I’ve been searching and I’ve been finding scripts which have been giving various errors. Here’s one which I’ve managed to compile and at least triggers without errors… but it doesn’t reliably know if the music player is running, because it fails to trigger the else condition when the music isn’t playing…
- id: 20230210-23
alias: Speak the time in the kitchen at 11:30 am
description: ''
triggers:
- trigger: state
entity_id:
- input_boolean.notify_washing
from: 'off'
to: 'on'
conditions: []
actions:
- if:
- condition: state
entity_id: media_player.office_player
state: playing
then:
- data: {}
target:
entity_id: media_player.office_player
action: tts.speak
metadata: {}
data:
cache: true
media_player_entity_id: media_player.office_player
message: 'Music Player Was Running'
target:
entity_id: tts.piper
- wait_for_trigger:
- entity_id:
- media_player.office_player
to: idle
trigger: state
timeout:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- data: {}
target:
entity_id: media_player.office_player
action: media_player.media_play
- data: {}
action: tts.clear_cache
else:
action: tts.speak
metadata: {}
data:
cache: true
media_player_entity_id: media_player.office_player
message: 'Else condition triggered'
target:
entity_id: tts.piper
mode: single
The message “Music Player Was Running” is firing twice, indicating that I’ve still got a syntax problem and possibly part of the else condition maybe is still firing?
Either way, the player doesn’t restart playing after the announcement.
Getting there… I had errors in indentation and other things about my YAML formatting, but it seems that the “media_player.media_play” is responsible for the second firing of the speech. It seems that it’s lost the pointer to what it was previously playing and I need to find out how to capture that, and then re-point it before resuming play, somehow.
- id: 20230210-23
alias: Speak the time in the kitchen at 11:30 am
description: ''
triggers:
- trigger: state
entity_id:
- input_boolean.notify_washing
from: 'off'
to: 'on'
conditions: []
actions:
- if:
- condition: state
entity_id: media_player.office_player
state: playing
then:
- service: media_player.media_pause
data: {}
target:
entity_id: media_player.office_player
- action: tts.speak
metadata: {}
data:
cache: true
media_player_entity_id: media_player.office_player
message: 'Music Player Was Running'
target:
entity_id: tts.piper
- wait_for_trigger:
- entity_id:
- media_player.office_player
to: idle
trigger: state
timeout:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- service: media_player.media_play
data: {}
target:
entity_id: media_player.office_player
- data: {}
action: tts.clear_cache
else:
- action: tts.speak
metadata: {}
data:
cache: true
media_player_entity_id: media_player.office_player
message: 'Else condition triggered'
target:
entity_id: tts.piper
mode: single
Right - final script… which I’ve hashed together from other people’s scripts.
However - when running a playlist, which is what I do… it starts from the beginning of the playlist again. At my very beginner level, I’m at the limit of what I can steal from other people to solve this.