-
-
Notifications
You must be signed in to change notification settings - Fork 187
FirstAction
Now that you have the skill setup and configured, it is time to setup your first actionable notification.
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.'
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 }}"
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.
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'
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 notification
trigger:
platform: event
event_type: alexa_actionable_notification
event_data:
event_id: actionable_notification_lock_left_unlocked
event_response_type: ResponseYes
action:
- service: lock.lock
entity_id: lock.front_door
There are six different event_response_types
types you can trigger off of.
- ResponseYes - The response was a "yes"
- ResponseNo - The response was a "no"
- ResponseNone - There was no response
- ResponseNumeric - The response was a numeric value
- ResponseDuration - The response was a duration
- ResponseSelection - The response was a predefined selection as defined by the Advanced Features section.
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.
Please see the Advanced Features Wiki section
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"
NOTE: Not setting event_id
will allow you to only make alexa say something and not expect a response nor trigger an event.
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 the next level. Please, if you like what you see, consider buying me a coffee to help fuel my late nights :)
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