Beat the Heat and Begin Cooling your Home before you Arrive - seangreen2/home_assistant GitHub Wiki

What you'll need:

  1. A Smart Phone with a GPS tracker such as the official Home Assistant app.
  2. A Smart Thermostat such as a Nest or Ecobee, or a Thermostat that can receive commands from HA

It's never fun to come home to a hot and humid home just to have your AC kick on as soon as it detects you on your WiFi or however else you have your local presence set up. Like you, I used to also come home and be miserable until the HVAC finally caught up to my comfortable temperatures. Depending on your preferences this could take TENS OF MINUTES! That simply will not do.

Enter the Proximity Component.

This tutorial assumes you know the basics of YAML and making changes to your configurations. It is also assumed you already have a functioning GPS device tracker in your configuration.

While this may seem pretty basic as far as automatons go, especially for the HA veterans, this could benefit a lot of newer users, or users that never knew the Proximity Component even existed. I also enjoy writing these.


After you have your GPS Device Tracker setup on your phone and in HA, we have to make several changes to your configuration.yaml and you can mostly copy the example I have below:

proximity:
  home:
    devices:
      - device_tracker.sean_pixel
      - device_tracker.emily_pixel
    tolerance: 100 #In meters
    unit_of_measurement: mi #Used for travel distances

zone:
  - name: home
    latitude: !secret latitude
    longitude: !secret longitude
    radius: 200 #In meters

You should already have your Longitude and Latitude from your initial set up, but if for some reason you don't you can easily find that information here: https://www.latlong.net/

I recommend the official Home Assistant app for your GPS tracking.

Changing the Zone to a larger number simply increases the Radius of when HA will determine you are "Home." I recommend not making this number too large.

Go ahead and save your file and reload all your YAML to confirm that you have a proximity.home in your entities.

Once confirmed, we now need to add some automations! We own two Nest Thermostats which are capable of presence detection, but I always found them incredibly unreliable. I disabled all presence setting for Nest and use HA solely to control it. This also means that whenever the house becomes empty, an automation sets the Nests to Away and Eco mode. I'm going to include my automations for Away Mode so the following automatons make sense.

- alias: "Nest Away Mode"
  initial_state: on
  trigger:
    platform: state
    entity_id: group.family
    to: "not_home"
  action:
    - service: climate.set_preset_mode
      data:
        entity_id: climate.downstairs
        preset_mode: "eco"
    - service: climate.set_preset_mode
      data:
        entity_id: climate.upstairs
        preset_mode: "eco"

The actions in this automation sets our Nests to Eco Mode as well as the home status to "Away". Pretty basic stuff.


Now here's the Proximity automation. The trigger here is important because as soon as HA detects our phones are within 5 miles of our home, the automation will fire and the home will start cooling down (or heating if it's winter). Feel free to adjust the proximity number to whatever your liking if you want it to fire sooner or later. We have two thermostats so this automation also staggers out which one to adjust first as the first one will get priority over the other.

- alias: "Climate Proximity"
  initial_state: on
  trigger:
    - platform: numeric_state
      entity_id: proximity.home
      below: 5
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: group.family
        state: "not_home"
      - condition: template
        value_template: '{{ states.proximity.home.attributes.dir_of_travel == "towards" }}'
  action:
    - service: climate.set_preset_mode
      data:
        entity_id: climate.downstairs
        preset_mode: "none"
    - service: climate.set_hvac_mode
      data_template:
        entity_id: climate.downstairs
        hvac_mode: >
          {% if states('sensor.season') == 'spring' or states('sensor.season') == 'summer' %}
            cool
          {% elif states('sensor.season') == 'autumn' %}
            heat_cool
          {% else %}
            heat_cool
          {% endif %}
    - delay:
        seconds: 30
    - service: climate.set_preset_mode
      data:
        entity_id: climate.upstairs
        preset_mode: "none"
    - service: climate.set_hvac_mode
      data_template:
        entity_id: climate.upstairs
        hvac_mode: >
          {% if states('sensor.season') == 'spring' or states('sensor.season') == 'summer' %}
            cool
          {% elif states('sensor.season') == 'autumn' %}
            heat_cool
          {% else %}
            heat_cool
          {% endif %}

The Conditions:

  1. The first condition guarantees that the automation will only fire if everyone is away from the home.
  2. The second condition ensures that HA will only fire if it determines that we are driving towards our home. It won't fire if we're driving to work or some other place, only if the system believes we are on our way home.

The Actions:

  1. Our Nest supports several different Operation Modes: Cool, Heat, Heat_Cool, Eco, and Off. Depending on the current season, I have HA automatically change the Operation Mode to whatever is appropriate. In Spring and Summer it will change to Cool, Fall it will change to Heat_Cool, and Winter it will change to Heat_Cool. To use this setup you will also need to add the Season integration in Home Assistant

  2. The second action simply turns off the Nest's Away Mode.


Once your automatons are entered, restart HA and you should be good to go! Now you will enjoy coming to a cooling home or an already cooled home and beat the heat!