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