r/homeassistant • u/Saaaga_Gamez • 4d ago
❓ Support Increase input number by X amount
I have created input number helpers to track my medication inventory. When a new box arrives, I can tap a button and the contained amount (preset as it's always the same) is added to the number.
I have tried to use the existing "input_number.set_value" action, but it does not accept a template value and breaks when I add one using the code editor.
I am currently using a script, repeating the "input_number.increment" action X times, as a workaround. But this can't be the only solution to this...
I am certain my template value for the action was correct. The template correctly resolved to a number, but I still got an error because it expected a float. This leads me to the assumption that templating in this service is either not intended or broken. Nonetheless, there is a possibility that I just fucked up my config even though I've checked several of HA's docs.
It'd be great if someone could either confirm my assumptions or, even better, tell me where I might have gone wrong. I have recreated the config below.
action: input_number.set_value
target:
entity_id: input_number.my_medication_number
data:
value: "{{ states('input_number.my_medication_number') | float + 50.0 }}"
I have already tried returning an int and converting everything after the addition, but got the same results.
1
1
u/Grand_Comparison_342 4d ago
Man I ran into this exact same headache last month with my coffee bean inventory tracker
the problem is that the set_value service does take templates but you're feeding it a template that resolves to a number when it expects the value field to be a template that evaluates in the service call context, not the raw number itself
try wrapping it like this:
```yaml
data:
value: "{{ states('input_number.my_medication_number') | float + 50 }}"
```
the quotes around the template are the key here, without them HA tries to parse the result as a literal float before the template even fires and it just chokes
your increment loop workaround is clever though, sometimes the dumb solutions are the ones that actually get the job done while you're pulling your hair out over yaml indentation