Don't understand, how delays and triggers work

I created this automation. But I can’t understand how can I force automation to stay in the loop until loop ended??? I even creates a variable (bool), turn it on at start of a loop and turn off at the end, and creates 2 triggers (temp state changed (any) and my bool-variable changed to zero (from is empty)) - NO result. How can I force an automation to stay in the loop without any timers? I don’t know how many times and how much time loop will cycle!

By ONE automation? How?

Yes, simple job is as you wrote (and I already done that). But “improve the logic a bit”. Basically I need force my program to NOT exit a loop, until all(!) conditions in a loop are met. I need control some delay conditions in a loop, but I don’t know, how many and how much times loop will cycle, so I want to force the trigger NOT TO interrupt my loop.

It’s not only for heating, a “delay-theme” inside some cycles is main here.

The automation you presented controls a switch based on a desired target temperature. That’s what Generic Thermostat is designed to do.

The Generic Thermostat will turn on the switch only for the amount of time necessary to reach the target temperature (and you can control the minimum amount of time using min_cycle_duration).

Your automation contains delay statements ensuring the switch isn’t on for more than 3 minutes (and no less than 3 minutes) and that it doesn’t test the temperature until 3 minutes after the switch is turned off. Why is this your preferred method? What are the design requirements that are fulfilled by these delays?

The reason this is so hard is that building loops that are waiting for things to happen using delays is not how Home Assistant is designed to operate. HA is an event driven system, that is a very different design principle.

The basic concepts you’re supposed to use are triggers and state.

In an event driven system delays are a bit of a design breach in event driven systems, especially longer ones. The timers (that you do say you do not want to use) create events when the time has passed. So those fit very well in event driven systems.

The same goes for loops. They are fine for doing the same thing a couple of times, but once you introduce delays in them you break the event driven design. Event handles are supposed to execute quickly.

Adopting a true event driven approach will make your life easier, as that is what HA is built for. But it will involve splitting your algorithm up in multiple automations (which you also do not want). Trying to force the entire thing in one automation will almost always result in added complexity and fighting the event driven design of HA.

Adopting the event driven design may be easier if you think of your original problem in terms of a state machine:

With a whole load of pointless complexity using if or choose blocks.

Personally I don’t see the point.

Perhaps to deal with a hysteresis from when the heating is stopped and that the temperature measurement can be made accurately?

I get the sense that OP is essentially needing a max_cycle_duration behavior instead of a min_cycle_duration

Edit - after some additional pondering: If it is a hysteresis issue, I would think with some experiments the effect could be characterized. And once characterized, be compensated for by picking appropriately adjusted min, max, and target temps.

Could be that, could be something else or for no reason at all; until poddex explains the requirements (requested several times) we’re left guessing why anyone would want to maintain temperature in such a crude way.

Ok. I want to build an automation that (1) see that temperature falls above some temp - no time bindings (2) start an automation. This automation triggers another device that has it’s own algorithm. And I want, that (1) shouldn’t fire again UNTIL temp exceeds some value “below temp”. Then the trigger “temp below” (3) fires another automation (heating, cooling, etc) and anything will not interrupt this automation (3). Automation (3) should work until (1) is met. For now, when I use trigger “State” for (1), it see that temp is above some temp and triggers (2), so my device gets “on”-signal again and again. Problem is that this device resets to start point when it get an “on”-signal, while it already “on”. That’s a point, I want to NOT interrupt. And no time bindings. How can I do that?
Ok, trigger “temp falls above some T” for X minutes…time bindings =( “temp exceeds above some T” - if state changed. it will sell ON-signal on my device again and again. I want that trigger must do nothing UNTIL another condition will met.

Hmm, I investigate signals of my device and then included it in the condition after the trigger. It seems that automation has stopped working after one launch and now all automation waits UNTIL another condition met. But I had to create two automations for this. I can’t make it via one automation. I will see if it works for a day or two and then post a result.

All works fine, but 2 automations…state machine is much harder to understand. And I need a third automation - between 2 parameters. For now I firstly statrt my devices, they outpits a signals, then these signals used for my 2 automations. All is ok in this case.
Thanks all.