Hi, can someone help please with the following template.
I’m trying to give colors to the certain result of comparison status1 to status2.
If status1 is below status2 with a value between 0 and -250, a color must show. If it is between -250 and -500, another color.
But also the way around: if status1 is ABOVE the value of status2, up to and including +250, it must also be given a color, just as it is between +250 and +500.
I just don’t know how to compare this to status2 in this template?! What I have is:
but of course isn’t working.
{% set status1 = states('sensor.value') %}
{% set status2 = states('sensor.value_ath') %}
{% if status1 > 0 and -250 > status2 %}
lightorange
{% elif status1 > -250 and -500 > status2 %}
orange
{% elif status1 > 0 and 250 > status2 %}
lightgreen
{% elif status1 > 250 and 500 > status2 %}
lightgreen
{% else %}
white
{% endif %}
Hm it feels like I’m almost there, this is my testing so far.
is the template correct when I say:
first check: is status1 greater than status2? yes? then the value is checked, is it greater than 250 (ORANGE) or 500 (RED)?
second check: is status2 smaller then status2? yes? then the value is checked, is it smaller than -250 (GREY) or -500 (BLUE)?
{% set status1 = states('sensor.value') | float %}
{% set status2 = states('sensor.value_ath') | float %}
{% if status1 > status2 < 250 %}
orange
{% elif status1 > status2 < 500 %}
red
{% elif status1 < status2 > -250 %}
grey
{% elif status1 < status2 > -500 %}
blue
{% else %}
white
{% endif %}
but is it still not 100% correct because the result (compare status1 with status2) = -48 at this moment.
it gives me grey, but when I change -250 to -600 for instance, it also gives me grey ?!
It is difficult to help when we don’t have a “truth table” to compare against or even any idea what the possible value ranges are for these statuses.
What do you mean by “with a value” and “it is between”? Are you referring to status1, status2 or something else?
What do you mean by “the result”? How is a comparison (>, <, <=, >=) returning anything but true or false? If you are performing other calculations you need to show/describe them.
something comes to mind as I write a response to you.
I’ve got 2 sensors which reports a certain EUR value (currency), so for instance status1 is 300 EUR. Status2 is the all-time-high of status1 so if status1 changes to 500 EUR, status2 will change too, to the same value.
So what I just thought; a 250 or 500 EUR difference above status2 is not possible. I’m sorry for the confusing.
But I still want to know the color when status1 is below status2.
So if status1’s value has a difference with status2, between 0 and -250 EUR, I want to see a specific color. The same for the difference between -500 and -750 EUR.
status1 has a value at this moment of: 5733 EUR
status2: 5794 EUR
the difference is -61 EUR
so when I try a template like this I would expect to see green but I see blue in the template tester?!
because it is closer to -250 (in the between 0 and -250 range) than between -250 and -500
{% set status1 = states('sensor.value') | float %}
{% set status2 = states('sensor.value_ath') | float %}
{% if status1 < status2 < -250 %}
green
{% elif status1 < status2 > -500 %}
blue
{% else %}
red
{% endif%}
{% set status = states('sensor.valuedif') | int %}
{% if status > -100 %}
blue
{% elif -100 > status > -250 %}
orange
{% elif -250 > status > -500 %}
red
{% else %}
grey
{% endif %}
Dont ask me why because I don’t understand the < and > here