I’ve run into what I think is a limitation with scripts and the Assist pipeline.
The whole goal I’m trying to accomplish is to write a HA script that a voice assistant can call, which will use Music Assistant to search for a track and play it on the device the request originated from (assuming the assist device has a companion media_player on the same device).
The core problem I’m having: I don’t see any way to identify the “source” of the script being run.
So if I have a script: script.my_script And this is invoked from a device like Voice PE, I get the following context:
From this, how can I determine what the source is? For example, I want to know that this script was invoked by assist_satellite.office and not assist_satellite.kitchen.
Hm, that could work - assuming that nobody queries their Voice PE device to play music at (roughly) the same time. I didn’t think of this, I’ll give it a try and report back if it works!
Sorry, I wasn’t specific. I’m using an LLM to call the script so I can use natural language. The Custom Sentence trigger on intents doesn’t fit my needs.
It works! For those wondering, here’s what you have to do:
Create an input_text helper.
Then add the following automation:
alias: Set Last Used Voice Device
description: ""
conditions: []
mode: single
triggers:
- trigger: state
to: listening
entity_id:
# Replace with the list of your voice assistants.
- assist_satellite.one
- assist_satellite.two
- assist_satellite.three
actions:
- action: input_text.set_value
target:
# Replace with your helper entity ID.
entity_id: input_text.last_queried_voice_entity_id
data:
# This template assumes you have an assist satellite and a
# media player with the same device name.
# Tweak to map your entities accordingly.
value: >-
{{ trigger.entity_id | replace('assist_satellite.', 'media_player.') |
replace('_assist_satellite', '_media_player') }}
To use in an action:
# In a service call / action:
target:
entity_id: "{{ states('input_text.your_last_used_assist_id_helper') }}"