I’m currently working on building a bunch of automations to control all my thermostats. I’ve got 12 thermostats with a total of 20 setpoints (8 have heat-to and cool-to setpoints, and 4 are only heat-to). I’m trying to build a 4-stage / weekday-vs-weekend + vacation-mode configuration. I have a bunch of input_number settings to store all the setpoints (one set per stage per day) and I’ve already written a script it iterate through all the thermostats to save (initialize) the input_number settings. This is done as a python-script.
The other automation I have is that I want to “remember” the settings if they are changed locally. In other words, if I modify a thermostat setting at the thermostat, I want to record and remember that setting based upon the current time-stage setting. I have this implemented, but it currently saves to only one of the TOD settings; it is not dynamic.
As I work through this, I’m finding that I’d like to build a subroutine that determines the specific time-stage/day setting for a particular thermostat given the current time/day. I don’t think I can easily do this via a template. Basically, I need to do something like:
{% set thermo = entity_id | replace('climate.','',1) -%}
{% set weekday_weekend = ... %}
{% set tod = (based on current time, determine the morning/day/evening/night timeframe %}
Part of the reason I want this in a subroutine is that I need the same code in many different scripts/automations. I would need it in the ‘save’ automation, but I also need it in the “update thermostats” automations. Moreover, due to the fact that some thermostats have two settings and some only have one (temperature, target_temp_high, and target_temp_low) I need to either build conditional actions or separate automations. I haven’t figured out how to make conditional actions, or ways to set two values in one call, so right now I have one script to run for my 8 high/low thermostats and another one for the 4 temp thermostats.
So back to my question: IF I could do this as a subroutine, then I could really simplify the rest of my automation and scripting. I could literally do
{% set day_time_info = SUBROUTINE(entity_id) %}
Unfortunately I have NO CLUE how to actually do what I want. I have not found any way to “return” a value, or extend the template capabilities to add a new function.
Is this doable?