Hi!
I can get a minumum value of 2 temperature sensors with this :
value_template: {{ [ states('sensor.one') , states('sensor.two')] | min }}
But I would like the outcome to specify the name of the sensor as well. How can I achieve this ?
Hi!
I can get a minumum value of 2 temperature sensors with this :
value_template: {{ [ states('sensor.one') , states('sensor.two')] | min }}
But I would like the outcome to specify the name of the sensor as well. How can I achieve this ?
No one to help ?
I’m sure there’s a better way, but this works:
{% set ents = ['input_number.foo', 'input_number.test'] %}
{% set vals = expand(ents)|map(attribute='state')|map('float')|list %}
{% set ent_dict = {ents[0]: vals[0], ents[1]: vals[1]} %}
{% set max_key=ent_dict|max %}
{{ "%s: %d"|format(max_key, ent_dict[max_key]) }}
{% set x = expand('sensor.one', 'sensor.two') | list %}
{% for i in x if i.state|float(0) == x|map(attribute='state')|map('float', 0)|min %}
{{ i.name }}: {{ i.state }}
{% endfor %}
Works like a charm. Thank you Taras.
May I ask one last question. Sometimes, very rarely 2 sensors might have the same value like 21.7. Then this code displays both of them. How can we push it to display only one sensor when 2 or more values are the same ?
Replace this line:
{{ i.name }}: {{ i.state }}
with this:
{% if loop.index == 1 %} {{ i.name }}: {{ i.state }} {% endif %}
Thank you very much again.