Share your Alexa Actionable Notifications

Thanks to @keatontaylor’s new Alexa Actions skill, we can now have Alexa prompt us before an optional action is taken. I figured we could use a separate topic to share our favorite automation, so we can leave the original topic to announcements and tech support.


I have an automation which locks the front door 5 minutes after it is unlocked. We have been eating meals in the front yard more lately, so we’d like the convenience of leaving the door unlocked during these times.

So every time the door is unlocked Alexa asks “Would you like to leave the front door unlocked?” Answering “Yes” cancels the countdown timer. Both ignoring the question or answering “No” results in the timer being cancelled so the door doesn’t lock us out.

I like to organize my automations into one file per automation, and I subdivide them into folders. This works well for the way my brain thinks. So, I have created /automations/alexa_actionable_notifications. Under which sit two folders: 1_triggers & 2_actions.

/automations/alexa_actionable_notifications/1_triggers/front_door_unlocked.yaml

---
alias: "Alexa Actionable Notifications: Trigger - Front door unlocked"
trigger:
  platform: state
  entity_id: lock.front_door
  from: locked
  to: unlocked

action:
  - service: script.activate_alexa_actionable_notification
    data_template:
      text: Would you like to leave the front door unlocked?
      event_id: actionable_notification_leave_unlocked
      alexa_device: media_player.family_room

/automations/alexa_actionable_notifications/2_actions/front_door_unlocked_response.yaml

---
alias: "Alexa Actionable Notifications: Action - Leave front door unlocked"
trigger:
  platform: event
  event_type: alexa_actionable_notification
  event_data:
    event_id: actionable_notification_leave_unlocked

action:
  - service_template: >-
      {#- User responds "YES". -#}
      {% if trigger.event.data.event_response == "ResponseYes" %}
        input_boolean.turn_on
      {#- User responds "NO" or User does not respond (NONE). -#}
      {% else %}
        input_boolean.turn_off
      {% endif %}
    entity_id: input_boolean.leave_unlocked

  # If Leave Unlocked is enabled, cancel the relock countdown timer.
  - condition: state
    entity_id: input_boolean.leave_unlocked
    state: "on"
  - service: timer.cancel
    data_template:
      entity_id: timer.front_door_unlocked

The helper input_boolean.leave_unlocked is used as a conditional check in my existing door locking automatons to make sure the door doesn’t lock unless we want it to.

4 Likes

Hey @BrianHanifin love the idea of a separate thread for sharing examples and automations. I’ve also setup an Examples section on the wiki to aggregate many examples in both YAML and NodeRED. If anyone finds some they want to add the Wiki is opened for edits.

1 Like

@BrianHanifin, very good idea. Here’s a simple one I did for controlling the lights when someone watches movies in our family room. Please ignore the kludged light action with the Input Boolean … it’s temporary. :grinning:

# Family Room Movie time Alexa Question
  - alias: Family room Apple TV ON
    trigger:
      platform: state
      entity_id: remote.harmony_hub
    condition:
      - condition: template
        value_template: '{{ trigger.to_state.attributes.current_activity == "Watch Apple TV" }}'
      - condition: state
        entity_id: sun.sun
        state: 'below_horizon'

    action:
      - service: script.activate_alexa_actionable_notification
        data_template:
          text: 'I see you are watching Apple TV, would you like me to dim the family room lights?'
          event_id: 'actionable_notification_family_room_lights'
          alexa_device: 'media_player.family_room_2'

  - alias: Dim the family room lights
    trigger:
      platform: event
      event_type: alexa_actionable_notification
      event_data:
        event_id: actionable_notification_family_room_lights
        event_response: ResponseYes
        
    action:
      - service: input_boolean.turn_on
        entity_id: input_boolean.dim_family_room
2 Likes

I will add this example to the Wiki if folks would like but just need to clean up some stuff first. But wanted to point out to some who may not have noticed yet about the responses or just to give another idea out there. I setup a duration response in node red for the garage door being open. Most of the examples for node red out there has just the event_response as the responses for the switches. The ResponseDuration shows under the event_response_type (it states this in the wiki but the examples for node red just have event_response as the filter) with the duration in secs as the event_response.

Here is the duration response:
Screen Shot 2020-05-26 at 1.12.23 PM

Here is a No response:
Screen Shot 2020-05-26 at 1.12.38 PM

So the responses still show under the type too so I have the switch node looking for the type and then the response in secs gets turned into the delay time in milliseconds for the delay node. Then it just pipes back to ask if I want it shut again after the delay.
Screen Shot 2020-05-26 at 1.11.06 PM


Function Node:

msg.delay = (msg.payload.event.event_response *= 1000)
return msg;

And the Delay node is set like this:
Screen Shot 2020-05-26 at 2.10.45 PM

Now when she asks and for whatever reason I want to get her to remind me later, I just tell her to remind me for however long I want. I tested it with hours also. The responses come back as seconds and the delay node wants it in milliseconds so the function node should take care of that for you. I just say “Remind me in 5 minutes” and it does. It does not setup a reminder in the alexa app. I checked. :slight_smile:

I only have the garage setup so figured I would play around with some delay stuff for possibly something else in the future. Let me know if you have any questions. Thanks for all the work on this! I love it but it is hard to come up with examples to use it.

I have some of the SSML stuff working too and was hoping to randomize the request/responses with the SSML but so far all I can do is have one type of response on the random template. For example it has to choose a phrase and then it goes into the SSML format. If I want an excited response for something or a regular response, the random phrase is put as the payload in the SSML format. So she may say something regular when the phrase was meant for her to be excited about it. A work around I thought of was a random number and it splits to choose one of those random responses already setup in the right format per the SSML you want. So maybe some excited responses ready to go and it sends that into the payload example below. Hope that makes sense so someone may want to add some random request/responses in there this may be a work around. Basically it boils down that I haven’t been able to send a random phrase with the SSML markups. The random phrase has to come into the call service node without the SSML markup.

Only way I have it working is the random quote has to go in first. I tried to have the SSML markup in the random but it she just reads it out. I know it is probably a quote or something I am missing but figured I would put this out there as an idea for folks.

Here is the random SSML working.

Template Node:

{{ [
"Something",
"Here we are!",
"Test this out.",
"All good stuff here!",
 ] | random }}

Then this is the data for the call service node.

{
    "text": "<amazon:effect name='whispered'>{{payload}}</amazon:effect>",
    "event_id": "alexa_right_garage_open",
    "alexa_device": "media_player.alexa_keeping_dot"
}
1 Like

@BrianHanifin, i just found your Topic after i created my own for this automation, but here is a better place for this:

Alexa, when is my laundry finished

With this automation i can ask my Echo: Alexa, when is my laundry finished?
She will respond:

  • and ask wich kind of laundry is in to answer the minutes it needs to be finished
  • or only respond that it’s already finished or that there is no laundry in

So it’s not really a Notification but ‘Actionable’ with Alexa Actions :slight_smile:

I already use a AVM Fritz!Dect 200 for power metering to know in wich state my Washing Machine is
in with this Input Select:

input_select:
  state_washingmachine:
    name: Washing Machine Status
    options:
      - Switched Off
      - Idle
      - Washing

.
To change the options based on the power metering i use these automations:

- alias: 'Washing Machine - Change State Switched Off'
  trigger:
    platform: numeric_state
    entity_id: switch.waschmaschine
    value_template: "{%if states.switch.waschmaschine.attributes.current_power_w is defined %}{{state.attributes.current_power_w}}{%else%}0{%endif%}"
    below: 1
  action:
    - service: input_select.select_option
      data:
        entity_id: input_select.state_washingmachine
        option: 'Switched Off'

- alias: 'Washing Machine - Change State Idle'
  trigger:
    platform: numeric_state
    entity_id: switch.waschmaschine
    value_template: "{%if states.switch.waschmaschine.attributes.current_power_w is defined %}{{state.attributes.current_power_w}}{%else%}0{%endif%}"
    above: 1
    below: 2
    for: '00:01:00'
  action:
    - service: input_select.select_option
      data:
        entity_id: input_select.state_washingmachine
        option: 'Idle'

- alias: 'Washing Machine - Change State Washing'
  trigger:
    platform: numeric_state
    entity_id: switch.waschmaschine
    value_template: "{%if states.switch.waschmaschine.attributes.current_power_w is defined %}{{state.attributes.current_power_w}}{%else%}0{%endif%}"
    above: 20
    for: '00:01:00'
  action:
    - service: input_select.select_option
      data:
        entity_id: input_select.state_washingmachine
        option: 'Washing'

Requirements

To use the following Automations you should have

Routine in Alexa App

To ask Alexa i set up a Routine with Alexa App that switch a Template Switch. I created an Input Boolean

input_boolean.switch_laundry_finished

A Routine in Alexa App can’t trigger an Input Boolean so an additional Template Switch is necessary in configuration.yaml

switch:
  - platform: template
    switches:
      switch_laundry_finished_template:
        value_template: '{{states.input_boolean.switch_laundry_finished.state}}'
        turn_on:
          service: input_boolean.turn_on
          entity_id: input_boolean.switch_laundry_finished
        turn_off:
          service: input_boolean.turn_off
          entity_id: input_boolean.switch_laundry_finished

Finally the Automation

The first one has a condition looking for the state ‘Washing’ and fires the actionable notification.

To make Alexa answer from that device you are talking to i use templating and the last_called state from alexa media player for each echo device so here you always have to change the entities based on your devices.

The second action turn off the template switch, so that the next turn on signal from Alexa App Routine will trigger the automation again.

- alias: 'is laundry finished ask what kind'
  trigger:
    platform: state
    entity_id: switch.switch_laundry_finished_template
    from: 'off'
    to: 'on'
  condition:
    condition: state
    entity_id: input_select.state_washingmachine
    state: 'Washing'
  action:
    - service: script.activate_alexa_actionable_notification
      data_template:
        text: "I am not sure, wich kind of laundry is in?"
        event_id: 'alexa_action_is_laundry_finished'
        alexa_device: '{% if states.media_player.wohnzimmer.attributes.last_called == true %}media_player.wohnzimmer{% elif states.media_player.schlafzimmer.attributes.last_called == true %}media_player.schlafzimmer{% elif states.media_player.bad.attributes.last_called == true %}media_player.bad{% elif states.media_player.arbeitszimmer.attributes.last_called == true %}media_player.arbeitszimmer{% endif %}'
    - service: switch.turn_off
      entity_id:
        - switch.switch_laundry_finished_template

If the Machine is ‘Turned Off’ this automation fires

- alias: 'is laundry finished no laundry in'
  trigger:
    platform: state
    entity_id: switch.switch_laundry_finished_template
    from: 'off'
    to: 'on'
  condition:
    condition: state
    entity_id: input_select.state_washingmachine
    state: 'Switched Off'
  action:
    - delay:
        seconds: 1
    - service: notify.alexa_media
      data_template:
        target: >
          {% if states.media_player.wohnzimmer.attributes.last_called == true %}
          media_player.wohnzimmer
          {% elif states.media_player.schlafzimmer.attributes.last_called == true %}
          media_player.schlafzimmer
          {% elif states.media_player.bad.attributes.last_called == true %}
          media_player.bad
          {% elif states.media_player.arbeitszimmer.attributes.last_called == true %}
          media_player.arbeitszimmer
          {% endif %}
        data:
          type: tts
        message: "I am sorry, but there is no laundry in. Did you forget something?"
    - service: switch.turn_off
      entity_id:
        - switch.switch_laundry_finished_template

And this will fire when the state is Idle and assume your laundry is finished and Alexa will tell you since when

- alias: 'is laundry finished laundry already finished'
  trigger:
    platform: state
    entity_id: switch.switch_laundry_finished_template
    from: 'off'
    to: 'on'
  condition:
    condition: and
    conditions:
      - condition: template
        value_template: "{{ as_timestamp(now()) > as_timestamp(states.automation.washing_machine_change_state_idle.attributes.last_triggered) }}"
      - condition: state
        entity_id: input_select.state_washingmachine
        state: 'Idle'
  action:
    - delay:
        seconds: 1
    - service: notify.alexa_media
      data_template:
        target: >
          {% if states.media_player.wohnzimmer.attributes.last_called == true %}
          media_player.wohnzimmer
          {% elif states.media_player.schlafzimmer.attributes.last_called == true %}
          media_player.schlafzimmer
          {% elif states.media_player.bad.attributes.last_called == true %}
          media_player.bad
          {% elif states.media_player.arbeitszimmer.attributes.last_called == true %}
          media_player.arbeitszimmer
          {% endif %}
        data:
          type: tts
        message: "Laundry is finished since {{ ( (as_timestamp(now()) - as_timestamp(states.automation.washing_machine_change_state_idle.attributes.last_triggered)) / 60 ) | round(0) }} minutes"
    - service: switch.turn_off
      entity_id:
        - switch.switch_laundry_finished_template

For each kind of laundry and Slots created https://github.com/keatontaylor/alexa-actions/wiki/AdvancedFeatures#adding-a-new-slot-type i have the following automation.
You should change the first number in the last code line, this represents the minutes these kind of laundry needs or rather how long the Washing Machine program needs to be finished.

- alias: 'Easy Care was triggered'
  trigger:
    platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: alexa_action_is_laundry_finished
  condition:
    condition: template
    value_template: "{{ trigger.event.data.event_response == 'Easy Care' }}"
  action:
    - service: notify.alexa_media
      data_template:
        target: >
          {% if states.media_player.wohnzimmer.attributes.last_called == true %}
          media_player.wohnzimmer
          {% elif states.media_player.schlafzimmer.attributes.last_called == true %}
          media_player.schlafzimmer
          {% elif states.media_player.bad.attributes.last_called == true %}
          media_player.bad
          {% elif states.media_player.arbeitszimmer.attributes.last_called == true %}
          media_player.arbeitszimmer
          {% endif %}
        data:
          type: tts
        message: "Laundry will be finished in {{ 42 - (((as_timestamp(now()) - as_timestamp(states.automation.washing_machine_change_state_wash.attributes.last_triggered)) / 60 ) | round(0)) }} minutes"

Last Word

You should also change the text phrases Alexa speaks because i translated this with my first grade school english :slight_smile:

2 Likes

Actionable Notifications From Multiple Echos
I have 5 Echo Flex and want the responses to bounce from one to another to hopefully catch someone in a room and respond to the reply. Currently, actionable notifications can’t work with groups of devices.

I set up the following: (Only showing 3 Echo Flex for brevity, but you’ll get the idea).

- alias: Boiler turned on Option to turn off
  trigger:
    platform: state
    entity_id: switch.boiler
    from: 'off'
    to: 'on'
  action:
    - service: script.activate_alexa_actionable_notification
      data_template:
        text: 'The heating has turned on. Do you want me to turn it off for you?'
        event_id: 'actionable_notification_heating_turned_on_1'
        alexa_device: 'media_player.lounge_2'

- alias: Turn off heating alexa request to kitchen
  trigger:
    platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: actionable_notification_heating_turned_on_1
      event_response: ResponseNone
  action:
    - service: script.activate_alexa_actionable_notification
      data_template:
        text: 'The heating has turned on. Do you want me to turn it off for you?'
        event_id: 'actionable_notification_heating_turned_on_2'
        alexa_device: 'media_player.kitchen_alexa'

- alias: Turn off heating alexa request to office
  trigger:
    platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: actionable_notification_heating_turned_on_2
      event_response: ResponseNone      
  action:
    - service: script.activate_alexa_actionable_notification
      data_template:
        text: 'The heating has turned on. Do you want me to turn it off for you?'
        event_id: 'actionable_notification_heating_turned_on_3'
        alexa_device: 'media_player.office'

- alias: Turn off heating alexa request to landing
  trigger:
    platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: actionable_notification_heating_turned_on_3
      event_response: ResponseNone      
  action:
    - service: script.activate_alexa_actionable_notification
      data_template:
        text: 'The heating has turned on. Do you want me to turn it off for you?'
        event_id: 'actionable_notification_heating_turned_on_4'
        alexa_device: 'media_player.landing_alexa'

- alias: Turn off heating alexa action
  trigger:
    - platform: event
      event_type: alexa_actionable_notification
      event_data:
        event_id: actionable_notification_heating_turned_on_1
        event_response: ResponseYes
    - platform: event
      event_type: alexa_actionable_notification
      event_data:
        event_id: actionable_notification_heating_turned_on_2
        event_response: ResponseYes  
    - platform: event
      event_type: alexa_actionable_notification
      event_data:
        event_id: actionable_notification_heating_turned_on_3
        event_response: ResponseYes
    - platform: event
      event_type: alexa_actionable_notification
      event_data:
        event_id: actionable_notification_heating_turned_on_4
        event_response: ResponseYes          
  action:
    - service: input_boolean.turn_off
      entity_id: input_boolean.heating_on_all_day, input_boolean.heating_on_24hrs

This works, in theory, and mostly in practice, moving on to the next Echo Flex if the ResponseNone event is fired.

However, if a device is offline, the chain breaks. I’m assuming that this is because the event of a non-connected device is not ResponseNone.

Looking through the docs, there doesn’t seem to be a way of handling an offline device event.

Is there an alternative way of achieving this?

1 Like

I am able to make the event get triggered when only I say Alexa Open custom actions.
How to make it trigger automatically

Is there a more efficient way of doing this yet?

I now have 13 Echo Flex devices and it’s all getting a little unwieldy!

I’m looking to do this and I’m not sure if amazon changed the way they have skills built but I can not get the skill for custom actions working. I have followed keatontaylor many times but keep getting the same result via Alexa. (There was a problem with the custom skills response.) I cant get it to work. I tested in the alexa skills builder section and get the same message so I know its not with Home assistant.
to have this working in an smart home setup would be game a changer.