Automation to set HVAC mode depending on presence

Good evening,

I’ve been having some fun times slowly automating my home and I’m trying to tackle this next challenge.

I own a Gree mini split AC that has its own temp sensor. What I would like the automation to do:

If the temperature of the sensor is above 24C, and either myself or my wife are home, start the unit in “cool” mode.

I’ve gotten this part to work quite well. The issue is, if temps reach the threshold while we are not home, the automation does not fire again (no trigger) even when we do get home. I’m used to program other stuff but if it was in another language I would memorize that I have crossed the threshold and fire when either person gets home.

This must be something real simple I am forgetting, I’m not used to YAML at all. I figured using the restart mode would work but it would require the temperature to rise another degree before triggering again, unless I am mistaken.

Here is the automation as it stands currently:

alias: Auto HVAC (Cool)
description: ''
trigger:
  - platform: numeric_state
    entity_id: climate.1e466751
    attribute: current_temperature
    above: '24'
condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: device_tracker.iphone_1
        state: home
      - condition: state
        entity_id: device_tracker.iphone_2
        state: home
action:
  - device_id: 64bfa1752510b1baf9d7130e80a621ed
    domain: climate
    entity_id: climate.1e466751
    type: set_hvac_mode
    hvac_mode: cool
mode: restart

The trick in these situations is to use the temperature and your phone presence as triggers and conditions. This way you being home when the temperature increases triggers it, and so does you getting home when it is already hot.

So something like.

trigger:
  - platform: numeric_state
    entity_id: climate.1e466751
    attribute: current_temperature
    above: '24'
  - platform: state
    entity_id: 
      - device_tracker.iphone_1
      - device_tracker.iphone_2
    to: home
condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: device_tracker.iphone_1
        state: home
      - condition: state
        entity_id: device_tracker.iphone_2
        state: home
      - condition: numeric_state
  - condition: numeric_state
    entity_id: climate.1e466751
    attribute: current_temperature
    above: '24'

Thank you for your help so far. Bear with me, I’m a pretty good learner but I need to fully understand to apply this to this particular situation and then generalize to other stuff.

Doing what you’re suggesting makes sense at a first glance. Basically the automation will trigger if the temp sensor reaches 24C, and will then check if we’re home.

If we’re not, it dies right then and there.

When either of us does get home, it fires again, since the OR condition is true it’ll keep going to the next condition, which checks whether the temperature is higher than 24C. That will be TRUE, thus it’ll do the action.

My updated YAML now looks like this but will require further testing (wife is using her phone so I don’t think she’ll appreciate me tearing it out of her hands to turn off wifi).

alias: Auto HVAC (Cool)
description: ''
trigger:
  - platform: numeric_state
    entity_id: climate.1e466751
    attribute: current_temperature
    above: '24'
  - platform: state
    entity_id:
      - device_tracker.iphone_1
      - device_tracker.iphone_2
    to: home
condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: device_tracker.iphone_1
        state: home
      - condition: state
        entity_id: device_tracker.iphone_2
        state: home
  - condition: numeric_state
    entity_id: climate.1e466751
    attribute: current_temperature
    above: '24'
action:
  - device_id: 64bfa1752510b1baf9d7130e80a621ed
    domain: climate
    entity_id: climate.1e466751
    type: set_hvac_mode
    hvac_mode: cool
mode: restart

One further question I would like to know is if it would be easy to implement this on a seasonal basis? I wouldn’t want this thing to fire in the middle of winter if we’re having fondue near the AC that is in the dining room, for example.

Add the season integration and add another state condition to your automation that checks the sensor it creates: