I’m attempting to use Intents for the first time with the following goal:
If “Turn On Apple TV” is stated within a specific room through an ESP32 voice assistant – I would like Home Assistant to identify which zone the voice assistant is coming from and respectively power on the tv/projector/device + switch the receiver zone output for the respective device + turn on the Apple TV in the server rack.
And the intent script to handle the incoming data is within my configuration.yaml:
intent_script:
AppleTVTurnOn:
action:
service: "script.turn_on_apple_tv"
data:
tv_media_player: "{{ tv_media_player }}"
media_player_zone: "{{ media_player_zone }}"
speech:
text: "Turned on the Apple TV, {{ tv_media_player }} and set to zone {{ media_player_zone }}"
The following script is contained within my Scripts:
alias: Turn On Apple TV
sequence:
- service: media_player.turn_on
target:
entity_id: "{{tv_media_player}}"
data: {}
- service: media_player.turn_on
metadata: {}
data: {}
target:
entity_id: "{{media_player_zone}}"
mode: parallel
fields:
tv_media_player:
selector:
entity:
multiple: false
name: TV Media Player
required: true
media_player_zone:
selector:
entity: {}
name: Media Player Zone
required: true
max: 10
Atm, when stating the phrase “Hey Jarvis, … Turn on The Apple TV” with the ESP32 zoned for the Master Bedroom Area, the response is something along the lines of “I don’t know of any device…”.
Clearly I’m doing something wrong to register the Intent, and the documentation around this stuff is extraordinarily piece mailed and fragmented.
I’m not completely sure of your intentions regarding tv_media_player and media_player_zone. But, I think the reason the script isn’t working now is it doesn’t know what tv_media_player or media_player_zone you wish to use. You haven’t added that in your intent sentences. Try something like:
language: "en"
intents:
AppleTVTurnOn:
data:
- sentences:
- "turn on [the] Apple TV in the {tv_media_player}"
- "turn on [the] {tv_media_player} Apple TV"
slots:
name: "Apple TV" #What are you using this for?
lists:
tv_media_player:
values:
- in: "living room"
out: "media_player.living_room_tv"
- in: "master bedroom"
out: "media_player.master_bedroom_lg_tv"
Hope this helps.
Also, I would leave out the zone and use a template for that, so you don’t need to mention both in your sentence:
alias: Turn On Apple TV
sequence:
- service: media_player.turn_on
target:
entity_id: "{{tv_media_player}}"
data: {}
- service: media_player.turn_on
metadata: {}
data: {}
target:
entity_id: >-
{% if tv_media_player == "media_player.living_room_tv" %}
media_player.marantz_sr6012_2
{% elif tv_media_player == "media_player.master_bedroom_lg_tv" %}
media_player.marantz_sr6012_2
{% else %}
media_player.marantz_sr6012_2 #makes this the default zone is none of the above apply.
{% endif %}
I’m hoping I can “imply” both the zone and the media player through the area the intent is triggered from. Is that not possible?
I’d much rather eliminate the in the {tv_media_player} part of the phrase all together.
I see how you’re using lists as param value substitution. For some reason, in the context of what I saw, I thought it could be used for associating values based on the area.
If I’m understanding your question correctly, you can pass the area of the device as a slot and use that in the intent.
PlayAudioOnSpeaker:
data:
- sentences:
- "( play | turn on | setup | put on | change to ) [ playlist ] {audio_request} ( in | on | and ) [ the ] {speaker_area} [ speaker | music | audio | speakers ]"
requires_context:
area:
slot: true
Then for your intent you can access the ‘area’ slot and do whatever you need to with it - it contains the area of the satellite device. Here I’m just passing it to the script, but you could use it however you need to, including to match speaker to area directly in the intent:
Correct, that might be true for your use case. For me there’s not a 1:1 relationship between location of the satellites and speakers, so I typically specify the speaker location. It works just the same either way though. A simpler example would be:
language: "en"
intents:
getSatelliteArea:
data:
- sentences:
- "Satellite area check"
- "what room is this satellite in"
- "what room is this"
- "identify this room"
requires_context:
area:
slot: true
and then
getSatelliteArea:
speech:
text: >-
{{ ['This satellite is located in the', 'I am in the '] | random }} {{ area_name(area) }}