Alarm clock automation: intent and intent_script

Hi everybody, I made an automation that set an alarm. it works with 2 imput number and works well.

alias: Sveglia con input_number
description: Automazione per sveglia basata su input_number
triggers:
  - value_template: |
      {{ now().hour == states('input_number.sveglia_ora') | int and
         now().minute == states('input_number.sveglia_minuti') | int }}
    trigger: template
conditions: []
actions:
  - action: assist_satellite.announce
    metadata: {}
    data:
      message: SVEGLIA ATTIVATA è ORA DI SVEGLIARSI
    target:
      entity_id: assist_satellite.home_assistant_voice_0925d6_assist_satellite
mode: single

Now I want to set an intent and an intent_script to modify input_number.sveglia_ora and input_number.sveglia_minuti and toggle the automation, but i cannot figure out where is my mistake and if it is possible to do

Intent:

  ImpostaSveglia:
    data:
      - sentences:
          - "Imposta una sveglia alle {ore} e {minuti}"
          - "Metti una sveglia per le {ore}:{minuti}"
          - "Sveglia per le {ore} e {minuti}"
        slots:
          ore:
            type: number
          minuti:
            type: number

Intent_script:

  ImpostaSveglia:
    description: "Imposta una sveglia per l'orario specificato."
    action:
      - service: input_number.set_value
        target:
          entity_id: input_number.sveglia_ora
        data:
          value: "{{ trigger.variables.ore | int }}"
      - service: input_number.set_value
        target:
          entity_id: input_number.sveglia_minuti
        data:
          value: "{{ trigger.variables.minuti | int }}"
      - service: automation.turn_on
        target:
          entity_id: automation.sveglia_con_input_number
    speech:
      text: "Sveglia impostata per le {{ trigger.variables.ore }} e {{ trigger.variables.minuti }}."
     

Your trigger could be made simpler with an input date time with time only.
That way you can trigger with a time trigger

Thanks, the idea looks better. But Assist still not recognize the intent. I think I’m doing something wrong making the custom sentence or the intent script. The automation works good so I think there are some error on mapping the request

I m sorry I’m new in home assistant and I’m discovering lot of stuff every days

Calling variables is a little different
{{ trigger.slot.ore }} - in gui automation
{{ ore }} in intent_scripts

You must also define variables. see the example in the documentation
and remove slots block, it doesn’t seem right.

Thanks i read the documentation, now is better but i still have problems.

this is my custom intent i used

language: "it"
intents:
  ImpostaSveglia:
    data:
      - sentences:
          - "Imposta una sveglia alle {ore} e {minuti}"
          - "Metti una sveglia per le {ore}:{minuti}"
          - "Programma una sveglia alle {ore} e {minuti}"
          - "Metti la sveglia per le {ore} e {minuti}"
          - "Svegliami alle {ore}:{minuti}"
          - "Svegliami alle {ore} e {minuti}"

lists:
  ore:
    range:
      type: "number"
      from: 0
      to: 23
  minuti:
    range:
      type: "number"
      from: 0
      to: 59


this is my intent_script

intent_script:
  ImpostaSveglia:
    action:
      - service: input_datetime.set_datetime
        target:
          entity_id: input_datetime.sveglia
        data:
          time: >
            {% set ore = (intent.get("ore", 7) | int) %}
            {% set minuti = (intent.get("minuti", 0) | int) %}
            {{ '{:02d}:{:02d}'.format(ore, minuti) }}
      - service: automation.turn_on
        target:
          entity_id: automation.sveglia_con_input_datetime
    speech:
      text: >
        Sveglia impostata per le {{ intent.get("ore", 7) }}:{{ '{:02d}'.format(intent.get("minuti", 0) | int) }}.

and i have this error in log when i try to give the command to assist

Registratore: homeassistant.components.conversation.default_agent
Fonte: components/conversation/default_agent.py:456
Integrazione: Conversazione (documentazione, problemi)
Prima occorrenza: 06:20:59 (6 occorrenze)
Ultimo accesso: 07:14:16

Unexpected intent error
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 643, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2756, in _render_with_context
    return template.render(**kwargs)
           ~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/jinja2/environment.py", line 1295, in render
    self.environment.handle_exception()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/site-packages/jinja2/environment.py", line 942, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
TypeError: argument of type 'Context' is not iterable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 416, in async_prepare_call_from_config
    render = template.render_complex(config[conf], variables)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 260, in render_complex
    render_complex(key, variables, limited, parse_result): render_complex(
                                                           ~~~~~~~~~~~~~~^
        item, variables, limited, parse_result
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 266, in render_complex
    return value.async_render(variables, limited=limited, parse_result=parse_result)
           ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 645, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: TypeError: argument of type 'Context' is not iterable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/intent.py", line 145, in async_handle
    result = await handler.async_handle(intent)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/intent_script/__init__.py", line 243, in async_handle
    action_res = await action.async_run(slots, intent_obj.context)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1808, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 464, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 528, in _async_step
    self._handle_exception(
    ~~~~~~~~~~~~~~~~~~~~~~^
        ex, continue_on_error, self._log_exceptions or log_exceptions
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 558, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 526, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 735, in _async_call_service_step
    params = service.async_prepare_call_from_config(
        self._hass, self._action, self._variables
    )
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 423, in async_prepare_call_from_config
    raise HomeAssistantError(f"Error rendering data template: {ex}") from ex
homeassistant.exceptions.HomeAssistantError: Error rendering data template: TypeError: argument of type 'Context' is not iterable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/conversation/default_agent.py", line 456, in _async_process_intent_result
    intent_response = await intent.async_handle(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<10 lines>...
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/intent.py", line 153, in async_handle
    raise IntentUnexpectedError(f"Error handling {intent_type}") from err
homeassistant.helpers.intent.IntentUnexpectedError: Error handling ImpostaSveglia

the problem is that i cannot let the sistem use the variables Hour and minutes and give to intent script

you don’t need to use the type option

lists:
  ore:
    range:
      from: 0
      to: 23

Тhis construction raises many questions, check it in devtools-template (insert numeric values instead of variables).

{{ intent.get("ore", 7) }}:{{ '{:02d}'.format(intent.get("minuti", 0) | int) }}

And don’t use quotes for variables in the response