WTH is there no "while" condition?

I want my ceiling fan to turn on (in reverse/“winter”) mode while my heating is on.

Not “switch on when the heating switches on” then “switch off when the heating switches off”.

I don’t want two conditions. I only want one: “Ceiling fan is on while the heating is on”. Nothing else! :slight_smile:

Then you want an automation platform that uses a continuous-polling model, not Home Assistant’s event-based model.


Just for clarity’s sake, in HA automations conditions are checked immediately, they do not wait or poll multiple times… so the concept of a “While” condition is kind of non-nonsensical.

Not necessarily.

I’d be fine if, under the hood, HA would turn on the fan on event X, then turn it off on event Y. Continuous polling is not mandatory. What I don’t want is having to manually set two conditions for on and off. I’d like one condition that understands what I want.

triggers:
  - trigger: state
    entity_id: climate.example
    attribute: hvac_action
actions:
  - action: fan.turn_{{ 'on' if trigger.to_state.attributes.hvac_action == 'heating' else 'off'  }}
    target:
      entity_id: fan.example


If you are interested in other approaches, there is also a “While” trigger available in Spook. It’s a little closer to what you asked for, but, as I understand, it still isn’t reload/restart-safe.

Nice template. Elegant. I would have probably made some much more wordy if loop, but this is nicer. One thing for the OP to be aware of: it also turns off the fan if the heating goes unavailable or undefined. I don’t know if that is what the OP wants but it is easily adjusted.

For some devices, it is as easy as using conditions from the UI. Didgeridrew’s method is very clean and cover UI deficiencies.

triggers:
  - entity_id: climate.nest
    attribute: hvac_action
    trigger: state
actions:
  - choose:
      - conditions:
          - condition: state
            entity_id: climate.xxxx
            attribute: hvac_action
            state: heating

What if I’d like to turn the heating on only if my solar array yields a certain amount of power (say 2000W) and turn it off if it’s getting below (shadow/cloud) that power level ?

Related to this, I recall struggling with an automation some time ago, was looking for a while condition or at least the possibility to manually define a “system wide” boolean state variable that I could read in some other conditional checks - thus, simulating a “while” loop. I also documented the issue here in the forum (it was about starting/stopping the recording on some surveillance cameras based on triggering events) and got no replies ever since. In this respect HA is really limited… a pity.

Edit - found the thread with the cameras I referred to

Wait for trigger in your action block.

It satisfies OPs needs but it’s not a condition. Likely why it was overlooked by OP.

Wait template is similar

And upvote this feature request (or add its own WTH if it doesn’t already exist) to add wait_for_condition which is one I’ve been wanting personally for a very long time :upside_down_face:.

While not native, and still pretty new, I created an app using AI that does something like it, for the same reason - persist across reboots and make sure the state is always synced. I can’t promise that there won’t be breaking changes as it matures, but I use it now and it’s been working flawlessly

My apps repo → State Sync