Whag
(Whag)
October 21, 2022, 8:44pm
1
hi there any idea why the below code from the the template editor which works as expected does not work in a template sensor yaml file, i get unknown back
{{states('input_number.oiltankheight')|float(0) -
(states('sensor.lvl_oiltank') |float(0)*1000)|round(1)/1.1 - 110
}}
Whag
(Whag)
October 21, 2022, 8:46pm
2
yaml file
oiltankvolulme:
value_template: >-
"{{(states('input_number.oiltankheight')|float(0) - (states('sensor.lvl_oiltank') |float(0)*1000) /1.1 - 110) |round(0)}}"
nikito7
(nikito7)
October 21, 2022, 8:59pm
3
value_template: >-
{% set x = states('input_number.oiltankheight')|float(0) %}
{% set y = states('sensor.lvl_oiltank') |float(0)*1000 %}
{{ ( (x - y) / 1.1 - 110 ) | round(0) }}"
Whag
(Whag)
October 21, 2022, 9:35pm
4
Hi nikito7 i appeciate the reply, strangley this worked for me after trying a few things. All i did was enter the string in one line which i do not undeerstand.
oiltankvolulme:
value_template: "{{(states('input_number.oiltankheight')|float(0) - (states('sensor.lvl_oiltank') |float(0)*1000) /1.1 - 110) |round(0)}}"
tom_l
October 21, 2022, 11:44pm
7
Don’t use quotes for multi line templates. So like this
oiltankvolulme:
value_template: >
{{(states('input_number.oiltankheight')|float(0) - (states('sensor.lvl_oiltank') |float(0)*1000) /1.1 - 110) |round(0)}}
Or like this:
oiltankvolulme:
value_template: "{{(states('input_number.oiltankheight')|float(0) - (states('sensor.lvl_oiltank')|float(0)*1000) /1.1 - 110) |round(0)}}"
Whag
(Whag)
December 31, 2022, 9:04pm
8
Thanks for the update btw.