How to Increment Counter Helper within Template

I have been using the Template Developer tool (which is great btw) to try to figure out how to increment a counter helper within a template.

{% if states('counter.front_porch_status') | int < 3 %}
  {{ counter.front_porch_status.increment }}
{% endif %}

The ‘if states’ works correctly on it own in the tool, but I can’t get the syntax of the increment right. Any guidance would be appreciated.

You can’t.

You increment a counter by using a service call, specifically this one: counter.increment

Plus you can’t execute a service call within the Template Editor (you can use Developer > Services to execute a service call).

Ah. Thanks, that makes sense now. But is it not possible to increment it within a template ‘outside’ of the testing tools in real automation usage? Or do I still need to make a Service Call?

You need to use a service call.

Is there something in the documentation that gave you the impression that it was possible to do the following?

counter.front_porch_status.increment

Or is it based on your experience with some other software, or programming language, that you have used and you are making an assumption it must exist in Home Assistant as well?

Ok. Then a Service Call it is. Not making any assumptions, must have been a misunderstanding on my part of the documentation.

Thanks for your help in clearing it up. :grinning:

and if you want to cimplay display the counter value of “counter.front_porch_status.increment” … what would you write ?

For example I want to display its value in a card … value. something or … ?

Display where? In a template?

{{ states('counter.front_porch_status') }}

In an entity card, just select the counter entity.

Super thanks !!
I hade written state_attr
;-(

Many thanks !