Your template checks between 09:00today and 01:00today.
Copy-paste the following template into the Template Editor and confirm it reports the correct value.
{% set start = states('input_datetime.living_thermostat_time_day') %}
{% set end = states('input_datetime.living_thermostat_time_night') %}
{% set day = states('input_number.living_thermostat_temp_day') %}
{% set night = states('input_number.living_thermostat_temp_night') %}
{{ day if today_at(start) <= now() <= today_at(end) + timedelta(days=1) else night }}
The idea is that I can adjust the times and between the two times (so for example between 09:00 and 15:00 or between 09:00 and 02:00) it should be 23° and outside the 2 times it should be 18°!!
That’s to be expected because the end time is now being set to tomorrow. The expectation is that the end time is normally shortly after 00:00 (like 01:00).
Any end time greater than 00:00 but less than the start time is a time that is tomorrow.
That’s why your original template failed because it attempted to find a time greater than 9 but less than 1 today and there’s no such time.
There’s no time that is between 09:00 today and 02:00 today.
The solution is if you intend to change the end time so that sometimes it’s today and sometimes it’s tomorrow, your template will need to check if the end time value is greater or less than the start time and adjust the timedelta value accordingly.
Copy-paste the following into the Template Editor and test it.
{% set start = today_at(states('input_datetime.living_thermostat_time_day')) %}
{% set end = today_at(states('input_datetime.living_thermostat_time_night')) %}
{% set day = states('input_number.living_thermostat_temp_day') %}
{% set night = states('input_number.living_thermostat_temp_night') %}
{% set offset = 1 if start > end else 0 %}
{{ day if start <= now() <= end + timedelta(days=offset) else night }}
I had already found this myself. But this doesn’t work either. Because when it is 0:00 am I already get the 18° because the start time is already smaller than the end time, but I actually want this from 01:00 am. I really can’t solve this and I think this should be possible, right?
I suggest you consider solving the problem a completely different way. Instead of attempting to create a template that checks if the current time is between a starting and ending time, simply create an automation with two Time Triggers.
Yes I have tried this already, and it works but the problem is that ariston.net often goes offline and when it comes back online it still doesn’t work. Apparently this is an almost unsolvable problem.
The intention is that when Ariston.net comes back online it will be checked whether the thermostat should be set to 22 or 18 degrees. and then it will be checked whether a higher temperature is requested in the house. If so, the thermostat of the heating boiler should be set higher than 22 (if the temperature in Living is higher than 22 otherwise not). It is very difficult to explain what the intention is in the end. My first step however is the temperature in teseellen at 22° at 9:00 AM and at 18° 01:00 AM, if I can manage that I can continue I think. But this is apparently much more difficult than I expected.
Thank you very much for helping me a little further. I am quite new but I try a lot of things to learn a lot. I did not even know this code. ok I will try this immediately.
I tested your solution tonight at 0:00 and 01:00 and it worked. So my first step in my automation works now and I can continue searching. Thank you very much for helping me out!!