Hi there, I have tried to find an answer to this myself, but I’ve not found anything, so if it’s obvious, I apologize.
I’m new to Home Assistant in general, so it’s possible my whole approach is wrong.
I’m trying to set up my Voice PE to accept the command “Read my book” and have it resume my most recent book on Music Assistant (backed by Audiobookshelf)
I should mention that I can play the audiobook through the Music Assistant web ui to the voice PE just fine
Here’s my automation so far:
alias: Read My Book
description: Continue the last played Audio book from Music Assistant
triggers:
- trigger: conversation
command: Read my book
conditions: []
actions:
- action: music_assistant.get_library
metadata: {}
data:
media_type: audiobook
limit: 1
order_by: last_played_desc
config_entry_id: 01K7BQVKK6S2GKQK7MCF4EQFTH
response_variable: continue_book
- variables:
book_uri: >-
{{ continue_book['items'][0]['uri'] if continue_book and
continue_book['items']|length > 0 else none }}
trigger_device: "{{ trigger.device_id }}"
- choose:
- conditions:
- condition: template
value_template: "{{ book_uri is not none }}"
sequence:
- action: music_assistant.play_media
target:
entity_id: |-
{{ device_entities(trigger_device)
| select('search', '^media_player\.')
| list | first }}
data:
media_type: audiobook
media_id: "{{ book_uri }}"
enqueue: replace
default:
- action: assist_satellite.announce
metadata: {}
data:
message: Couldn't find a book to play
preannounce: true
target:
device_id: "{{ trigger_device }}"
mode: single
What’s working:
- The automation is triggered
- An audiobook is found
- The
play_mediaaction is reached - The correct media_player entity is being returned (matches the MA web ui at least)
What’s not:
- It’s just a random audio book, not the one listed under “Continue listening” in the web ui
- It’s not playing. There’s no errors in the
tracessection for the automation, and the voice PE says “done” but then nothing happens
I’ve been banging my head against this for a couple hours now and I’m sure I’m just missing something simple.
Any help would be appreciated
Cheers
UPDATE: I’ve gotten playback to work. Turns out the media player associated with the trigger device ID is the wrong one to use. I don’t fully grok why, and I’m not certain this explanation is correct: there is another one created by the music assistant integration that should be used instead?
Getting this working required going to Settings > Devices & services > Music Assistant ( under integrations ) → For each entry, view entities, and select the media player entity → Settings → Use device area to ON
Then I changed the entity id selector to:
entity_id: |-
{% set area = device_attr(trigger.device_id, 'area_id') %}
{{ area_entities(area)
| select('match', '^media_player\\.')
| reject('search', 'voice_.*_media_player$')
| select('search', 'home_assistant_.*_media_player$')
| list | first }}
Now I just need it to select the correct audio book