Setting input_number depending on other sensors' states

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

If you want to check if the next two days are colder (lower value), why is this statement checking if they are warmer (higher value)?

{% if (b>a) and (c>a) %} {% set X = 2 %}

Also, why is the test in the elif identical to the test in the if statement?

{% if (b>a) and (c>a) %} {% set X = 2 %}
{% elif (b>a) and (c>a) %} {%set X = 1 %}

Taras, right.

I was playing around to make sure I get the ‘and’ and the <> right. So never mind, the actual logic will need to be more complex. That’s where I feel I am moving on more solid ground, getting the variable X into yaml to set input_number is where I am lost.
F

Do you mean the requirements you posted will become more complex than what was described?

I want to get a variable that is either “2” for two days of colder temps ahead, or “1”, for just one,

Well, my electric heating system runs on rel cheaper off-peak juice at night with heat being stored in a stone buffer, to be released gradually over time. So whenever colder days are forecast, I’d like to charge the buffer more, and vice versa. The logic will need to differentiate between a) a row of cold days, b) a cold front passing during one day, with improving weather thereafter, etc.

These scenarios should all result in a discrete variable that will drive input_number to set the heating cycles’ duration.
F