Struggling with custom intent

I’m trying to create a custom intent that changes the value of an input_number helper.

In my sentences/en/jarvis.yaml file I have

language: "en"
intents:
  SetCarBatteryLevel:
    data:
      - sentences:
          - "set the car battery to seventy percent"

and in my intent_script I have

intent_script:
  SetCarBatteryLevel:
    action:
      - action: input_number.set_value
        target:
          entity_id: input_number.car_battery_charge_level
        data:
          value: 70

If I ask Assist to “set the car battery charge level to 70%” it does exactly that.

How do I make the value part a variable that is captured by the custom sentence and passed to the intent script?

I’ve tried using trigger slots, as in

  SetCarBatteryLevel:
    data:
      - sentences:
          - "set the car battery charge level to {value} percent"

and

 SetCarBatteryLevel:
    action:
      - action: input_number.set_value
        target:
          entity_id: input_number.car_battery_charge_level
        data:
          value: "{{trigger.slots.value}}"

but that didn’t work and the intent was not processed locally.

To set my heating I have:

CustomSetTemperature:
  action:
    - service: climate.set_temperature
      data:
        temperature: "{{ temp }}"
      target:
        entity_id: climate.hallway

Edit: Sorry, should have included the sentence:

language: "en"
intents:
  CustomSetTemperature:
    data:
      - sentences:
          - "(set|change) [the] (temperature | heating | thermostat) to {temp} [degrees]"
lists:
  temp:
    range:
      from: 0
      to: 35

Yeah, I also tried

SetCarBatteryLevel:
  action:
    - action: input_number.set_value
      target:
        entity_id: input_number.car_battery_charge_level
      data:
        value: "{{ value }}"

that didn’t work. I know setting a fixed number works so it’s just getting the variable right.

If you are using yaml, you need to set the type of the variable.
For example

lists:
  value :
    range:
      from: 0
      to: 100

Also check which way numbers are recognized, as words or as digits.

I tried that too

  SetCarBatteryLevel:
    data:
      - sentences:
          - "(set|change) [the] car (battery|battery level) to {value} [percent]"
        requires_context:
          domain: "input_number"
        lists:
          value:
            range:
              from: 0
              to: 100

I think this might be the root of the issue. If I simply put

    - action: input_number.set_value
      target:
        entity_id: input_number.car_battery_charge_level
      data:
        value:  70

in the intent script, it clearly recognises 70 as a number. However, if I try to use a wildcard such as {value} then instead of the number 70, put {{value}} in the intent script, am I hitting a formatting issue where the {{value}} variable is rendered as a something other than a number. In which case, something like {{value|int}} should work. But if that’s the case, why does {temp} and {{temp}} work in @jackjourneyman example work?

I did wonder if it’s because there is already a built-in intent to change the temperature of a climate entity, but there is no built-in intent that can change the value of an input_number helper.

If other commands with numeric values work, there is nothing wrong with the format.
Try removing

        requires_context:
          domain: "input_number"

Your phrase is unique enough that it won’t conflict with the built-in intents.
If that doesn’t help either, do the automation in the GUI, there’s less chance of error there, and all new variables are automatically assigned the wildcard type

Okay, this is interesting.

In my custom_sentences/en/jarvis.yaml file I have

language: "en"
intents:
  SetCarBatteryLevel:
    data:
      - sentences:
          - "(set|change) [the] car (battery charge|battery charge level) to {value} [percent]"
        lists:
          value:
            range:
              from: 0
              to: 100

Now when I use the Assist sentence parser in Developer Tools to test the sentence by typing “set the car battery charge level to 90 percent” I get the following result:

intent:
  name: SetCarBatteryLevel
slots:
  value: '90'
details:
  value:
    name: value
    value: 90
    text: '90'
targets: {}
match: true
sentence_template: >-
  (set|change) [the] car (battery charge|battery charge level) to {value}
  [percent]
unmatched_slots: {}
source: custom
file: en/jarvis.yaml

So the intent is being correctly recognised. It’s obviously what I have in the intent_script that is not being correctly processed.

Here’s what’s in the intent_script.

First of all , my intent_script is in a file called intent_script.yaml which is correctly located in the homeassistant/ directory. I have correctly pointed my config towards it by having the line
intent_script: !include intent_script.yaml
Inside the intent_script.yaml file I have

  SetCarBatteryLevel:
    action:
      - action: input_number.set_value
        target:
          entity_id: input_number.car_battery_charge_level
        data:
          value: "{{ value }}"

and it still doesn’t work!

Okay, I’m closing this one off here. I could not get the custom sentence and intent in a script to work so I went for an automation instead.

It took a bit of digging to get the right variable to use and to strip off the % sign after the number, but this automation works.

alias: Set Car Battery Level via Assist
triggers:
  - command:
      - >-
        (set|change) [the] car (battery charge|battery charge level) to {number}
        [percent]
    trigger: conversation
conditions: []
actions:
  - variables:
      level: "{{ trigger.slots['number'] | regex_replace('%', '') | int }}"
  - target:
      entity_id: input_number.car_battery_charge_level
    data:
      value: "{{ level }}"
    action: input_number.set_value
mode: single