A way to instruct HA in automation to take and convert a spoken number

Since I can say to ASSIST something like “open cover to fifty percent”, THERE must be already an automatic conversion from a spoken number into an integer or a float.

In my case I defined a Sentence triggered automation which should take an intent and a number like “set X to thirtyfive seconds”, having X to be a number_sensor to be set to 35 (not “thirtyfife”…) .

  1. How should I define the sentence to catch that number? Like e.g. “set X to {seconds} seconds”
  2. How can I ensure that X be set to the integer or float representation of the spoken number (here seconds)?

Thank you so much in advance for any hints.

PS: The followint does not function and does not even tell why not:

actions:

  • target:
    entity_id: input_number.X
    data:
    value: “{{ trigger.event.data.variables.seconds | int }}”

The Assist (executing this) says just “Done” Which must be a kind of catch-all … and I suppose something wrong happens…

Not too clear what you’re trying to do, but we need to see the whole automation, and you’ll need to post it as preformatted text (</>) in the toolbar.

However, if you use a custom sentence and an intent script you can define the number slot as a range and it will always be passed to the intent as a number, whatever the voice assistant “hears”.

language: "en"
intents:
  CustomAlarmclockSet:
    data:
      - sentences:
          - "set ( the | an ) alarm for {hour} {minute}" 
lists:
  hour:
    range:  
      from: 0
      to: 23  
  minute:
    range:
      from: 0
      to: 59

Thanks a lot for that, Jack.

here my “complete” automation:

alias: ASSIST RESPONSE Set Light Time Kitchen
triggers:
  - trigger: conversation
    command: Set light time of Kitchen to {seconds} seconds
actions:
  - target:
      entity_id: input_number.rip_cucina_inching_off_secs
    data:
      value: "{{ trigger.event.data.variables.seconds | int }}"
    action: input_number.set_value
  - set_conversation_response: >-
      Light time of kitchen set to {{
      trigger.event.data.variables.seconds }} seconds
mode: single

So basically I wish to set the spoken value (as number) in
input_number.rip_cucina_inching_off_secs

Sentence trigger variables don’t have a property called event

Available Trigger Data - Sentence Triggers

You should do automation (custom sentences) in YAML, as shown above. This is because lists for ranges only work there (the unicode-rbnf library is used).

1 Like

OK (thank you)

But then I still do not know where to change…
OK, event does not exists, so what should be the expression there?
How should I change my code?
It should not be too difficult… But since I do not know the implementation, I permit myself to ask here…

This is what I have understood (from your kind suggestions so far) to do:
NB: list cannot be entered in the yaml description of an automatioin.

alias: ASSIST RESPONSE Set Light Time Kitchen
triggers:
  - trigger: conversation
    command: Set light time of Kitchen to {seconds} seconds
actions:
  - target:
      entity_id: input_number.rip_cucina_inching_off_secs
    data:
      value: "{{ seconds | int }}"
    action: input_number.set_value
  - set_conversation_response: >-
      Light time of kitchen set to {{ seconds }} seconds
mode: single

But this won’t work. Any sugg what I shoud change here please?

As shown in the docs linked by mchk and myself, the property of the trigger variable is called slots.

alias: ASSIST RESPONSE Set Light Time Kitchen
triggers:
  - trigger: conversation
    command: Set light time of Kitchen to {seconds} seconds
actions:
  - target:
      entity_id: input_number.rip_cucina_inching_off_secs
    data:
      value: "{{ trigger.slots.seconds | int }}"
    action: input_number.set_value
  - set_conversation_response: >-
      Light time of kitchen set to {{ trigger.slots.seconds }} seconds
mode: single

Doing it this way will usually work, but it is possible that seconds gets returned as a string value like “thirteen” which will cause the action to fail. If you go with this, it would be prudent to add a default to the int filter to avoid those complete failures. Or you could use a kind-of silly template to convert them.

Using a custom intent like Jackjourneyman showed above is the more sure-fire method.

1 Like

Thank you Didgeridrew!

Without the set action (which indeed uses the text representation of a number instead of the number as integer), now the automation “reponds” with the right argument (seconds) as a text.

Now: I have a web service which translates a number as text into a json obj containing the corresponding number representation (because I need the number, not the speaking part).

It is in italian (because I am de-facto working on an italian speaking version)

example:
curl “http://localhost:6000/converti?numero=tremilaquattrocentotrepuntozerocinque

=>
{
“numero_parole”: “tremilaquattrocentotrepuntozerocinque”,
“risultato”: 3403.05,
“tipo”: “float”
}

So this would convert the spoken text-number into a float and hence I could set the number into the inching object.

HOW could I integrate this mircoservice with HA or with the automation so I get the conversion of the heard number please ?