Replies: 3 comments
-
This template will not work because you do not follow the Jinja2 template rules (https://www.home-assistant.io/docs/configuration/templating/). You can test the template using the HA Template editor in Developer Tools ->Template. When you have a template which works you can make a template sensor in the configuration.yaml. See here: https://www.home-assistant.io/integrations/template/ |
Beta Was this translation helpful? Give feedback.
-
Here is an example template binary sensor and sensor from my home assistant configuration, using the new syntax. See altso the docs for home assistant templating: https://www.home-assistant.io/integrations/template/ |
Beta Was this translation helpful? Give feedback.
-
Sorry for giving you the wrong answer @strutings. I tried the template which Erlend has made (https://github.com/erlendsellie/priceanalyzer/wiki/Templating-PriceAnalyzer-to-make-it-your-own) and it works in the template editor.
Remember to use correct indentation when writing yaml or template. When pasting the template code into configuration.yaml the indentation must be correct. You can output the variabel in template editor if you use {{}} Example:
|
Beta Was this translation helpful? Give feedback.
-
maybe a silly question, but where do you put templates? I made a copy of a blueprint, and added this template at the end together with a modified automation, but it's not working as the custom sensor is not showing up at all.
`template:
unit_of_measurement: "C"
state: >-
{%set analyzer = states.sensor.priceanalyzer_tr_heim%}
{%set current_hour = analyzer.attributes.current_hour%}
{%set temp = analyzer.state | float %}
{%set outside_temp = states.sensor.utendorstemp.state | float(default=10)%}
{%if temp > 0 and outside_temp < 5%}
{%if current_hour.price_next_hour > 2.00 or current_hour.value > 2.00%} {{temp * 2}}
{%else%} {{temp}}
{%endif%}
{%else%}
{%if current_hour.price_next_hour > 2.00 or current_hour.value > 2.00%} {{temp * 4}}
{%elif current_hour.price_next_hour > 1.00 or current_hour.value > 1.00%} {{temp * 3}}
{%elif current_hour.is_max%} {{temp * 2}}
{%else%} {{temp}}
{%endif%}
{%endif%}`
Beta Was this translation helpful? Give feedback.
All reactions