Skip to content
Keaton Taylor edited this page May 9, 2020 · 23 revisions

Setting up your first actionable notification

Now that you have the skill setup and configured, it is time to setup your first actionable notification.

Creating the script.

Below is a helpful script that will allow you to trigger actionable notifications easily within your automations.

script:
  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.'
      event_id:
        description: 'Correlation ID for event responses'
      alexa_device: 
        description: 'Alexa device you want to trigger'
    sequence:
      - service: input_text.set_value
        data_template:
          entity_id: input_text.alexa_actionable_notification
          value: "{'text': '{{ text }}', 'event': '{{ event_id }}'}"
      - service: media_player.play_media
        data_template:
          entity_id: "{{ alexa_device }}"
          media_content_type: skill
          media_content_id: <Your Skill ID>

Replace <Your Skill ID> with the skill id for the custom skill you created. You can find this on the Alexa Developer Console by clicking "View Skill ID" on the skill you created in the previous step.

Triggering the Actionable Notification

Using the script above we can trigger the actionable notification in any automation similar to the below example code:

automation:
  - alias: Front door left unlocked for 5 mins
    trigger:
      platform: state
      entity_id: lock.front_door
      to: 'on'
      for:
        minutes: 5 

    action:
      - service: script.activate_alexa_actionable_notification
        data_template:
          text: 'The front door has been unlocked for 5 mins, would you like me to lock it?'
          event_id: 'actionable_notification_lock_left_unlocked'
          alexa_device: 'media_player.living_room_echo'

Performing actions on user response.

When the user says yes or no the custom component will trigger an event in Home Assistant that can be used for automations to perform actions based on how the user responds. For example, the above automation is using the event_id: actionable_notification_lock_left_unlocked so if they respond with "yes" you can capture that even with an automation like:

automation:
  - alias: Lock the door via actionable notificaiton
    trigger:
      platform: event
      event_type: alexa_actionable_notification
      event_data:
        event_id: actionable_notification_lock_left_unlocked
        event_response: ResponseYes
        
    action:
      - service: lock.lock
        entity_id: lock.front_door

There are three different event_response types you can trigger off of.

  1. ResponseYes - Performs an action when the user says "yes" to the custom skill.
  2. ResponseNo - Performs an action when the user says "no" to the custom skill.
  3. ResponseNone - Performs n action when the user does not respond to the custom skill.

Note: There is no requirement to create automations for a specific response. If saying "no" should perform no action in home assistant, there is no need to create an automation for it.

Adding additional event responses.

Please see the Advanced Features Wiki section

Other Fun Stuff

In your automation the text you want Alexa to speak supports the full range of Speech Synthesis Markup Language. This allows you to create automations where the skill will speak the test exactly as you define it.

For example to whisper the question, simply change the text to:

    action:
      - service: script.activate_alexa_actionable_notification
        data:
          text: '<amazon:effect name="whispered">The front door has been unlocked for 5 mins, would you like me to lock it?</amazon:effect>'
          event_id: 'actionable_notification_lock_left_unlocked'
          alexa_device: 'media_player.living_room_echo'

Thank you

If you've made it this far, let me thank you! It is the encouragement of the community that continues to inspire me to find new and creative ways to take home automation to he next level. Please, if you like what you see, consider buying me a coffee to help fuel my late nights :)

coffee