Template sensor based on counter value

I’m fairly new to Home Assistant and trying to get my head around template sensors. Not being familiar with Jinja is making this a challenge! I’ve got a use case where I think a template sensor would be useful, but struggling to work out what I need. The scenario is I am using a counter to indicate perimeter threat level around my house, based on number of motion events and a few other triggers. I want to create a template sensor that displays a different value, based on the number of the counter - eg something like:
0 = CLEAR
1-3 = LOW
3-5 = MEDIUM
5-7 = HIGH
7-10 = CRITICAL

I could do this with several events and a text helper, but I think a template sensor would be suitable here. Is there a more elegant way than something like this (missing some states from above, but you get the picture)

      {% set threat = states('counter.threat_counter')|float %}
      {% if threat > 0 and threat < 3 %}
        Low
      {% elif threat < 5 and threat > 3 %}
        Medium
      {% elif threat > 5 %}
        High
      {% else %}
        Clear
      {% endif %}

Cheers

There are roughly 1 million ways to do it, but the best choice is really personal preference. You could make a basic simplification with the following:

{% set threat = states('counter.threat_counter')|float %}
{% if 0 < threat <= 3 %}
  Low
{% elif 3 < threat <= 5 %}
  Medium
{% elif threat > 5 %}
  High
{% else %}
  Clear
{% endif %}

I usually look for a way to use an integer as an index into a list of strings for stuff like this, but I don’t see a less wordy way to do that with the problem you laid out. I did add some “=” in there to avoid missing the transition values, so make sure you take that into account in your final solution.

Thanks

Thanks… I’ve implemented this version as it seems a bit tidier and it doesn’t give any errors, but the sensor only says Clear, even when I change the value. I have a sneaky suspicion this may be something to do with manually changing the counter state, vs it being triggered (I think I read something somewhere about that)… Does changing the state manually trigger a template sensor to update?