Actionable Notifications via Alexa Media Player

@dbrunt

First I’ll apologize for two things…

The first is for tagging you directly but you seem to be the most likely person to help me based on your recent posting history here.

Second is that I’ll apologize for the questions I’ll ask and for how possibly complex this might be. :laughing:

so on to my issue…

I’ve been using this integration for a while and haven’t really had any problems.

I saw your discussion above about the “ResponseNumeric” and it provided a possible means to do something I’ve been recently wanting to figure out how to do. Namely I want to be able to tell Alexa to set my phone alarm to a variable based on my voice input.

I previously had this set up to just set the phone to a pre-defined value set up thru an input_datetime (I’ll call it ) and that worked as expected. I even had the actionable notifications set so that it only set the alarm after a confirmation question.

All of that worked.

Then I added the “ResponseNumeric” into the mix and just can’t seem to get it working. I’ve been trying for a couple of days and I can’t see where I’m going wrong.

I’ll start out with some pseudo-code based on my (much longer) real code and I’ll indicate what works and where it’s failing.

  - alias: Alarm Ask to Set Manually
    action:
      - if: sensor.my_mobile_app_next_alarm != "unavailable"
        then: "There is already an alarm set on your phone" => STOP # <-- this step works
        else: actionable_notification_alarm_set => "Would you like me to set your alarm for...<currently set value>?" # <-- this step works
          possible responses:
            ResponseYes
            ResponseNone
            ResponseNo
        
  - alias: Alarm Set From Response
    event_id: actionable_notification_alarm_set
    action:
      choose:
        - "ResponseYes" => "OK, your alarm has been set to ...<currently set value>" => STOP # <-- this step works
        - "ResponseNone" => "OK, your alarm has been set to ...<currently set value>" => STOP # <-- this step works 
        - "ResponseNo" => actionable_notification_alarm_set_time_variable => "Would you like me to set your alarm for a different time?" # <-- this step works
            possible responses:
              ResponseNo
              ResponseNone
              ResponseYes
  
  - alias: Alarm Set Variable Time From Response
    event_id: actionable_notification_alarm_set_time_variable
    action:
      choose:
	    - "ResponseNo" => "OK, no alarm has been set" => STOP # <-- this step works
            - "ResponseNone" => "OK, no alarm has been set" => STOP # <-- this step works
            - "ResponseYes" => actionable_notification_alarm_set_time_for => "What time would you like it set for?" # <-- this step works
               possible responses:
                 ResponseNumeric
                 ResponseNone

## this is where it breaks down
                
  - alias: Alarm Change Time Set From Response
    event_id: actionable_notification_alarm_set_time_for
    action:
      choose:
        - "ResponseNumeric" => set_datetime to...<numeric reponse> => "OK, your alarm has been set to...<numeric response>" => STOP
        - "ResponseNone" => "OK, no alarm has been set" => STOP

When Alexa asks “What time would you like it set for?” the echo device stops listening (indicated by the light ring turning off).

No matter what the response is that I provide nothing happens (sort of…)

BUT…If I wait a bit (even up two or three minutes) and I start the sequence again (“Alexa, set the alarm on my phone”) the device starts to make its first question (“Would you like me to set your alarm for…?”) but it gets interrupted part way thru by the device saying “OK, no alarm has been set” followed by my phone alarm getting set to the then the device telling me that my alarm has been set (" OK, your alarm has been set to …").

Obviously there should be no other steps of setting the alarm until it registers the numeric response.

and it shouldn’t tell me no alarm is set at the end unless it receives a ResponseNone. But there are no responses registered at all after that.

And it definitely shouldn’t do both. (say no alarm is set and then set an alarm at the same time)

Then everything resets and I can again go thru the above sequences. At least till I get to the part that it asks what time I want the alarm set for. Then the same thing happens.

I’m really at a loss.

It almost seems as if there is only a certain number of chained actionable notifications the system can process before it gets lost.

watching the actionable notification events I see that everything gets registered correctly until the question about “what time?” then everything stops.

I’ll post the code but I knew this was already a really info heavy post and I didn’t want to add any more to it.

Anyone have any insight into this?

Code to follow…

automation:
  - alias: MA Alarm Ask to Set Manually
    id: ma_alarm_ask_to_set_manually
    trigger:
      - platform: state
        entity_id: input_boolean.ma_alarm_set
        to: 'on'
    condition:
      - condition: state
        entity_id: person.me
        state: 'home'
    action:
      - delay: "00:00:02"
      - service: input_boolean.turn_off
        entity_id: input_boolean.ma_alarm_set
      - if:
          not:
            - condition: state
              entity_id: sensor.my_mobile_app_next_alarm
              state: "unavailable"
        then:
          - service: media_player.volume_set
            data:
              entity_id: "{{ states('sensor.last_alexa') }}" 
              volume_level: 0.5
          - service: notify.alexa_media
            data:
              target:
                - "{{ states('sensor.last_alexa') }}" 
              data:
                type: tts 
              message: "There is already an alarm set on your phone"
        else:
          - service: media_player.volume_set
            data:
              entity_id: "{{ states('sensor.last_alexa') }}"
              volume_level: 0.5
          - service: script.activate_alexa_actionable_notification
            data:
              alexa_device: "{{ states('sensor.last_alexa') }}" 
              event_id: actionable_notification_alarm_set
              text: >
                {% set hour_twentyfour = states('input_datetime.ma_alarm_set_time').split(':')[0]| int(0) %}
                {% set hour_twelve = hour_twentyfour if hour_twentyfour < 13 else hour_twentyfour - 12 %}
                {% set minutes = states('input_datetime.ma_alarm_set_time').split(':')[1] %}
                {% set minutes_formatted = minutes if minutes != '00' else '' %}
                {% set am_pm = 'am' if hour_twentyfour < 12 else 'pm' %}
                  Would you like me to set your alarm for {{hour_twelve}} {{minutes_formatted}} {{am_pm}}?
        
  - alias: MA Alarm Set From Response
    id: ma_alarm_set_from_response
    trigger:
      - platform: event
        event_type: alexa_actionable_notification
        event_data:
          event_id: actionable_notification_alarm_set
    condition:
      - condition: state
        entity_id: person.me
        state: 'home'
      - condition: state
        entity_id: sensor.my_mobile_app_next_alarm
        state: "unavailable"
    action:
      choose:
        - conditions:
            - '{{ trigger.event.data.event_response_type == "ResponseYes" or trigger.event.data.event_response_type == "ResponseNone" }}'
          sequence:
            - service: script.mobile_app_notification_command_set_alarm
            - wait_for_trigger:
                - platform: state
                  entity_id: sensor.my_mobile_app_next_alarm
                  from: "unavailable"
            - service: notify.alexa_media
              data:
                target:
                  - "{{ states('sensor.last_alexa') }}" 
                data:
                  type: tts 
                message: >
                  {% set hour_twentyfour = states('input_datetime.ma_alarm_set_time').split(':')[0]| int(0) %}
                  {% set hour_twelve = hour_twentyfour if hour_twentyfour < 13 else hour_twentyfour - 12 %}
                  {% set minutes = states('input_datetime.ma_alarm_set_time').split(':')[1] %}
                  {% set minutes_formatted = minutes if minutes != '00' else '' %}
                  {% set am_pm = 'am' if hour_twentyfour < 12 else 'pm' %}
                    OK, your alarm has been set to {{hour_twelve}} {{minutes_formatted}} {{am_pm}}
        - conditions:
            - '{{ trigger.event.data.event_response_type == "ResponseNo" }}'
          sequence:
            - service: script.activate_alexa_actionable_notification
              data:
                alexa_device: "{{ states('sensor.last_alexa') }}"
                event_id: actionable_notification_alarm_set_time_variable
                text: Would you like me to set your alarm for a different time?
  
  - alias: MA Alarm Set Variable Time From Response
    id: ma_alarm_set_variable_time_from_response
    trigger:
      - platform: event
        event_type: alexa_actionable_notification
        event_data:
          event_id: actionable_notification_alarm_set_time_variable
    condition:
      - condition: state
        entity_id: person.me
        state: 'home'
      - condition: state
        entity_id: sensor.my_mobile_app_next_alarm
        state: "unavailable"
    action:
      choose:
        - conditions:
            - '{{ trigger.event.data.event_response_type == "ResponseNo" or trigger.event.data.event_response_type == "ResponseNone" }}'
          sequence:
            - service: notify.alexa_media
              data:
                target:
                  - "{{ states('sensor.last_alexa') }}" 
                data:
                  type: tts 
                message: "OK, no alarm has been set"
        - conditions:
            - '{{ trigger.event.data.event_response_type == "ResponseYes" }}'
          sequence:
            - service: script.activate_alexa_actionable_notification
              data:
                alexa_device: "{{ states('sensor.last_alexa') }}"
                event_id: actionable_notification_alarm_set_time_for
                text: What time would you like it set for?
        
                
  - alias: MA Alarm Change Time Set From Response
    id: ma_alarm_change_time_set_from_response
    trigger:
      - platform: event
        event_type: alexa_actionable_notification
        event_data:
          event_id: actionable_notification_alarm_set_time_for
    condition:
      - condition: state
        entity_id: person.me
        state: 'home'
      - condition: state
        entity_id: sensor.my_mobile_app_next_alarm
        state: "unavailable"
    action:
      choose:
        - conditions:
            - '{{ 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.ma_alarm_set_time
            - delay: '00:00:02'
            - service: script.mobile_app_notification_command_set_alarm
            - wait_for_trigger:
                - platform: state
                  entity_id: sensor.my_mobile_app_next_alarm
                  from: "unavailable"
            - service: notify.alexa_media
              data:
                target:
                  - "{{ states('sensor.last_alexa') }}"
                data:
                  type: tts 
                message: >
                  {% set hour_twentyfour = states('input_datetime.ma_alarm_set_time').split(':')[0]| int(0) %}
                  {% set hour_twelve = hour_twentyfour if hour_twentyfour < 13 else hour_twentyfour - 12 %}
                  {% set minutes = states('input_datetime.ma_alarm_set_time').split(':')[1] %}
                  {% set minutes_formatted = minutes if minutes != '00' else '' %}
                  {% set am_pm = 'am' if hour_twentyfour < 12 else 'pm' %}
                    OK, your alarm has been set to {{hour_twelve}} {{minutes_formatted}} {{am_pm}}
        - conditions:
            - '{{ trigger.event.data.event_response_type == "ResponseNone" }}'
          sequence:
            - service: notify.alexa_media
              data:
                target:
                  - "{{ states('sensor.last_alexa') }}"
                data:
                  type: tts 
                message: "OK, no alarm has been set"

I believe I tried it your way with ResponseNumeric but found it too confusing to have to say something like six hundred fifteen or six one five. I changed instead to let Alexa’s built-in set alarm processing via media_content_id but that won’t work for you since you’re setting an alarm on your phone, not an Echo.

Anyways, here is my Good Night script:

alias: Good Night
sequence:
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id:
        - input_boolean.sleep_mode
        - input_boolean.bedroom_automatic_lights
  - if:
      - condition: state
        entity_id: input_boolean.coffee_prepared
        state: "off"
    then:
      - service: script.activate_alexa_actionable_notification
        data:
          text: Did you prepare your coffee?
          event_id: actionable_notification_coffee_prepared
          alexa_device: "{{ states(\"sensor.last_alexa\") }}"
      - wait_for_trigger:
          - platform: event
            event_type: alexa_actionable_notification
        timeout: "00:00:20"
  - service: media_player.turn_off
    target:
      area_id:
        - bedroom
        - living_room
    data: {}
  - service: light.turn_off
    target:
      area_id:
        - bathroom
        - front_door
        - garage
        - living_room
        - office
    data: {}
  - if:
      - condition: not
        conditions:
          - condition: state
            entity_id: climate.living_room
            attribute: preset_mode
            state: eco
    then:
      - service: climate.set_preset_mode
        continue_on_error: true
        data:
          preset_mode: eco
        entity_id: climate.living_room
      - service: notify.alexa_media_last_called
        continue_on_error: true
        data:
          message: Furnace is now in echo mode
          data:
            type: tts
      - delay:
          hours: 0
          minutes: 0
          seconds: 3
          milliseconds: 0
  - if:
      - condition: state
        entity_id: lock.front_door_lock
        state: unlocked
    then:
      - service: lock.lock
        data: {}
        target:
          entity_id: lock.front_door_lock
      - service: notify.alexa_media_last_called
        data:
          message: The front door was unlocked but I locked it for you.
          data:
            type: tts
      - delay:
          hours: 0
          minutes: 0
          seconds: 3
          milliseconds: 0
  - if:
      - condition: state
        entity_id: cover.garage_door
        state: open
    then:
      - if:
          - condition: state
            entity_id: sensor.season
            state: summer
        then:
          - service: notify.alexa_media_last_called
            continue_on_error: true
            data:
              message: Hey. Did you know the garage door is open?
              data:
                type: tts
          - delay:
              hours: 0
              minutes: 0
              seconds: 2
              milliseconds: 0
        else:
          - service: cover.close_cover
            data:
              entity_id: cover.garage_door
          - service: notify.alexa_media_last_called
            continue_on_error: true
            data:
              message: I closed the garage door for you
              data:
                type: tts
          - delay:
              hours: 0
              minutes: 0
              seconds: 2
              milliseconds: 0
  - choose:
      - conditions:
          - condition: state
            entity_id: input_boolean.garbage_is_out
            state: "off"
          - condition: or
            conditions:
              - condition: and
                conditions:
                  - condition: state
                    entity_id: sensor.garbage
                    state: "0"
                  - condition: time
                    before: "09:00:00"
                    weekday:
                      - wed
                    after: "00:00:00"
              - condition: and
                conditions:
                  - condition: state
                    entity_id: sensor.garbage
                    state: "1"
                  - condition: time
                    after: "12:00:00"
                    weekday:
                      - tue
                    before: "00:00:00"
        sequence:
          - service: script.activate_alexa_actionable_notification
            data:
              text: Did you put the garbage out?
              event_id: actionable_notification_garbage_pickup
              alexa_device: "{{ states(\"sensor.last_alexa\") }}"
          - wait_for_trigger:
              - platform: event
                event_type: alexa_actionable_notification
            timeout: "00:00:10"
          - delay:
              hours: 0
              minutes: 0
              seconds: 1
              milliseconds: 0
    default: []
  - choose:
      - conditions:
          - condition: state
            entity_id: input_boolean.recycling_is_out
            state: "off"
          - condition: or
            conditions:
              - condition: and
                conditions:
                  - condition: state
                    entity_id: sensor.richmond_recycling
                    state: "0"
                  - condition: time
                    before: "09:00:00"
                    weekday:
                      - thu
                      - fri
                    after: "00:00:00"
              - condition: and
                conditions:
                  - condition: state
                    entity_id: sensor.richmond_recycling
                    state: "1"
                  - condition: time
                    after: "12:01:00"
                    weekday:
                      - wed
                      - thu
                    before: "00:00:00"
        sequence:
          - service: script.activate_alexa_actionable_notification
            data:
              text: Did you put the recycling out?
              event_id: actionable_notification_recycling_pickup
              alexa_device: "{{ states(\"sensor.last_alexa\") }}"
          - wait_for_trigger:
              - platform: event
                event_type: alexa_actionable_notification
            timeout: "00:00:10"
          - delay:
              hours: 0
              minutes: 0
              seconds: 1
              milliseconds: 0
    default: []
  - service: script.enable_alarm
    data: {}
  - service: media_player.play_media
    continue_on_error: true
    data:
      media_content_id: Alexa.GoodNight.Play
      media_content_type: sequence
    target:
      entity_id: "{{ states(\"media_player.last_alexa\") }}"
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - service: light.turn_off
    data:
      transition: 30
    target:
      entity_id: light.bedroom_lamps
mode: single
icon: hass:weather-night

Near the end I call script.enable_alarm:

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

And the actionable_notification_enable_alarm automation which then triggers Alexa’s built-in handling for set alarm:

alias: Actionable - Enable Alarm
description: ""
trigger:
  - platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: actionable_notification_enable_alarm
      event_response_type: ResponseYes
condition: []
action:
  - service: media_player.play_media
    data:
      media_content_type: custom
      media_content_id: set alarm
    target:
      entity_id: "{{ states.sensor.last_alexa.state }}"
mode: single

Also note that I follow my service: script.activate_alexa_actionable_notification calls with a wait_for_trigger and timeout:'s and then proceed as if ResponseNone. I am not sure now why I chose that route.

The only sequence I have which used to use ResponseNone was when I arrive home which opens the garage, waits for the car to power off and then asks if I want to close the garage door. I say used to because I disabled ResponseNone as I decided I prefer to only close it if I say Yes. But ResponseNone did work before and I was not using wait_for_trigger and a timeout:.

alias: Clarity Arrives
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.honda_clarity_presence
    id: Clarity Zigbee Sensor
    to: "on"
    from: "off"
  - platform: state
    entity_id:
      - binary_sensor.close_to_home
    id: Close to Home
    to: "on"
    enabled: true
    from: "off"
condition:
  - condition: state
    entity_id: cover.garage_door
    state: closed
    for:
      hours: 0
      minutes: 0
      seconds: 0
  - condition: state
    entity_id: binary_sensor.clarity_in_garage
    state: "off"
  - condition: or
    conditions:
      - condition: trigger
        id: Clarity Zigbee Sensor
      - condition: and
        conditions:
          - condition: trigger
            id: Close to Home
          - condition: state
            entity_id: binary_sensor.clarity_bluetooth
            state: "on"
          - condition: not
            conditions:
              - condition: state
                entity_id: sensor.direction_of_travel
                state: away_from
action:
  - service: notify.mobile_app_p30_pro
    data:
      message: TTS
      data:
        media_stream: alarm_stream_max
        tts_text: The garage door is open
  - service: notify.pushover
    data:
      title: Arrived - Door opened
      message: |
        Triggered by {{ trigger.id }}
        from {{ trigger.from_state.state }}
        to {{ trigger.to_state.state }}
      data:
        priority: 0
  - service: input_text.set_value
    data:
      value: "{{trigger.id}}"
    target:
      entity_id: input_text.clarity_arrived
    continue_on_error: true
  - service: switch.turn_on
    data: {}
    target:
      entity_id:
        - switch.car_charger
  - service: cover.open_cover
    data: {}
    target:
      entity_id: cover.garage_door
  - wait_for_trigger:
      - platform: state
        entity_id:
          - binary_sensor.honda_clarity_real_power
        to: "off"
    timeout: "00:05:00"
  - service: script.activate_alexa_actionable_notification
    data:
      text: Shall I close the garage door?
      event_id: actionable_notification_garage_door_open
      alexa_device: media_player.garage_echo_dot
mode: single
max_exceeded: silent
alias: Actionable - Close the garage
description: ""
trigger:
  - platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: actionable_notification_garage_door_open
      event_response_type: ResponseYes
  - platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: actionable_notification_garage_door_open
      event_response_type: ResponseNone
    enabled: false
condition:
  - condition: state
    entity_id: cover.garage_door
    state: open
action:
  - service: cover.close_cover
    data: {}
    target:
      entity_id: cover.garage_door
mode: single

When I have more time I will duplicate your automations/scripts and try and debug, if you don’t figure it out in the meantime!

Can you post your script.mobile_app_notification_command_set_alarm ?

It sounds like Alexa is still processing a previous actionable notification which eventually triggers a ResponseNone when it times out, but I cannot find what that timeout period defaults to. Might it be a delay in the processing of the mobile app set alarm??

I had to add script/automation delays for other operations where she just speaks as HA would proceed ahead after calling the TTS and the next TTS would cut off the one in progress. Not saying that is what is happening here exactly but thought it worth throwing out there.

I’ve added your automations but will need your script to complete the process…

I would be OK with that if I could get that far but I can’t even get it to listen for that response.

It does sound like a delay but I can’t see the source of the delay.

Everything before it happens pretty much in real time. And there doesn’t even seem to be a “listen for response” action happening for the last event.

And there is definitely no alarm being set action that it’s waiting on because it hasn’t received the response to know whether an alarm needs set or not at that time. It never even triggers that last automation according to the debug trace.

Here is the script:

script:
  mobile_app_notification_command_set_alarm:
    alias: Mobile App Android Notification Command Set Alarm
    mode: restart
    sequence:
      - service: notify.mobile_app_mobile_app
        data:
          message: "command_activity"
          data:
            tag: android.intent.action.SET_ALARM
            group: |
              {% set timelist = states('input_datetime.ma_alarm_set_time').split(':') %}
              {% set timehour = timelist[0] %}
              {% set timemin = timelist[1] %}
              android.intent.extra.alarm.HOUR:{{timehour}},android.intent.extra.alarm.MINUTES:{{timemin}},android.intent.extra.alarm.SKIP_UI:true

Thanks for taking the time to look into it!

So, it is all working for me now up to the point of the script which does not set an alarm on my phone and my sensor.p30_pro_next_alarm still shows unavailable. If I manually create an alarm on my phone then the sensor correctly shows it:

I modified the final automation in the sequence to NOT continue on timeout with a timeout: 00:02:00 otherwise she blindly tells me the alarm was set.

Since I am a Mobile App Beta user I had to make two changes to the script:
image

The script result:

Executed: August 11, 2022 at 5:32:36 PM
Result:
params:
  domain: notify
  service: mobile_app_p30_pro
  service_data:
    message: command_activity
    data:
      intent_action: android.intent.action.SET_ALARM
      intent_extras: >-
        android.intent.extra.alarm.HOUR:07,android.intent.extra.alarm.MINUTES:30,android.intent.extra.alarm.SKIP_UI:true
  target: {}
running_script: false
limit: 10

But my HA App (Beta Version) Active Notification list is incorrect:

The portions that actually set an alarm on the phone all work as expected for me.

But the issue is that it never seems to even listen for the response to “what time…?”.

I’ll try adding the timeout and not continue and see where that gets me. I can see that it would solve the issue of the spurious “no alarm has been set” followed by “an alarm has been set” actions.

But I don’t think it will solve the not listening for a response at all portion.

I’m at work until tomorrow morning so I’ll let you know how it goes and what changes, if any.

Here is the modified final automation:

  - alias: MA Alarm Change Time Set From Response
    id: ma_alarm_change_time_set_from_response
    trigger:
      - platform: event
.
.
    action:
      choose:
        - conditions:
            - '{{ 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.ma_alarm_set_time
            - delay: '00:00:02'
            - service: script.mobile_app_notification_command_set_alarm
            - wait_for_trigger:
                - platform: state
                  entity_id: sensor.my_mobile_app_next_alarm
                  from: "unavailable"
              timeout:                                 # <-- added this
                seconds: 30                       
              continue_on_timeout: false   # <-- and this
            - service: notify.alexa_media
              data:
                target:
                  - "{{ states('sensor.last_alexa') }}"
                data:
                  type: tts 
                message: >
                  {% set hour_twentyfour = states('input_datetime.ma_alarm_set_time').split(':')[0]| int(0) %}
                  {% set hour_twelve = hour_twentyfour if hour_twentyfour < 13 else hour_twentyfour - 12 %}
                  {% set minutes = states('input_datetime.ma_alarm_set_time').split(':')[1] %}
                  {% set minutes_formatted = minutes if minutes != '00' else '' %}
                  {% set am_pm = 'am' if hour_twentyfour < 12 else 'pm' %}
                    OK, Jeff's alarm has been set to {{hour_twelve}} {{minutes_formatted}} {{am_pm}}
        - conditions:
            - '{{ trigger.event.data.event_response_type == "ResponseNone" }}'
          sequence:
            - service: notify.alexa_media
              data:
                target:
                  - "{{ states('sensor.last_alexa') }}"
                data:
                  type: tts 
                message: "OK, no alarm has been set"

is that what you had intended?

I’ve resolved my issue with the alarm not setting on my phone. With the mobile app open I executed the service call and was prompted to enable the permission to Draw over other apps. The next service call then triggered the phone option Open with Clock (default) or Sleep as Android, Just Once or Always. I picked Clock, Always and then the alarm was added.

Below are my current automations and script.
In the third automation, I modified the trigger: section with my preferred way to handle actionable notifications. By separating the triggers and labelling them with id: I can use use choose: conditions based on the trigger id I defined. Your templated way should work though.

Are you seeing the ResponseNumeric in the Event Listener?

alias: DB Alarm Ask to Set Manually
trigger:
  - platform: state
    entity_id: input_boolean.db_alarm_set
    to: "on"
condition:
  - condition: state
    entity_id: person.daniel_brunt
    state: home
action:
  - delay: "00:00:02"
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id:
        - input_boolean.db_alarm_set
  - if:
      - condition: not
        conditions:
          - condition: state
            entity_id: sensor.p30_pro_next_alarm
            state: unavailable
    then:
      - service: media_player.volume_set
        data:
          entity_id: "{{ states('sensor.last_alexa') }}"
          volume_level: 0.5
      - service: notify.alexa_media
        data:
          target:
            - "{{ states('sensor.last_alexa') }}"
          data:
            type: tts
          message: There is already an alarm set
    else:
      - service: media_player.volume_set
        data:
          entity_id: "{{ states('sensor.last_alexa') }}"
          volume_level: 0.5
      - service: script.activate_alexa_actionable_notification
        data:
          alexa_device: "{{ states('sensor.last_alexa') }}"
          event_id: actionable_notification_alarm_set
          text: >
            {% set hour_twentyfour =
            states('input_datetime.ma_alarm_set_time').split(':')[0]| int(0) %}
            {% set hour_twelve = hour_twentyfour if hour_twentyfour < 13 else
            hour_twentyfour - 12 %} {% set minutes =
            states('input_datetime.ma_alarm_set_time').split(':')[1] %} {% set
            minutes_formatted = minutes if minutes != '00' else '' %} {% set
            am_pm = 'am' if hour_twentyfour < 12 else 'pm' %}
              Would you like me to set your alarm for {{hour_twelve}} {{minutes_formatted}} {{am_pm}}?
alias: DB Alarm Set From Response
trigger:
  - platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: actionable_notification_alarm_set
condition:
  - condition: state
    entity_id: person.daniel_brunt
    state: home
  - condition: state
    entity_id: sensor.p30_pro_next_alarm
    state: unavailable
action:
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ trigger.event.data.event_response_type == "ResponseYes" or
              trigger.event.data.event_response_type == "ResponseNone" }}
        sequence:
          - service: script.mobile_app_notification_command_set_alarm
            data: {}
          - wait_for_trigger:
              - platform: state
                entity_id:
                  - sensor.p30_pro_next_alarm
                from: unavailable
          - service: notify.alexa_media
            data:
              target:
                - "{{ states('sensor.last_alexa') }}"
              data:
                type: tts
              message: >
                {% set hour_twentyfour =
                states('input_datetime.db_alarm_set_time').split(':')[0]| int(0)
                %} {% set hour_twelve = hour_twentyfour if hour_twentyfour < 13
                else hour_twentyfour - 12 %} {% set minutes =
                states('input_datetime.db_alarm_set_time').split(':')[1] %} {%
                set minutes_formatted = minutes if minutes != '00' else '' %} {%
                set am_pm = 'am' if hour_twentyfour < 12 else 'pm' %}
                  OK, your alarm has been set to {{hour_twelve}} {{minutes_formatted}} {{am_pm}}
      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.event_response_type == \"ResponseNo\" }}"
        sequence:
          - service: script.activate_alexa_actionable_notification
            data:
              alexa_device: "{{ states('sensor.last_alexa') }}"
              event_id: actionable_notification_alarm_set_time_variable
              text: Would you like me to set your alarm for a different time?
alias: DB Alarm Set Variable Time From Response
trigger:
  - platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: actionable_notification_alarm_set_time_variable
condition:
  - condition: state
    entity_id: person.daniel_brunt
    state: home
  - condition: state
    entity_id: sensor.p30_pro_next_alarm
    state: unavailable
action:
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ trigger.event.data.event_response_type == "ResponseNo" or
              trigger.event.data.event_response_type == "ResponseNone" }}
        sequence:
          - service: notify.alexa_media
            data:
              target:
                - "{{ states('sensor.last_alexa') }}"
              data:
                type: tts
              message: OK, no alarm has been set
      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.event_response_type == \"ResponseYes\" }}"
        sequence:
          - service: script.activate_alexa_actionable_notification
            data:
              alexa_device: "{{ states('sensor.last_alexa') }}"
              event_id: actionable_notification_alarm_set_time_for
              text: What time would you like it set for?
alias: DB Alarm Change Time Set From Response
trigger:
  - platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: actionable_notification_alarm_set_time_for
      event_response_type: ResponseNone
    id: ResponseNone
  - platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: actionable_notification_alarm_set_time_for
      event_response_type: ResponseNumeric
    id: ResponseNumeric
condition:
  - condition: state
    entity_id: person.daniel_brunt
    state: home
  - condition: state
    entity_id: sensor.p30_pro_next_alarm
    state: unavailable
action:
  - choose:
      - conditions:
          - condition: trigger
            id: 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.db_alarm_set_time
          - delay:
              hours: 0
              minutes: 0
              seconds: 2
              milliseconds: 0
          - service: script.mobile_app_notification_command_set_alarm
            data: {}
          - wait_for_trigger:
              - platform: state
                entity_id:
                  - sensor.p30_pro_next_alarm
                from: unavailable
            timeout: "00:02:00"
            continue_on_timeout: false
          - service: notify.alexa_media
            data:
              target:
                - "{{ states('sensor.last_alexa') }}"
              data:
                type: tts
              message: >
                {% set hour_twentyfour =
                states('input_datetime.db_alarm_set_time').split(':')[0]| int(0)
                %} {% set hour_twelve = hour_twentyfour if hour_twentyfour < 13
                else hour_twentyfour - 12 %} {% set minutes =
                states('input_datetime.db_alarm_set_time').split(':')[1] %} {%
                set minutes_formatted = minutes if minutes != '00' else '' %} {%
                set am_pm = 'am' if hour_twentyfour < 12 else 'pm' %}
                  OK, your alarm has been set to {{hour_twelve}} {{minutes_formatted}} {{am_pm}}
      - conditions:
          - condition: trigger
            id: ResponseNone
        sequence:
          - service: notify.alexa_media
            data:
              target:
                - "{{ states('sensor.last_alexa') }}"
              data:
                type: tts
              message: OK, no alarm has been set
alias: Mobile App Notification Command Set Alarm
sequence:
  - service: notify.mobile_app_p30_pro
    data:
      message: command_activity
      data:
        intent_action: android.intent.action.SET_ALARM
        intent_extras: >
          {% set timelist =
          states('input_datetime.db_alarm_set_time').split(':') %}
          {% set timehour = timelist[0] %}
          {% set timemin = timelist[1] %}
          android.intent.extra.alarm.HOUR:{{timehour}},android.intent.extra.alarm.MINUTES:{{timemin}},android.intent.extra.alarm.SKIP_UI:true
mode: single

No.

and the light ring turns off immediately after it asks the “what time…?” question.

but on the prior runs the light ring stays lit awaiting the responses.

Just to clarify…did the automations you posted above work for you as expected to set the alarm to a variable set time?

Yes. I can answer seven forty five, seven four five, eight zero zero, eight hundred and they all are correct.

I just finished editing 4 instances of input_datetime.ma_alarm_set_time to …datetime.db_… but that only affected the spoken confirmations of the time set (she was saying Zero)

It sounds like something got messed up in the HA automation engine. I had one run through where a delay: 00:00:02 said cancelled after 1.82 seconds and the rest of the automation did not execute. Scratched my head over that one! Made some more edits and I’ve done like 6 or 8 run throughs since then and everything is okay. Maybe try restarting HA or at least reload automations & scripts?

I’d sort the automations by Triggered oldest->newest and review each automation’s debug closely…

Hey, do you think you’re talking to a noob here!? :face_with_raised_eyebrow:

:laughing:

But seriously, I’ve restarted/reloaded more times than I can remember.

I’ll try your automations exactly (modified for my entities) and see if it works.

as for the automation trace the last one always says last triggered is “never”.

I’ll keep you updated either way.

:laughing:

That’s the problem, but Why? is the $64M question…

Yup. agreed.

That’s why I was wondering if there was some sort of max question/response in a time frame that I was coming up against. But it doesn’t sound like it since you say your automations are working.

I haven’t tested my variations of your automations yet tho to see where I stand.

How about a simple test?

Dev Tools, Events, Listen to events: alexa_actionable_notification
Dev Tools, Services:

service: script.activate_alexa_actionable_notification
data:
  alexa_device: "{{ states('sensor.last_alexa') }}"
  event_id: actionable_notification_response_numeric_test
  text: What time would you like it set for?

If that fails to show in Event Listener then the problem might be with your Alexa skill?

Well, I tried both the copied automations and tried your test and in none of them did the system react to a numeric response.

it reacted to a yes and a no response but never a numeric response.

And when I gave it no response it never registered that response until I ran the same test script again and then it finally popped up with a ResponseNone event.

Definitely some strangeness going on there.

So it must be something wrong in the skill.

Do you have any insight as to what that might be?

No, I currently do not.

Definitely. I am having some strangeness myself but in a different item - Alexa Media Player, which has been happening off and on for a couple of months. This morning, I initiated my Good Morning script via Alexa and it failed to complete. This portion executed:


but this did not say anything, and the rest of script did not run: