Actionable Notifications via Alexa Media Player

Does anyone know how to use the other “Event Response Types” in the Actionable Notifications via Alexa Media Player by @keatontaylor?
Three of them are very well documented and used:
event_response_type: ResponseYes
event_response_type: ResponseNo
event_response_type: ResponseNone

What I am seeking, is information about the other response types;
RESPONSE_SELECT
RESPONSE_NUMERIC and
RESPONSE_DURATION.

Specifically, RESPONSE_NUMERIC. I would like to utilize that in my workshop. When the area detects occupancy, I would like to utilize your code to have Alexa ask for security code, being a numeric response, using that within HA to verifying a pass/fail criteria.

Does anyone know if the response is passed back as a numeric, or string variable that can use in an comparison of the automation response? If possible, that would make this skill truly intelligent as well as convenient.

All you need is this to capture the numeric response…
value_template: '{{ trigger.event.data.event_response_type == "ResponseNumeric" }}'
The event_response is a string:


image

I also tested a RESPONSE_DURATION which looks like this after responding “5 hours”, which it reports as 18000 seconds:

I’ve not tried RESPONSE_SELECT but the default configuration only recognizes Amazon Prime, Hulu, YouTube and Netflix…

I’ve just finished implementing NUMERIC in lieu of a DATETIME type response which currently is not recognized by the skill I wish it was).

image

alias: Enable Alarm
sequence:
  - service: script.activate_alexa_actionable_notification
    data:
      text: Do you want your alarm enabled?
      event_id: actionable_notification_enable_alarm
      alexa_device: '{{ states.sensor.last_alexa.state }}'
  - wait_for_trigger:
      - platform: event
        event_type: alexa_actionable_notification
        event_data:
          event_id: actionable_notification_alarm_is_complete
    timeout: '00:01:00'
  - service: notify.persistent_notification
    data:
      message: Complete
      title: Enable Alarm
mode: single

image

alias: Actionable - Enable Alarm
description: ''
trigger:
  - platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: actionable_notification_enable_alarm
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.event_response == "ResponseYes" }}'
        sequence:
          - service: input_boolean.turn_on
            data: {}
            target:
              entity_id: input_boolean.alarm_enabled
          - service: script.activate_alexa_actionable_notification
            data:
              text: What time?
              event_id: actionable_notification_set_alarm_time
              alexa_device: '{{ states.sensor.last_alexa.state }}'
    default:
      - event: alexa_actionable_notification
        event_data:
          event_id: actionable_notification_alarm_is_complete
mode: single

In here I convert the numeric response of “715” or “900” or “1700” to the corresponding time of “07:15”, “09:00” or “17:00”

alias: Actionable - Set Alarm Time
description: ''
trigger:
  - platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: actionable_notification_set_alarm_time
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.event_response_type == "ResponseNumeric" }}'
        sequence:
          - service: input_datetime.set_datetime
            data:
              time: >-
                {{ (((( trigger.event.data.event_response | int / 100 ) - (
                trigger.event.data.event_response | int / 100) | int) * 1.66667
                + ( trigger.event.data.event_response | int / 100) | int) *
                3600) | timestamp_custom("%H:%M:%S", local=False) }}
            target:
              entity_id: input_datetime.alarm_time
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.event_response == "ResponseNone" }}'
        sequence:
          - service: input_datetime.set_datetime
            data:
              time: '08:00:00'
            target:
              entity_id: input_datetime.alarm_time
          - service: notify.alexa_media_last_called
            data:
              message: Your alarm has been set for 8 am
              data:
                type: tts
          - delay:
              hours: 0
              minutes: 0
              seconds: 5
              milliseconds: 0
    default: []
  - event: alexa_actionable_notification
    event_data:
      event_id: actionable_notification_alarm_is_complete
mode: single

I now have to add the finishing touch which I JUST figured out how to do…

Now for my new issue…

I have one Echo 3rd Gen w/clock which recently stopped recognizing the custom skill. Extremely perplexing as my 7 other echos are working fine with Actionable Notifications and respond correctly to “Alexa, open custom actions”. When I say that phrase to my Bedroom Echo Dot Right, she answers “Did you mean positive actions?”.
I’ve rebooted the echo, factory reset the echo, as well as deregistered the echo & removed Alexa Media Player integration, deleted all deletable entities, reregistered the echo &re-installed Alexa Media Player integration, all to no avail.
My Bedroom Echo Dot Left is the exact same model and firmware and is working. I’ve no idea what wires are crossed/disconnected or where…

Thank you for the reply!!! Can you tell me where I am going astray?
In Developer Tools I get UndefinedError: ‘trigger’ is undefined.
In my Automation, I know event_response_type: ResponseNumeric is triggered because I have it toggle a light I can watch… But nothing I can see past that. Ideas?

alias: action1_test
description: Action1 Response numeric
trigger:
  - platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: alexaactionstest
      event_response_type: ResponseNumeric
condition: []
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.grand_father_clock
  - service: input_text.set_value
    data:
      value_template: '{{ trigger.event.data.event_response_type == "ResponseNumeric" }}'
    target:
      entity_id: input_text.input_text_response
  - service: input_number.set_value
    data:
      value_template: '{{ trigger.event.data.event_response_type == "ResponseNumeric" }}'
    target:
      entity_id: input_number.input_number_response
mode: single

Both input_text_response and input_number_response remain unchanged from initial settings.

That template will return true or false. You will want:
value_template: '{{ trigger.event.data.event_response }}'

In Dev Tools, Events you will want to START LISTENING to alexa_actionable_notification

Hi, do I always need to create a new custom action on Alexa dev console for every automation that I’ll create in HA?
Or can I use the same Skill ID in every automation?

@Asig,
I am not sure exactly what you are asking here, but, I will take the liberty of explaining what I can (Hopefully, I will not transgress too far).
Once you have the skill created. you can set up an automation (Trigger). In the action: section, you call out service: script.activate_alexa_actionable_notification, under that you have data: where you send the message… In that section, you designate a event_id:. that event_id designation should be unique for each initial action and matching each response action.
Please let me know if that answered your question. I have examples if you would like. I also am in the process of setting up a github repository that will have an example of how to implement the event_response_type: ResponseNone and have it continue the same event on another amazon alexia device. (When no one is in that room).

How can the value_template: return a true or false until you define what you are comparing it to?
I was hoping for capturing the response, saving it to a helper, and then flowing my action based on content. I will attempt recreating your test(s) in Developer tools. I apologist for misunderstanding. I am still looking for a method of capturing and saving the response in an automation. I know this one is not easy, or it would have been done already :wink:

I think in some way this answers my question :slight_smile: I have one workin actionable notification for checking if my car is locked. But I was wondering that when I want to make other actionable automation, then can I use the same Skill ID from amazon, but of course create a new event_id for that?

Explanation this way:

  1. I set up custom action on Amazon Dev console
  2. I create an automation in HA with my own event_id and Skill ID from amazon.
  3. I create second automation for something else with unique event_id but with same Skill ID -is this gonna work properly?

You only should have one script which contains the Amazon Skill ID. Everything else calls that one script and your various actionable automations are triggered by the event being fired…
script:

alias: Activate Alexa Actionable Notification
sequence:
  - service: input_text.set_value
    entity_id: input_text.alexa_actionable_notification
    data:
      value: '{"text": "{{ text }}", "event": "{{ event_id }}" }'
    target:
      entity_id: input_text.alexa_actionable_notification
  - service: media_player.play_media
    target:
      entity_id: '{{ alexa_device }}'
    data:
      media_content_type: skill
      media_content_id: amzn1.ask.skill.<redacted>-<redacted>-<redacted>-<redacted>
mode: single
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.new_white_echo_dot

In your automation…

alias: action1_test
description: Action1 Response numeric
trigger:
  - platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: alexaactionstest
      event_response_type: ResponseNumeric
condition: []
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.grand_father_clock
  - service: input_text.set_value
    data:
      value_template: '{{ trigger.event.data.event_response_type == "ResponseNumeric" }}'
    target:
      entity_id: input_text.input_text_response
  - service: input_number.set_value
    data:
      value_template: '{{ trigger.event.data.event_response_type == "ResponseNumeric" }}'
    target:
      entity_id: input_number.input_number_response
mode: single

the trigger is the event with event_id alexaactionstest AND the event response type ResponseNumeric that you have initiated by another automation calling the aforementioned script. In your action, you want to assign the user response to an input variable. Your service call for the input_text.set_value…

  - service: input_text.set_value
    data:
      value_template: '{{ trigger.event.data.event_response_type == "ResponseNumeric" }}'

currently says “Is the trigger.event.data.event_response_type equal to ResponseNumeric?” If it is that template returns the boolean True otherwise False as the data value to assign to the input_text. I have not tried assigning a boolean to an input_text but I would expect the automation might fail at that point (check your automation debug trace) and log an error in your log, but I could be wrong on that.

If you want to execute different actions based on the ResponseType then start with a Choose, Option 1, Condition value_template: ‘{{ trigger.event.data.event_response_type == “ResponseNumeric” }}’ , actions; Option 2, Condition value_template: ‘{{ trigger.event.data.event_response_type == “ResponseYes” }}’ .but your current trigger precludes different response types. If you want the automation to process the actions for any response type then you have to remove the event_response_type from the trigger and use Choose in your Actions as I just stated. .

To reiterate, the user’s response is contained in the event.data.event_response so that is what you want to test, assign, etc.

action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.grand_father_clock
  - service: input_text.set_value
    data:
      value_template: '{{ trigger.event.data.event_response }}'
    target:
      entity_id: input_text.input_text_response
  - service: input_number.set_value
    data:
      value_template: '{{ trigger.event.data.event_response" | int(default=0)}}'
            * OR *
      value_template: '{{ trigger.event.data.event_response" | float(default=0)}}'                     
    target:
      entity_id: input_number.input_number_response

This will assign the “numeric” response as text to input_text.input_text_response and as a number to input_number_response, which doesn’t make sense to me why you would want to do that. I am trying to 2nd guess your goal…

Still thinking of method to explain…

@dbrunt,
Well, I must thank you in advance. And express my application you you being understanding.
I was finally able to get a response from developer tools - Events… Not as documented as the other tools… BUT, I see what you are talking about and played with various test automation… MY findings… I am able to (In the Trigger: section) add the event_response: and if that number is used, the automation is triggered… I am now ½ way there thanks to you :smiley: … Currently with the new knowledge, I am able to use that number in the trigger, but I am not able to save the number in the action: section. Do you think that is because it is automatically dismissed after trigger is activated?

No, the trigger variables remain available throughout the duration of that invocation of the automation and will be available in the action: section. Post your automation code and let’s have a look…

I am using ResponseNumeric in my set alarm actionable notification.
First action is to ask Do you want to set an alarm?
ResponseNo - sequence complete.
ResponseYes - run script to execute 2nd actionable notification What time?
(My response has to be numeric as the skill does not understand date/time)
ResponseNone - default to 08:00 AM
ResponseNumeric process the number converting it to a time:
“710” > “07:10:00”, “1750” > “17:50:00”, etc.
and save that to an input_datetime.helper.
Mine is basically equivalent to what you want to do except I have extra processing to do on the numeric response to convert to a date/time value and I am saving it to an input_datetime helper instead of an input_number helper.

My “I bought coffee filters” routine is closer to what you want to do.
When I say “Alexa, I bought coffee filters” it runs this Alexa scene/HA script…

alias: Coffee Filters
sequence:
  - service: alexa_media.update_last_called
    data: {}
  - service: script.activate_alexa_actionable_notification
    data_template:
      text: How many coffee filters did you buy?
      event_id: actionable_notification_coffee_filters
      alexa_device: '{{ states.sensor.last_alexa.state }}'
mode: single

and this automation is triggered:

alias: Actionable - I Bought Coffee Filters
description: ''
trigger:
  - platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: actionable_notification_coffee_filters
      event_response_type: ResponseNumeric
condition: []
action:
  - service: input_number.set_value
    target:
      entity_id: input_number.coffee_filter_count
    data_template:
      value: >-
        {{ trigger.event.data.event_response| int(default=0) + states("input_number.coffee_filter_count")|int}}
  - service: notify.alexa_media_last_called
    data:
      message: >-
        You now have {{ states("input_number.coffee_filter_count")|
        int(default=0) }} coffee filters.
      data:
        type: tts
  - service: shopping_list.complete_item
    data:
      name: Coffee filters
mode: single
1 Like

I just tried this but failed to get ask home assistant actions simon says do you want me to set an alarm for you eventid is alarm_time to work. She does not know what I am talking about…

works! :beers: Previous attempts like

did not work.
… BTW :thinking: I would bet there is only a hand full of users that have successfully installed the skill and very few of them do like we do and have a response invoke another question! I absolutely thank you for taking the time to guide me a solution… As mentioned previously, I was never able to get the Developer Tools - Events to do anything… then all the sudden I saw the capture like you shared… :slight_smile: Have a great day & keep in touch!

I did not check your original coding against mine thus did not notice data_template: value: should have been data: value_template! I was focused on the template itself {{ trigger.event.data.event_response_type == "ResponseNumeric" }} which was incorrect. Sorry about that.

Dev Tools - Events: I too was a little dumbfounded when I first went to that page!

Amazon Support was stumped and are replacing it for me…

@dbrunt,
I have followed your trouble you are having with your new 3rd generation echo. It just makes no sense. I experienced the same symptoms you describe, but the cause was there was a typo in the skill creation… Obviously, not your issue. The only thing I can mention is that when I ordered my last echo device, amazon had it added to my account before it even left the warehouse. So, I ponder, did they add it to the wrong account LOL? When you ask from a different device, “Announce”, is it included in the response? And yes, I know you have probably already tried those things, I am just curious in your findings… Yet another Amazon “feature”.
Anyhow, I am just do empowered by the assistance you gave me… Following an earlier thread of yours, I am now employing ResponseDuration to set a timer for the lights in my basement.
I must say, I am completely intrigued by your accomplishments! If you wouldn’t mind, I would love to hear how-to details in a much earlier thread of yours… Jan-21 “My fourth one now but using responses other than Yes/No/NoResponse”…
I believe you have it configured where you can start the Notification Automatons from addressing Alexa, by saying “Alexa… Statement”. If I understand correctly, you have a Alexa-Routine triggered, that inturn triggers the automation? OOOOhhhh I can see so many uses for that :grin: I will confess, I have never attempted to configure any Alexa-Routine’s or Scene’s yet so this will be entry level for me.

And - Back to the original topic… I agree, you can not go wrong getting Amazon to replace the new echo. I hope it all works out, as I know… we can easily become dependent on them.

Yes, it was bizarre behaviour with that echo. Everything else Alexa & HA related worked fine, just not that custom skill for actionable notifications. And all echos including it used to work fine, it’s not a brand new one. It seemed though to correlate with a power outage. I even had a little trouble with my wi-fi after that outage, 2.4 GHz was working but not 5 GHz to the echos was not let it was on my PC and my phone. Tell me how that could be??? Power cycling the AP resolved it.
Yes, all of my echos bought from Amazon were already registered to my account, just not my 1st one that was store bought.
My actionable notifications are triggered by routines with a phrase like “Alexa, I bought coffee filters” or “Alexa, good night”/“Alexa, good morning” The routines turn on scenes. The scenes are scripts from HA and the magic happens there.