Hi folks,
I’m new to HA, and am getting stuck with the following challenge:
I use met.io integration for the weather forecast, and use three template sensors to grab the ‘lowtemp’ (ie morning temps, most likely) for the next few days (weather.emsee_keuschn). Depending on whether the temps are reported to go up or down, I want to get a variable that is either “2” for two days of colder temps ahead, or “1”, for just one, using simple ‘if’/‘elif’/‘else’ statements. This variable should then serve as an input_number which in turn sets the time that my electrical heater will run overnight.
In the DevTools I managed to set up the three template sensors, and the if-statements, but I fail to define a variable that I can use in YAML to set input_number.
Here are the DevTemp lines that produce a variable ‘X’ which I’d like to use further, but get stuck any time when I try to paste the code into sensor.yaml.
{% set delta = states.weather.emsee_keuschn.attributes['forecast'][1]['templow'] %}
{{delta}}
{%set a=delta%}
{% set b = states.weather.emsee_keuschn.attributes['forecast'][2]['templow'] %}
{{b}}
{% set c = states.weather.emsee_keuschn.attributes['forecast'][3]['templow'] %}
{{c}}
{% if (b>a) and (c>a) %} {% set X = 2 %}
{% elif (b>a) and (c>a) %} {%set X = 1 %}
{%else%} {% set X = 0 %}
{%endif%}
{{X}}
I am sure there is a way, I have spent hours browsing to find ideas, but no no avail so far. Any hints welcome, many thanx in advance! Frankie