Tesla Model X winter

Dynamically preheating the car with Home Assistant

Introduction

Picture this: its freezing outside, and you’re about to head out for the day. Wouldn’t it be great if your car was already warmed up and ready to go? Not only that, but that it had used an appropriate amount of energy doing so? That’s not just wishful thinking; it’s entirely possible with a bit of smart automation. In this article, we’re going to explore how I configured this for Sparky, our Tesla Model X.

The gist: I set up an automation that preheats the car, with the duration depending on the temperature. It preheats for 1 minute for every degree under 10°C, which translates to about 30 seconds for each degree Fahrenheit below 50°F.

Though, just to be clear, you could do this with any car. Back in 2014, I preheated our VW Golf using a small fan. I could just as easily create this setup for that car, simply by using a smart plug to turn on the fan. If your car has an API or preferably a Home Assistant automation it becomes even easier.

Tesla Cold Climate

Planning the automation

The basic premise of this automation is to preheat Sparky based on the outside temperature. The colder it is, the earlier the heating starts. This setup is designed for those routine weekday mornings, specifically targeting departures around 7:35.

Here’s how it works:

  1. Time Trigger: The automation kicks off at 7:00 in the morning every weekday (Monday to Friday).
  2. Weather Check: It checks the outside temperature. If it’s below 10 degrees Celsius, Sparky needs some warming up.
  3. Location Check: We ensure that Sparky is at home
  4. Dynamic Preheating Schedule: For every degree below 10°C, Sparky starts preheating 1 minute earlier. So, if it’s 0°C outside, preheating starts at 7:25.

Setting up the Automation

You can do all this in the UI, but here I’m going through the automation YAML code, and showing how it works.

Trigger

This section defines what starts the automation. Here, the trigger is time-based, set to activate at 7:00 in the morning.

trigger:
  - platform: time
    at: "07:00:00"Code language: YAML (yaml)

Conditions

We then add some conditions that have to bet for the automation to run.

condition:
  - condition: time
    weekday:
      - fri
      - thu
      - wed
      - tue
      - mon
  - condition: numeric_state
    entity_id: weather.home
    attribute: temperature
    below: 10
  - condition: state
    entity_id: device_tracker.sparky_location_tracker
    state: homeCode language: YAML (yaml)
  • Condition – Time: This checks the day of the week. The automation only runs on weekdays (Monday to Friday).
  • Condition – Numeric State: It checks the temperature from weather.home. If the temperature is below 10° Celsius, the condition is met.
  • Condition – State: This checks if Sparky is at home using device_tracker.sparky_location_tracker. The automation proceeds only if Sparky is at home.

Action

This is the part where will tell the automation what to do.

action:
  - delay:
      minutes: "{{ 35 - ( 10 - state_attr('weather.home', 'temperature'))}}"
  - service: climate.turn_on
    target:
      entity_id: climate.sparky_hvac_climate_systemCode language: YAML (yaml)
  • Action – Delay: This calculates the delay before turning on the climate system. It takes the base time of 35 minutes before 7:35 and subtracts one minute for every degree Celsius below 10.
  • Action – Service; climate, turn on: This is the command to turn on the climate system of Sparky. It targets climate.sparky_hvac_climate_system, which is the entity ID of our Tesla’s climate system in the home automation platform.

Note, we could have made the delay a part of the trigger instead, but with a quick temperature drop, we could risk that the trigger time jumps to a time in the past – this way that will never be an issue. There are other workarounds, but I’m keeping it simple.

How do you to set the temperature?

The Tesla integration would also allow me to set the temperature.

  - service: climate.set_temperature
    data:
      temperature: 22
    target:
      entity_id: climate.sparky_hvac_climate_systemCode language: CSS (css)

Enable defrosting?

Tesla’s have a “defrost” mode. You can enable this as well if you aren’t parking a garage or car-port, and therefor might be prone to a frozen windshield of even a car covered in snow.

  - service: climate.set_preset_mode
    data:
      preset_mode: Defrost
    target:
      entity_id: climate.sparky_hvac_climate_systemCode language: CSS (css)

The result

All right, so lets put it all together and look at the result

alias: Sparky Preheat
description: ""
trigger:
  - platform: time
    at: "07:00:00"
condition:
  - condition: time
    weekday:
      - fri
      - thu
      - wed
      - tue
      - mon
  - condition: numeric_state
    entity_id: weather.home
    attribute: temperature
    below: 10
  - condition: state
    entity_id: device_tracker.sparky_location_tracker
    state: home
action:
  - delay:
      hours: 0
      minutes: "{{ 35 - ( 10 - state_attr('weather.home', 'temperature'))}}"
      seconds: 0
      milliseconds: 0
  - service: climate.turn_on
    data: {}
    target:
      entity_id: climate.sparky_hvac_climate_system
mode: singleCode language: YAML (yaml)

Gone are the days of forgetting to pre-heat and getting into a cold car on a frosty morning. With this smart automation, Sparky, is ready and warm, just as we are about to step out. It also showcases how integrating smart technology into our daily routines can bring a touch of comfort, efficiency, and even a bit of joy to our lives.

I'm a webdeveloper based in Oslo, Norway. I currently work with web development at Nettmaker.

I would like to change the world, but they won't give me the source…

0 0 votes
Article Rating
Subscribe
Notify of
guest

4 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments