Best way to "enqueue" automation to be scheduled fews seconds after last change of some related entities

I have a set of few HVAC/AC; each one is controlled by an IR bridge; each one has a set of few operating parameter (power, temperature, .fan speed, …).

When someone change one parameter for one AC in the HA frontend, I would like to avoid immediately sending an IR command to the AC because the IR command include every time all the four working parameters. (When sending several IR commands to AC in a short while, the AC can miss one or more.)

Instead I would like to wait fews seconds until no more changes are detected in any input_* entity. At this point send the IR command to the AC.

Ideally a first automation, triggered by state change of all parameters (every parameter, every AC) should enqueue an handler script execution for the involved AC, but this script should be rescheduled later if another change of the same or another parameter for the same AC is detected soon.

If in the meanwhile a change of a parameter for another AC occurs, we can choose if we want to handle in parallel (best but hard I think) or to enqueue also this one (maybe simpler).

I can figure a way to do this with several helpers entities and maybe several identical copies of the automation/scripts but I would like to know what is the more concise/manageable way implement.

You want to add a for attribute to your automation trigger. For example:

automation:
  trigger:
    - platform: state
      entity_id:
        - input_boolean.ac_power
        - input_number.ac_fan_speed
        - input_number.ac_temperature
      for:
        seconds: 10
      action:
        # Do something.

I’m not sure this works: the actions are started when all entity states are stable for at least 10 seconds or as soon the first entity changed has been stable for 10 seconds?

Said differently, if at t = 0 I change ac_fan_speed and at t = 9s I change ac_temperature, the action do something should start at t = 19s not at t = 10s.

And if this works as expected, I suppose I need to create one automation for every AC. I would like to avoid repeating code, if possible.

You could set the mode to “restart” and then use as conditions the same as the triggers for the same amount of time.

expanding on the example above I think this should work:

mode: restart
trigger:
  - platform: state
    entity_id:
      - input_boolean.ac_power
      - input_number.ac_fan_speed
      - input_number.ac_temperature
    for:
      seconds: 10
condition:
  - condition: state
    entity_id: input_boolean.ac_power
    for:
      seconds: 10
  - condition: state
    entity_id: input_number.ac_fan_speed
    for:
      seconds: 10
  - condition: state
    entity_id: input_number.ac_temperature
    for:
      seconds: 10
action:
.
.