Set counter to 'current state' + 40?

I’ve created a simple automation where each time my coffee maker brews, it reduces the the counter ‘counter.coffee_filters’ by 1, so that I’ll know when I’m running low on coffee filters and need to buy more. The idea is when I open a new box, I’ll just reset the counter back to 40 (the number of filters in the box).

The issue is, that in the situation above I’ve waited until there are 0 left to hit reset so it will be 40 again. But if I purchased more filters when there were 5 filters left, I now have total 45 filters, so really the counter should be at 40+5 = 45.

Does anyone know of how I can increase a counter as current counter value + 40?

Thank you

Create an automation or script (probably a script in this case) that grabs the current value of the counter, adds 40 and uses the service.set_value to set that value into the counter.

In your dashboard add a button card then use a service call from that button card (or your favorite card) to trigger the script and label the button ‘restock filters’.

Thanks! I was overthinking it. The solution is a script just like you said
service: counter.set_value
data_template:
entity_id: counter.coffee_filters
value: “{{ states(‘counter.coffee_filters’) | float + 40}}”

1 Like

I’m new to Home Assistant & coding, so I do apologize for looping back to this simple script/automation,

However, I’m trying to deploy a similar scirpt/automation and I can’t seem to get it to run.

I’m getting a 'failed to call service script. Service not found" error.

I should say I have split my config.yaml file (if that makes a difference here).

Hi! Are your other scripts working OK?