[SOLVED] Increment Input Number by value of another Input Number

I am trying to create a counter of pills left in my medicine box.
For that use I have made two helpers:
input_number: Package_size
input_number: current_count

Now I have one automation that decrements the current_count by one, everytime I push a button when I have taken my medicine.
Now when I buy a new package I want another automation that adds the package size to the current_count.

For the sake of simplicity I have tried to harcode the number in the first place, but this doenst work:

service: input_number.increment
  step: 100
entity_id: input_number.current:count

The documentation of input_number.increment doesn’t tell me how to exactly use steps.

Any ideas?


I suggest you use an input_number’s set_value service. This example sets the value of input_number.current to 100.

      service: input_number.set_value
        entity_id: input_number.current
        value: 100

You can enhance it with a template that adds the new quantity of pills (let’s say 50) to the existing quantity of pills.

       value: "{{ states('input_number.current') | int + 50 }}"

If you have no need for the current value to be adjustable via the UI, you may want to use a counter instead of an input_number.

1 Like

Thanks for the hint. For a hard coded number this works like a charm now. But I don’t seem to get it working for another input Number. So instead of 50 how would the syntax be for adding a value of another Input Number?

I tried different options. For example:

value: "{{ states('input_number.current_count') | int + {{ states('input_number.package_size') | int + 50 }} }}"

but this doesn’t seem to work.

If you are attempting to add the value of input_number.package_size to the value of input_number.current_count then it’s done like this:

value: "{{ states('input_number.current_count') | int + states('input_number.package_size') | int }}"
1 Like

Hi - @123 provides, as usual :wink:, the correct syntax. You had an extra set of double braces that confused the interpreter.

One suggestion is to test templates in the developer template first (I always do that) to make sure it works correctly before implementing it. It’s a great testing feature provided by HA and might be the one I use the most for development…

Thank you so much. Working like a charm.
And also thanks for the tipp with the developer template

Glad to hear it solved the problem.

BTW, there’s an existing method to indicate a problem has been solved (as opposed to adding the word [Solved] to the title). Simply select the post that contains the solution (the one that revealed how to correct the problem) and tick its Solution tag. Only one post in the thread can be assigned the Solution tag and only you, the author of this topic, can select it (and the forum moderators).

After you have marked the post with the Solution tag, a link to the post will automatically appear below your first post. In addition, a check-mark will also appear next to the topic’s title. This helps other users, with similar questions, find answers.

I’m trying to do exactly this and it doesn’t seem to work…
what am I doing wrong?

  - type: service-button
    title: '+10'
      '--mdc-typography-button-font-size': 20px
      color: white
      '--mdc-theme-primary': '#dddddd'
      top: 77.5%
      left: 92%
    service: input_number.set_value
      entity_id: input_number.my_points
      value: "{{ states('input_number.my_points') | float + 10 }}"

(nb, tried int but it keeps giving me errors about a float, hence float at the moment

You’re using the Picture Elements card which is one of Home Assistant’s standard set of cards. None of the the standard cards support templates (except for the Markdown card). That’s why you’re getting an error message.

  1. Create a script that sets the input_number.
  2. Configure the button to call the script.
1 Like