-
-
Notifications
You must be signed in to change notification settings - Fork 186
Home Assistant Talking to Alexa (The Script)
- install the script
- configure the script
- check the connection
You have created a Custom Skill. Have the ID of the skill at hand. You can find this on the Alexa Developer Console by clicking "Copy Skill ID" on the skill you created.
You have the ID of your media player at hand (i.e. an Echo device) to set into media_player.<Your Media Player>
for testing. In doubt go to Developer Tools > STATES and search for it.
The following steps and examples are using this script to connect to Alexa. Make sure to install it i.e. into /config/scripts.yaml
. Replace <Your Skill ID>
with your skills ID.
activate_alexa_actionable_notification:
alias: activate_alexa_actionable_notification
description: Activates an actionable notification on a specific echo device
fields:
text:
description: The text you would like alexa to speak.
example: 'What would you like the thermostat set to?'
event_id:
description: Correlation ID for event responses
example: 'ask_for_temperature'
alexa_device:
description: Alexa device you want to trigger
example: 'media_player.bedroom_echo'
suppress_confirmation:
description: Set true if you want to suppress 'okay' confirmation
example: 'true'
sequence:
- action: input_text.set_value
target:
entity_id: input_text.alexa_actionable_notification
data_template:
value: '{"text": "{{ text }}", "event": "{{ event_id }}", "suppress_confirmation": "{{ suppress_confirmation }}"}'
- action: media_player.play_media
target:
entity_id: "{{ alexa_device }}"
data_template:
media_content_type: skill
media_content_id: <Your Skill ID>
mode: single
Use the Developer Tools to reload SCRIPTS.
Open two windows of the Developer Tools side by side, one for the request, one for the response.
In Developer Tools > SERVICES > GO TO YAML MODE enter:
service: script.activate_alexa_actionable_notification
data:
text: "Yes or no?"
event_id: "alexa_actionable_notification_test"
alexa_device: media_player.<Your Media Player>
- Do translations.
- Insert your media Player ID.
In Developer Tools > EVENTS listen to the event alexa_actionable_notification
. Hit the CALL SERVICE
button.
Your echo device should ask the given question and wait for your answer. You successfully reached skill and device and the answer successfully took the opposite direction.
Observe how the response contains the event_id
of the request. As a takeaway notice, how this is the place to debug the structure of the data within the event.
If you hear nothing or you don't receive the expected response, check your setup.
- Is the skill listed within your Alexa App on your Smartphone?
- Is the volume up?
- Did you connect your device and not to a device of your wife's or husband's account?
- Did you provide the right ID of your skill?
- In the developer console check the Analytics of your skill. (Utterances count up with some latency.)
We already got close to end-to-end testing. To do real world end-to-end testing, we need a minimal application to run. This is covered by the hello world application in the next step.
Head to the next step: Hello World
If you get an error with the skills response:
For the URL make sure you are using an external URL and not your personal internal IP that you use to access the HA dashboard. You also need the long lived token.
Make sure you setup port forwarding to let HA communicate to outside your firewall.
Go to this video and watch how to port forward, create a URL, and setup the DNS in Home Assistant. https://www.youtube.com/watch?v=jkBcGl7Vq8s