Can't work out how to increment using input_number.set_value

Hi, I am trying to increment a number by a variable (amount) for all input_numbers in my test label.

I cannot seem to get the current entities state however
I thought this would be possible with something like:

service: input_number.set_value
  label_id: test
  value: >-
    {{ entity.state|float + amount|float }}

Any ideas?

Use the increment function amount times?

service: input_number.increment
  label_id: test

That only increments it by 1 not an amount!

Yeah, just figured that out testing it myself. It increments the counter by whatever step was originally set.

I think you’re going to have to iterate over the label’s entities, which you can get with {{ label_entities('test') }}.

You can use the template to supply an amount, it would be silly to use a loop to add 200 one step at a time. I did have trouble though with step size 0.01 and a 0.22 increment (claiming it was not a multiple). Instead of figuring out why I wanted a quick fix. so I used set_value instead with a template doing the calculation.

Where does the amount come from?

The problem here is applying it to multiple input_numbers that have a label set. If would be easy for a single referenced entity.

But there is the input_number.increment service right? And there is a step parameter. So if you know the amount, things should be easy. Unless you use fractions like I did, because that seemed to malfunction. I thought that the increment call was there, but now I see it was using set_value.

As mentioned by myself previously - this only increments it by a set amount… thanks BTW @Troon for informing me this is actually the step NOT 1 as I had initially thought.

Yeah sorry, I was being very unclear and misread a few things. There is an increment service with an amount parameter you can set. As long as that is a multiple of the step size of the input_number helper you should be fine.

Seeing the error I got with a 0.01 step size, I do start to wonder now wether the amount is the value added, or the number of steps. I think I may need to visit the docs again :slight_smile:

Edit: hmmm. The amount parameter is provided by the automation helper, but is isn’t mentioned in the docs?

Can you share a screenshot of where is it provided? I can’t see it on my system. The increment service always just adds on one step: the source code does not allow for any amount to be entered:

    async def async_increment(self):
        """Increment value."""
        await self.async_set_value(min(self._current_value + self._step, self._maximum))

This is what the automation editor suggests:

  - service: input_number.increment
      entity_id: input_number.stoffie_duur_actief_sinds_legen
      amount: 20

Oh!! Oops! Frenck did it. Or rather, Spook:

I guess I found a ‘bug’, the Spook emoji isn’t in the Dutch label, like it is in the Spook screenshot. So I didn’t see I was using a Skooky feature :wink:

1 Like

Well sucks that is isnt inbuilt… will check it out over the next few days and post back.

Great - it appears that Spook only supports HACS (I placed it in the custom_components folder and it did nothing, then read the docs)…

Unfortunately this is not an option for me for a few reasons:

  • it defeats the purpose of running docker stuff in a container as HACS requires modifying stuff in the container directly (and Spook too which is why it requires HACS)
  • also because of this it will not support the high availability failover clustering setup that I have for my docker containers

OK … in the end I just ended up making a script to do this:

alias: Increment Input Number By Label Name
  - repeat:
        - if:
            - condition: template
              value_template: "{{ states[repeat.item].domain|lower == 'input_number' }}"
            - service: input_number.set_value
              metadata: {}
                value: "{{states[repeat.item].state|float + Amount|float}}"
                entity_id: "{{ repeat.item }}"
              enabled: true
      for_each: "{{ label_entities(Label) }}"
description: "Variables: Label, Amount"

It can then be called through a service as follows:

service: script.increment_input_number_by_label_name
  Amount: 10
  Label: Test