Actionable Notifications via Alexa Media Player

I don’t believe you can suppress or change her default response that is defined in the functions.py when invoking the skill. You can edit the OKAY=“OKAY” to always say something different.

So, the sequence becomes…
Alexa Routine: When I say “Alexa, it’s hot in here”
Alexa Action: turn on a scene which is your script in HA.
Your script then invokes an actionable notification…
Alexa Ask: I understand you think it’s too hot in here. I’m fine with this temperature but would you like me to turn on the A/C for you?
Your Response: Yes
Alexa Response: Okay

This then triggers next actionable notification if ResponseYes:
Alexa Ask: What temperature would you like?
ResponseNumeric: 72
Alexa Says: Okay, I’ve set the temperature to 72 degrees.

As for Node Red, I’ve only used HA up until now but have recently started exploring AAN (Alexa Actionable Notifications) in NR. As I understand, it the interaction of the actionable skill in Amazon still occurs through HA. NR is simply tied into the HA event bus and can be actioned on by NR rather than HA automations…I think!

I am really on track and learning the many options and uses. You have one that if you could share a few extra details, it would be helpful. I am “assuming” you are using an “Alexa Routine” to trigger HA. How are you linking it to HA? (I am new to this and have only previously used a routine(s) as a timer to turn outside Christmas Lights On/Off.) So many options… Building a new routine, with intent to trigger HA… like “Alexa, I bought coffee filters” …
Steps to create:

  1. In the Amazon app, name the routine.
  2. When this happens (?) [Choices: Voice, Schedule, Smart Home, Location, Alarms, Echo Button, Sound Detection, Guard). Scrolling the options, it appears to add additional conditions and not Actions
  3. How to you send a detectable *trigger to an HA Automation? Pondering this, the only thing that comes to mind is have it toggle a switch without a device and in HA detect the Switch State changing…

I am pretty sure there is a simple thing I am missing to trigger a sequence from Alexa to HA… Can you help?

I may be misunderstanding your comment, but you do not need a physical switch without a device. You can activate an Input boolean or button helper .

But I believe Daniel is calling his HA scripts directly in the Alexa routine. Your HA script can be found under Smart Home > Control scene action in the Alexa routine editor.

1st, you need Actionable Notifications via Media Player custom skill set up & working. You know it’s working when you say Alexa, open custom actions and she responds with the default text from the primary input boolean you created in HA when setting up the skill:
image

Here is what I have for coffee filters:

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") }}'
mode: single

automation:

alias: Actionable - 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

Same here!!! :frowning: Did you fix it? I have tried the whole process several times but always the freaking positive actions grrrrrr

NEVERMIND!!! I changed the language to english UK and now it works… (I´m from Spain and the setup was for both English and Spanish but it seems that alexa didn´t like it so…)

Yes, she is very picky about the language settings!
I’ve spent several hours (feels like dozens) troubleshooting my issue and the replacement echo still was problematic. I originally started out with them registered to amazon.com (which would be en-us) so I could use Alexa Guard (and something else that I can’t remember) but ended up moving them all to amazon.ca so I could utilize Telus Home Assistant which is only available in Canada. After I moved them all back to amazon.com, and rebooting everything, they all started working with this custom skill. I have not tried yet to bring them back to .ca to see what happens…

Does anyone have an idea about how to add an error-trap routine to detect attempting to send a number larger that the max set in the input_number configuration? Currently, it completes the automation without making any changes.
My input_number and (Dynamic Timer):

timer_basement:
  name: Basement Timer
  min: 0
  max: 60
  step: 1
  mode: box
---------------------------------
alias: timer_basement_lights
description: Basement Light Timer
trigger:
  - platform: time_pattern
    minutes: "*"
condition:
  - condition: numeric_state
    entity_id: input_number.timer_basement
    above: 0
action:
  - choose:
    - conditions:
      - condition: state
        entity_id: switch.basement_lights
        state: 'on'
      sequence:
        - service: input_number.decrement
          entity_id: input_number.timer_basement
  - choose:
    - conditions:
      - condition: state
        entity_id: switch.basement_lights
        state: 'off'
      sequence:
      - service: input_number.set_value
        data:
          value: 0
        target:
          entity_id: input_number.timer_basement
mode: single

My Actionable Notification:

alias: alexa_basement_lights_initial
trigger:
  - platform: numeric_state
    entity_id: input_number.timer_basement
    above: '0'
    below: '3'
condition: []
action:
- service: script.activate_alexa_actionable_notification
  data:
    text: The basement lights are preparing to turn off. Since you are still down here, I can reset the timer. How many minutes longer?
    event_id: basement_lights
    alexa_device: media_player.basement
mode: single

and My Actionable Response:

alias: alexa_basement_light_response
trigger:
  - platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: basement_lights
      event_response_type: ResponseYes
    id: basement_lights_yes
  - platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: basement_lights
      event_response_type: ResponseNo
    id: basement_lights_no
  - platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: basement_lights
      event_response_type: ResponseNone
    id: basement_lights_none
  - platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: basement_lights
      event_response_type: ResponseSelect
    id: basement_lights_select
  - platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: basement_lights
      event_response_type: ResponseNumeric
    id: basement_lights_numeric
  - platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: basement_lights
      event_response_type: ResponseDuration
    id: basement_lights_duration
condition: []
action:
  - choose:
    - conditions:
      - condition: trigger
        id: basement_lights_yes
      sequence:
      - service: input_number.set_value
        data:
          value: 5
        target:
          entity_id: input_number.timer_basement
    - conditions:
      - condition: trigger
        id: basement_lights_no
      sequence:
      - service: input_number.set_value
        data:
          value: 0
        target:
          entity_id: input_number.timer_basement
    - conditions:
      - condition: trigger
        id: basement_lights_none
      sequence:
      - service: input_number.set_value
        data:
          value: 0
        target:
          entity_id: input_number.timer_basement
    - conditions:
      - condition: trigger
        id: basement_lights_select
      sequence:
      - service: input_number.set_value
        data:
          value: 0
        target:
          entity_id: input_number.timer_basement
    - conditions:
      - condition: trigger
        id: basement_lights_numeric
      sequence:
      - service: input_number.set_value
        data_template:
          value: >-
            {{ trigger.event.data.event_response | int(default=0) }}
        target:
          entity_id: input_number.timer_basement
    - conditions:
      - condition: trigger
        id: basement_lights_duration
      sequence:
      - service: input_number.set_value
        data_template:
          value: >-
            {{ trigger.event.data.event_response | int(default=0)/60 }}
        target:
          entity_id: input_number.timer_basement
mode: single

On first read through I would focus on this section:

- conditions:
      - condition: trigger
        id: basement_lights_numeric
      sequence:
      - service: input_number.set_value
        data_template:
          value: >-
            {{ trigger.event.data.event_response | int(default=0) }}
        target:
          entity_id: input_number.timer_basement

In sequence I would do a

Choose:

Option 1:
Condition:
NumericResponse is less than or equal to stateattr("input_number.timer.basement", "Max")
or
stateattr("input_number.timer.basement", "Min") <= NumericResponse <= stateattr("input_number.timer.basement", "Max")

Sequence:
(your existing actions go here)

Default:
(applies to outside acceptable range)
Sequence: Fire a new actionable notification: “{{ NumericResponse }} is outside the permitted range of {{ stateattr(“input_number.timer_basement”, “Min”) }} to {{ stateattr(“input_number.timer_basement”, “Max”) }}. Please specify a number in the allowable range”

Choose: is a great If…Then…Else… addition to HA!

The above is just pseudo code but I think you can figure it out!
Happy to assist and troubleshoot…

@dbrunt,
Again, thanks for your response. I think I am missing something… I set up the script, much like your example…

The Amazon routine is looking for the scene like your example.
t
My question… Do you have an example scene? Can you attach YAML code?
I looked for examples and cant find any that are not controlling entities in a script like function.
I also tried the UI


and I am really lost missing how to link a script to a scene so that the routine can identify what to do.
And even tried placing the script in the scene.yaml and get the error:

Any ideas?

@dbrunt,
This one is absolutely illogical!! The error trap works properly on
event_response_type: ResponseNumeric

      - condition: trigger
        id: basement_lights_numeric
      - condition: template
        value_template: "{{ '0' <= trigger.event.data.event_response<= '60' }}"

but not
event_response_type: ResponseDuration

      - condition: trigger
        id: basement_lights_duration
      - condition: template
        value_template: "{{ '0' <= trigger.event.data.event_response<= '3600' }}"

If the extra condition is added to trap duration no matter what, even if the value given is one minute it is passed to default. Being so strange and illogical, added the working trap and anyone asking for more than one hour in duration is in the dark :crazy_face:
Thought for the day, sometimes you have to take your victories if you one ½ the battle. :face_with_monocle:
Now back to learning the syntax of sequence.

Here is my scenes.yaml:

- id: '1648324269691'
  name: Close Bedroom Blind
  entities:
    cover.bedroom_blind:
      current_position: 4
      friendly_name: Bedroom
      supported_features: 7
      device_class: cover
      state: close
  icon: mdi:window-shutter-open
- id: '1648324334767'
  name: Open Bedroom Blind
  entities:
    cover.bedroom_blind:
      current_position: 4
      friendly_name: Bedroom
      supported_features: 7
      device_class: cover
      state: open
  icon: mdi:window-shutter-open

You can’t link a script to a scene. Scenes are only for defining a state you want for devices and entities when you activate the scene. But a script or automation can activate a scene.

service: scene.turn_on
target:
  entity_id: scene.close_bedroom_blind
metadata: {}

Both HA scripts and HA scenes appear in Alexa as Scenes.

The Event Listener is your best friend here to see what Alexa is returning.
To re-trigger the last actionable notification just ask Alexa, open custom actions.
I just tried on mine and if I answer with 3 hours I get 10800, which is seconds
whereas 4 and a half minutes returned 270, which is minutes.
1 minute looks like this:

Event 5 fired 12:29 PM:
{
    "event_type": "alexa_actionable_notification",
    "data": {
        "event_id": "actionable_notification_another_name",
        "event_response": 60,
        "event_response_type": "ResponseDuration",
        "event_person_id": "amzn1.ask.person.AICLLUQLXZNFVNMUOSLKWZBX4DXDPYOYXW3QQL3BMKMNSDCIRW7G52CM3U6M4YCM5GNHZESFQGKDEFUEMK5FNRQGSPRBC6JH23JCTTML"
    },
    "origin": "REMOTE",
    "time_fired": "2022-04-23T19:29:35.608907+00:00",
    "context": {
        "id": "1231fda53d36816d196ef2c4184d03f0",
        "parent_id": null,
        "user_id": "7c824b7712954da39c719cddefae9008"
    }
}

Have you checked your script/automation debug tracing?


I don’t have any actionable notification scripts/automations for ResponseDuration, just ResponseNumeric

I sometimes add an HA persistent notification to get an instant look at something I am debugging.

action:
  - service: input_select.set_options
    target:
      entity_id: input_select.destination
    data:
      options: '{{ states.zone | map(attribute="name") | list }}'
  - service: notify.persistent_notification
    data:
      title: Destination Selections Updated
      message: >-
        {{ trigger.event.event_type }}: {{ trigger.event.data.action }}: {{
        trigger.event.data.entity_id }}

Not mine. Just in case I am off the path, as I have never been here before… Here are the steps I am using to attempt linking to a HA Script (In the Amazon Alexa App):

  1. Open App.
  2. At the bottom, select more icon.
  3. In the list, select routines
  4. At the top, (+)
  5. Enter Routine Name (+), Coffee Filters, At the top, Next.
  6. When This Happens (+), In the list, select Voice, “I brought coffee filters”, At the top, Next.
  7. Add Action (+), In the list select “Smart Home”. Options are:
    All Devices; Lights; Control Group.
    All Devices: About 100 devices linked directly into Echo, all are Switches and Lights.
    Lights: (This brings up a link that opens a list of Lights, Noting some are duplicated.
    Control Group: This list is previous routines controlling lights created directly in this convention before I started learning HA.

Am I doing this right? I do not see any of the scripts in HA.

Yes, those are the correct steps. When I do those, I see All Devices, Lights, Control group, Control scene. How did you add the Alexa integration to HA? Are you using Nabu Casa or did you follow the manual setup steps?

www.xxxx.duckDNS.org

Hello,

the Actionable Notifications works well, but now im playing with a custom answer.

My example.

He Should question me which serie i want to play, i want to answer for example “simpsons” and he should play it on my mediaPlayer.

I had a input_text field which when changes the text (state) he plays this on my Plex.

now is the questions is it possible to answer with a series (custom) name? and request this answer from me to put it in the input_text?

can there someone help or give me a link to the wiki?

As I mentioned earlier, I followed all the steps explicitly adding the custom skill (It took two weeks of starting over because I had a typo in one step :exploding_head:, and the HACS Alexa Media Player, which enabled the integration Alexa Media Player.
Meanwhile, I thought about what you said. And beyond by better judgement :grimacing: I deleted the integration and added it back in. :pleading_face: Painful! with the same results and a side affect. My devices got renamed slightly. At first I thought I broke it good; fortunately I just have to edit YAML.
Still seeking this awesome method you enlightened me to. I am planning to pursue an alternate method using an input helper as mentioned by @Didgeridrew until I can learn more. Another clue I have is the log book. I have posted this awhile back, but no one responded.

Trying to make sense of the log(s) is challenging when you take on new ground by trial and error with the help of savior’s like yourself. I wish there was a book out there, the internet is riddled with documentation, but some of it is super vague. My experience tells me the information source most likely has some additional configuration or YAML that is not included.
Anyhow… If you think of anything, let me know.

All my echos do this, I gave up on getting alexa actionable notifications because of this…lemme know if your replacement does the same thing!

edit, fixed

Changing the language from english canada to english US made everything work.

I think you need advanced setup in your skill and that’s not something I have done.
The wiki is here

I originally started with manual setup then tried HA Cloud for a while, and liked the ease by which you can add/remove what’s presented to Alexa discovery without having to edit yaml and restart HA but I am now back to the manual setup. I am using Duck DNS and Nginx Proxy Manager add-ons with 443 forwarded to HA but now have my own domain name with dynamic DNS updating so I no longer need Duck DNS. I currently do not have the error you refer to so OAuth is working for me.
If you delete all HA discovered entities from Alexa and rediscover, does she still discover everything except scenes/scripts? If the websocket is not connecting she should discover nothing, If it is then everything in your smart_home: section should be discovered. What is in your smart_home: yaml for Alexa??