Random delay in automation triggering

Hi all,

I have a ducted air conditioning in my house which is controlled by HA. The house has three zones controlled by smart dampers. I have set up automations where a damper will automatically close or open depending on the temperature in the rooms.

I rely on sensors in my Xiaomi Humidifiers in my kids room and the master bedroom. I am using the Xiaomi Miio integration and the temperature readings from the Humidifiers update every minute.

What I am struggling to understand is the somewhat random nature on when the automation runs to turn the AC off. The rules are:

If AC is on, both rooms have a temperature of over 18 degrees and both dampers are closed then turn off the AC. The dampers are closed because the room is too hot. This way other parts of the house can heat up and then it turns off.

In the middle of the night, I have awoken to hear the AC running, both ducts are closed and looking at the log, the AC should have turned off about 30 minutes ago. Then I look at the trace logs and sometimes it will be testing the trigger to fire the automation every 5 minutes. I dont understand why the automation is not instantly triggering and then testing the conditions on whether to fire.

The whole point of these automations is to keep the house warm over night but only for when it is needed and turns off quickly (We have young kids and thats why I am relying on this, once they are older, they can stay warm under their blankets). Dont get me wrong, the automation works but the AC is running for sometimes 30 mins to an hour longer than needed.

Any ideas to make the automation instantly trigger when it detects both rooms are over 18 degrees?

It is hard to tell what is going on based on a description without seeing the automation.
This would fire when both rooms are hot:

alias: Both rooms hot
description: ''
mode: single
trigger:
  - platform: numeric_state
    entity_id: sensor.temperature_42
    above: '18'
  - platform: numeric_state
    entity_id: sensor.temperature_38
    above: '18'
condition:
  - condition: numeric_state
    entity_id: sensor.temperature_42
    above: '18'
  - condition: numeric_state
    entity_id: sensor.temperature_38
    above: '18'
action:
  - service: notify.persistent_notification
    data:
      message: Both rooms are hot

The thing is, triggers only fire if the temperature goes from below to above the supplied limit. So the more conditions you add, the more extra triggers you need. So lets say you add a condition: the light must be on. Then you also need a trigger: the light is turned on. Because if the light is off and both rooms are already hot, and you turn on the light, the automation won’t run, even if it gets hotter. That is why you need the extra trigger for the light being turned on, so the automation will also check the temperatures again.

So the automation you use needs to trigger on ducts being opened or closed, temperature changing and whatever other conditions are there to decide what to do with the AC. And if there’s a time condition in there, you also need to trigger at the start or end of the time period. Anything that can change to make the conditions true must be in the triggers.

ps. This can be simplified using a template trigger, but I wrote it this way to make the point clear. If you use a template condition, all entities in the template also act as a trigger, and the total template acts as the condition.

Hi Edwin,

Here is the automation code

alias: WINTER - Turn off heating when above 18 degrees
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.smartmi_evaporative_humidifier_temperature
    above: '17'
  - platform: numeric_state
    entity_id: sensor.kids_s_humidifier_temperature
    above: '17'
condition:
  - condition: state
    entity_id: climate.mitsubishi_ducted
    attribute: hvac_action
    state: heating
  - condition: state
    entity_id: switch.front_rooms_ac_duct_control_channel_1
    state: 'on'
  - condition: state
    entity_id: switch.kids_rooms_ac_duct_control_channel_1
    state: 'on'
action:
  - service: climate.turn_off
    data: {}
    target:
      entity_id: climate.mitsubishi_ducted
mode: single

It happened again last night where the initial trigger didnt fire even though both temperature settings were above 17 at 4.34am. The automations triggered at 4.04 and 4.24 but looking through the traces’ the conditions failed. It then didnt trigger again and my partner turned off the AC in the middle of the night.

In the past when this has happened, I have reloaded the xiaomi integration and that appears to do a trigger check. Its like the system has forgot to do a trigger check but the system goes “oh yeah, let me check. Yep trigger conditions met”