How to Tell Alexa to Set the Value of an Input Number

I am running Hassio on a Rasberry Pi, integrated with Alexa (an Echo Dot) via Haaska.

I have several input numbers in my config.yaml that I use to change the parameters of some of my scripts. I would like the ability to change an input number by telling Alexa to do so (rather than via Lovelace).

I found these two posts that seem to say that this can be done with a simple script (one them uses “input_slider”, which I believe is now the “input_number” component):

Based on these examples, I have the following in my config.yaml:

    name: Charging Time
    min: 1
    max: 8
    step: 1

And this for a script:

    - service: input_number.set_value
        entity_id: input_number.time_charging
        value: "{{ requested_level }}"

The script “Charging Time” shows up in my Alexa app as a scene.

However, when I say " Alexa, set Charging Time to 5," Alexa replies “Charging Time doesn’t support that.”

Any idea what I am doing wrong?

1 Like

What does
say about time_charging?
(replace with the ip-adress of your hass installation)

This resulted in web page that just says “404 Not Found.”

Upss…I’m sorry, I thought you use the hue emulation!


Would really like to set this up if possible.

Did you get anywhere with this? I also have a use case (allowing my son to delete a variable number of chapters from an audiobook playlist so he doesn’t have to spend 10 minutes telling Alexa to skip forward one chapter at a time…)

I found a workaround using a light. Lights have 2 different attributes for brightness. There is “brightness” which is a value from 1 to 255 and “brightness_pct” which is the same value expressed as a percentage. That is, brightness_pct = brightness / 2.55 (e.g., brightness of 26 = brightness_pct of 10). When you tell Alexa to “set [light name] to X” it sets the light to X% brightness. Thus, you can give your light whatever name you want, and then have an automation that sets the value of an input number based on the brightness (or brightness_pct) of the light.

Here is a sample:

- id: 'set_charging_hours'
  alias: 'Set Charging Hours'
    platform: state
    entity_id: light.charging_hours
  - condition: template
    value_template: "{{ (states.light.charging_hours.attributes.brightness|int) > 1 }}"
  - service: input_number.set_value
      entity_id: input_number.charger_hours
      value: "{{ (states.light.charging_hours.attributes.brightness|int /2.55)|round(0) }}"
  - service: light.turn_on
      entity_id: light.virt_light_charging
      brightness: 1

Three things to note. First, at the end of the automation, set brightness (not brightness_pct) equal to 1. This last step is necessary if you want to specify the same value two times in a row. I.e., without the last step, if you told Alexa to “Set [light name] to 4” two times in a row, it would work the first time, but the second time would not create a change in the state of the light (because it is already at 4%).
So the automation would not trigger.

Second, the condition at the beginning that brightness be > 1 is necessary to prevent the above-described last step from triggering the automation all over again.

Finally, this code will not work if you want to set the input number to zero. A brightness_pct of zero means the light is off, and if the light is off then HA thinks that the light has no brightness (or brightness_pct) attribute. So if you want to be able to set a number to zero, you would need some additional code.