Use duration spoken to Alexa in script

I’m trying to create the following automation:

  1. Ask Alexa to switch on a device e.g. Alexa, Switch on Fan
  2. Alexa replies with “For how long?”
  3. I reply with a duration, e.g. 3 minutes.
  4. The duration spoken to Alexa is saved to a varible so I can use it in a script or automation.

If anyone can provide a basic example that would be really helpful.

thanks

This thread should help. It’s basically the same thing you’re asking for.

Actionable Notifications via Alexa Media Player - Share your Projects! / Custom Integrations - Home Assistant Community (home-assistant.io)

Thanks for the link, it’s helped some but I’m struggling to get this working.

I have the Alexa Notification working and can capture the numeric response and have stored that in an Input Number.

The rest of the script now works using a manual value, but what I can’t work out is how to use the Number stored as a value further down the script.

The section of the script I need to use the value captured from Alexa is shown below where it is currently value: 4

  - device_id: 822dfb7c32020a633da369c0dd25b62f
    domain: number
    entity_id: e5c2313044351983c4a1e778de165be6
    type: set_value
    value: 4

I’ve tried various different combinations but it always generates an error.

Examples I have tried:

  - device_id: 822dfb7c32020a633da369c0dd25b62f
    domain: number
    entity_id: e5c2313044351983c4a1e778de165be6
    type: set_value
    value: >-
        {{ trigger.event.data.event_response| int(default=0) }}
  - device_id: 822dfb7c32020a633da369c0dd25b62f
    domain: number
    entity_id: e5c2313044351983c4a1e778de165be6
    type: set_value
    value: {{ states("input_number.microwave_run_time")|
        int(default=0) }}

Error:

Can anyone provide the correct format for this please?

Script:

alias: Start Microwave
sequence:
  - data: {}
    action: alexa_media.update_last_called
  - data_template:
      text: for how may minutes?
      event_id: actionable_notification_microwave
      alexa_device: media_player.lounge_2
    action: script.activate_alexa_actionable_notification
mode: single

Automation:

alias: Actionable - Start Microwave Full Power
description: ""
trigger:
  - platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: actionable_notification_microwave
      event_response_type: ResponseNumeric
condition: []
action:
  - action: input_number.set_value
    metadata: {}
    data_template:
      value: "{{ trigger.event.data.event_response| int(default=0) }}"
    target:
      entity_id: input_number.microwave_run_time
  - device_id: 822dfb7c32020a633da369c0dd25b62f
    domain: select
    entity_id: 49cd700ea40d009b9d12475457a4e425
    type: select_option
    option: Cooking.Oven.Program.Microwave.Max
  - device_id: 822dfb7c32020a633da369c0dd25b62f
    domain: number
    entity_id: e5c2313044351983c4a1e778de165be6
    type: set_value
    value: 4
  - device_id: 822dfb7c32020a633da369c0dd25b62f
    domain: button
    entity_id: dfdf41fd0fa9b71415c05c81ac8b89be
    type: press

What does the trace of the automation show?

The trace is fine when I simply have the value set manually, but there is no trace as I’m unable to save the changes to the YAML as the error I posted earlier comes up when I try and save it.

The error is likely due to the lack of quotes around your template and the use of Device actions.
Device triggers, conditions, and actions are meant for basic function and do not always support advanced tools like templating in all fields. You should use an Entity-based number.set_value action.

  - action: number.set_value
    data:
      value: "{{ states('input_number.microwave_run_time')|int(0) }}"
    target:
      entity_id: number.YOUR_ENTITY_HERE

I’m assuming I have update this correctly based on your reply?

I’m still getting and error when I try and save the yaml

alias: Actionable - Start Microwave Full Power
description: ""
trigger:
  - platform: event
    event_type: alexa_actionable_notification
    event_data:
      event_id: actionable_notification_microwave
      event_response_type: ResponseNumeric
condition: []
action:
  - action: input_number.set_value
    metadata: {}
    data_template:
      value: "{{ trigger.event.data.event_response| int(default=0) }}"
    target:
      entity_id: input_number.microwave_run_time
  - device_id: 822dfb7c32020a633da369c0dd25b62f
    domain: select
    entity_id: 49cd700ea40d009b9d12475457a4e425
    type: select_option
    option: Cooking.Oven.Program.Microwave.Max
  - action: number.set_value
    entity_id: number.383050426647027900_001_bsh_common_option_duration
    value: "{{ states('input_number.microwave_run_time')|int(0) }}"
  - device_id: 822dfb7c32020a633da369c0dd25b62f
    domain: button
    entity_id: dfdf41fd0fa9b71415c05c81ac8b89be
    type: press

Sorry, I did the conversion quickly and messed up the keys, I have fixed it above.