Skip to content

Home Assistant Talking to Alexa (The Script)

Elmar Hinz edited this page Jan 2, 2023 · 22 revisions

Goals

  • install the script
  • configure the script
  • check the connection

Prerequisites

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.

Screenshot of the skills overview with the copy skill ID button

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.

Screenshot of a search for media players

Installing the script

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:
  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'
  sequence:
    - service: input_text.set_value
      data:
        entity_id: input_text.alexa_actionable_notification
        value: '{"text": "{{ text }}", "event": "{{ event_id }}"}'
    - service: media_player.play_media
      data:
        media_content_type: skill
        media_content_id: <Your Skill ID>
      target:
        entity_id: "{{ alexa_device }}"

Use the Developer Tools to reload SCRIPTS.

Checking success

Talking to Alexa

Go to Developer Tools > SERVICES > GO TO YAML MODE and enter:

service: script.activate_alexa_actionable_notification
data:
  text: This is a test
  alexa_device: media_player.<Your Media Player>
  • Do translations.
  • Insert your media Player ID.
Screenshot 2023-01-02 at 17 03 31

Hit the CALL SERVICE button. Your echo device should speak the given sentence to you. You successfully reached skill and device. If you hear nothing, check your setup so far.

Troubleshooting

  • 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.)

Receiving the event

We didn't sent an event_id on purpose, not to make the Echo device waiting for an answer. To do end-to-end testing, we need a minimal application, that can also receive the event. This is covered by the hello world application in the next step.


Head to the next step: Hello World