Home Assistant: Scheduling the car heater

Winter is coming once again and pre-heating car is needed when the temperature drops below five degrees. This automation is something that I wrote to a friend of mine and he has been using it for a year now for two cars, so I’d say it’s usable since I’ve had no complaints about it πŸ™‚

Full package can be downloaded from my GitHub repository at https://github.com/kotope/ha_car_heater

(Note 10.12.2021: The old version automation will break with Home Assistant release 2021.12, since time format changes on the Home Assistant end. Fixed version of the automation is available at GitHub link above (basically just changing all timestamp_local -> timestamp_custom)

This is automation is based on existing automation, but this has quite many tweaks compared to the original. Original can be found from here (thanks to the original author as well).

What does it do?

The grand idea is to make pre-heating car as simple as possible. You set departure time from Home Assistant UI and the automation handles the rest.

Of course below the hood there’s more logic:

  • User sets the departure time from UI
  • Automation calculates how long should the heating be on using current temperature
    • Will run only if temperature drops < 10
    • Formula: temperature * -0.05 + 1
      • Summary: -30c = 2.5h; -20c = 2h; -10c = 1.5h; 0c=1h; +5c=0.8h
  • 3 hours before departure automation re-checks the temperature and does adjustments to heating time
  • At calculated heater start time checks the power comsumption of the plug
    • If power consumption stays at zero, send push notification to user to check if power cable is connected
  • Stop heating at departure time

Also there’s also a text included that shows the current status of the automation.


Required and optional hardware for this to work:

  • Home Assistant supported outdoor plug with power consumption support (e.g. Nedis Outdoor plug flashed with Tasmota. Note: latest Nedis plugs might contain other than ESP8266 and cannot be flashed to use Tasmota)
  • Home Assistant supported Outdoor temperature sensor (OPTIONAL)


Automation is created as a package, because it includes input components, helpers and automations. Download the car_heater.yaml package from https://github.com/kotope/ha_car_heater/blob/main/car_heater.yaml and copy to Home Assistant configuration directory. The package can be set up by adding it to configuration.yaml like this:

    car_heater: !include car_heater.yaml

After including the package in the configuration file, we should setup proper entities in the package file. Entities that needs to be added are: (All changed entities are marked as #CHANGE-ME in the car_heater.yaml file).

Car heater power switch

entity_id: switch.car_heater

This switch is the main switch entity that connects the car heater to the power socket.

Car heater power consumption

entity_id: sensor.car_heater_power

This is the power consumption sensor used to verify, that the power cable is physically connected.

Temperature sensor

entity_id: weather.home.attributes.temperature

Outside temperature sensor that is used to calculate proper heating times. This can be used from local weather service integration or some separate temperature sensor.

Notification entity

service: notify.mobile_app_samsung_s10

Service id to send notification, if the power cable is unplugged.

…and restarting

Finally after changing entities and devices it’s time to verify the config and restart the Home Assistant configuration interface.

Example UI

For the UI, I’m trying make it as simple as possible. In stock Home Assistant there’s not a very usable time picker car so with this UI I’m using a custom card called time-picker-card (also installable using HACS).

Example UI has time picker for scheduled departure, enable only weekdays switch, enabling/disabling the scheduler, manually controllable car heating plug, run time length and start time. Also some status information along with current outside temperature.

Example UI can be also downloaded directly from GitHub: https://github.com/kotope/ha_car_heater/blob/main/sample_lovelace_ui.yaml.

44 Replies to “Home Assistant: Scheduling the car heater”

  1. Awesome!
    I was googling this today on the 25th so the timing could not have been better!

  2. Hi,

    I have 6 of those Nedis plugs with flashed Tasmota’s from Puuilo and Motonet and now one for the Car heater just got this automation! Thanks.

    Too sad that new ones has that Beken chip.

    The old patch of the Nedis WIFIPO120FWT devices are still in sale. Working ones has that “works with Amazon Alexa and Google Assistant” in the Circle.

    Non working devices has fancy Alexa and Google logos at the right bottom corner of the package.

  3. Great automation, Toni! A couple of questions from a Home Assistant newbie:

    -Where do I find the Device ID to use for receiving notifications?
    -The calculated run time is always 2.5h regardless of the outside temperature, some examples of what I’ve tried so far:

    value: ‘{{ states.sensor.temperatur_ute }}’
    value: ‘{{ sensor.temperatur_ute }}’
    value: ‘{{ states.weather.********.attributes.temperature }}’


    Jesper from Sweden

    1. Hi!

      An excellent first question! I snooped around, but could not actually find the device_id anywhere anymore.. a long time ago it was visible in Home Assistant Companion app, but could not find it anymore. (I’ve been just copy pasting the device_id from another automations so far).

      You can replace the notification sending by changing it to call entity instead like this:
      – service: notify.mobile_app_samsung_s10
      message: Car heater
      title: Car heating power cable is not connected!

      For the second question I’d suggest to use the developer tools template editor to find the proper outside temperature sensor and it’s value. (You can also use developer tools ‘states’ view to find the proper entity first).

      My outside temperature works with value:
      {{ states(‘sensor.temperature_outdoor’) }}

      ..and through the weather integration:
      {{ states.weather.home.attributes.temperature }}

      However, that is totally dependant of your entity or weather integration you are using.
      Point is to get numeric decimal value out of outside temperature value.

      Ps. I will update the automation template from GitHub to support this new style notification sending in few days. Thanks for mentioning this issue πŸ™‚

  4. Thanks a lot for the reply! I managed to fix error no 2, but the notification problem is still there, so I’ll wait until you update it on GitHub!

    1. Hi,

      Finally had time to make the changes.
      So the notification service is now changed on the GitHub code and also fixed one small issue in the same automation block (had extra ‘ slipped in accidentally).

      Feel free to try it out now and please send me some feedback if it works properly now πŸ™‚

  5. Thank you so much!

    Works perfectly fine with notifications and all. I would just want to modify one thing and that is to make the run time a little bit longer. What should i change and to what to extend every activation with say 30 minutes or so?

    1. Hi and thanks for the feedback!

      Runtime calculation can be found from car_heater.yaml line 194:
      {{(states(‘input_number.car_heater_3h_before_temp’)|float * (-0.05) + 1)|round(1)}}

      As mentioned in this article the formula is: (temperature * -0.05 ) + 1
      So if you like to add static 30min (1/2 hours) to all calculated values you could modify the formula like: (temperature * -0.05 ) + 1 + 0.5

      Changing the line 194 as below should do the trick:
      {{(states(‘input_number.car_heater_3h_before_temp’)|float * (-0.05) + 1 + 0.5)|round(1)}}

        1. I have to correct myself. It doesn’t work as I thought. I seem to have the same issue as Jesper above, but for me the calculated run time is fixed at 1.8 hours (without the addition of the 30 minutes from the previous question). I have tried all variants with both weather- and sensor attributes and if I use the developer template the correct value is displayed. I just can’t get that part to work.

          1. Can you send me your car heater package (with your entities in place) and I’ll check the validity of it and try to reproduce the issue on my own environment?
            If yes, please send it to creatingsmarthome (at) gmail.com and I’ll have a look on it.

  6. Thanks for the automation, just what i was looking for! There will be cold in Finland soon!

  7. Hey.
    I don’t understand how the outdoor temperature sensor should increase. The calculated run time is always 2.5h regardless of the outside temperature. I have tried many different options to replace this.
    value: ‘{{states.weather.home.attributes.temperature}}’

    For example, this
    value: “{{states.sensor.ulkolampotila}}” This does not work.

    1. Hi!

      Please try to add that “{{states.sensor.ulkolampotila}}” in ‘developer tools->template editor’ section of your Home Assistant to verify that you get the value properly from that device.

      And just to clarify that the runtime is only updated in two states of the automation: when enabling the timer and second time three hours before departure time.

      Please post the results of your template editor and lets continue troubleshooting πŸ™‚

      1. β€œ<template TemplateState()>”

        but still not working. did i need to add my own outdoor temperature sensor to just one line?

        1. Hi,

          That response from developer tools/template editor is wrong. You should get proper temperature value out of it, like ‘-10.0’. That means that your entity is wrong in the automation as well.
          Temperature entity is in two places of the package (marked as CHANGE-ME comment in the yaml file).

          So, try to find the proper entity for your temperature or weather sensor (which ever you want to use).

  8. {{ states(‘sensor.ulkolampotila’) }}

    Result type: string

    This template listens for the following state changed events:

    Entity: sensor.ulkolampotila

    Configuration invalid

    if i put this on it still won’t work.

    Error loading /config/configuration.yaml: invalid key: “OrderedDict([(“states(‘sensor.ulkolampotila’)”, None)])”
    in “/config/packages/car_heater.yaml”, line 14, column 0

    1. Great
      Had the same issue. Your code solved it!
      I use the outdoor sensor of my Nibe heat pump.

  9. I have a Nedis outdoor plug of the latest model. As I understand it, that contact is not able to control the car heater. To make it work which outdoor plug should I buy?

    1. Hi!

      I’ve been only using the older Nedis outdoor plugs myself so I really can’t guarantee any other models to work. However the automation should work with any other outdoor plug as well that has a power consumption measurement and HA support.

      Few key points I’d suggest:
      – Search for an outdoor plug with local connectivity rather than a cloud
      – Enough amperages to handle car heater loads (16A)
      – Power consumption measurements
      – HA support (obviously)

      I can recommend Shelly 1pm, but it needs to be installed inside an electrical socket.

      However, you should be able to make the latest Nedis model to work as well. Just install it on HA with Tuya integration.
      One thing about automation you might have to chgange is the interval when checking if the car heater cable is connected. Few key steps:
      – Turn on the plug through home assistant
      – Measure the time it takes to actually update consumption value on Home Assistnt end after turning on the plug
      – Change the measured value into automation line 48 (timeout: 00:00:35)

    2. Hi
      I donΒ΄t know i you solved your issue with a new Nedis smart plug. I use one myself and IΒ΄ve managed to get it to work without flashing the device. Added the plug via Tuya intergration. In entities the sensors were deactivated by default. Activated the three sensors. My enitites are called:

      Since the original code was sensor.car_heater_power i used the first sensor in my solution.

  10. Is it absolutely necessary to have Tasmota? Could you not just use any smartplug? For example a Shellyplug with original firmware?

    1. Hi,

      Yes of course you can use any smart-plug.
      However, you might want to tweak notification time at line 48 (timeout: 00:00:35) depending on how fast does your smart-plug notify about changed power consumption

    1. Hi!

      1. Copy car_heater.yaml to car_heater_2.yaml
      2. Change all ids of automations, input values and sensors to something unique (e.g.car_heater_status_2, car_heater_3h_before_start_time_2, car_heater_on_timer_2, etc…) for the newly copied yaml
      * Remember to also change references inside the automations
      3. Change the correct entities for the second car
      4. Add also the second yaml file to packages in configuration.yaml
      car_heater: !include car_heater.yaml
      car_heater2: !include car_heater_2.yaml

      1. Sweet, thank you so much for this automation.
        Is it possible to change the calculations? Lets say its -1 here, now it starts an hour before departure, i would like to up the time a little bit. Maybe 1.5 hours before departure.

        1. I figured out the start time, i changed the calculated value like this: float * (-0.05) + 1.5)

          But about adding the second car. Could you make a list where the entries needs to be changed? I started, but unsure on quite a few if they need to changed or not πŸ™‚

          1. Hi,

            Please send me an email to creatingsmarthome (at) gmail.com and I’ll send you car_heater_2.yaml file that you can use (of course remember to change your own entities in it) πŸ™‚

  11. Really useful automation! Just what I have been searching for.

    I was a bit worried when the times stopped working after HA update but the solution was waiting for me at your site. Thanks for that!

  12. Hi,

    Thanks for the great automation!

    If i want to manually set run time, how can i do that ?

    1. Easiest way would be to set ‘car_heater_run_time’ to something static (or maybe change it to input_datetime to be able to set it manually every time you want).
      However, that would leave quite much of the automation void and there would be some non-required stuff in automation as well.

      I would most probably start from the scratch and just take bits and pieces from the current automation.

  13. Thanks! This was easy enough to implement =)
    Works like a charm…

    Now if only there was like a Calendar to this πŸ˜€
    Calendar where you could input multiple departure times per day… I work mostly from home these days. Still every morning I gotta drive the kid to kindergarten and then in the late afternoon I fetch her home. Now I got two separate cards and automations running to achieve this

  14. Nice automation and I am very happy that you have shared the setup. What do I need to adjust if I want to delay the stop of the car heater with say 1 hour? Sometimes the departure time can be delayed and I dont want the car to become cold again…When I leave a simply unplug the cord so no worries if the timer is delayed for me. Thanks

    1. Hi,

      I might have not undestood your question properly, but maybe you could just simply increase the departure time when you want to delay the start?

      1. That could be one way of course and maybe the simplest but I can try to explain a little bit more. If I schedule to depart at 08:00 but I am late for some reason and leave first at 09:00 I dont want the automation to stop at 08:00. The automation could continue for another hour or two to avoid a cold car. Then if I leave 08:00 (or 08:30 if I am late) I unplug the cable from the car which results in zero energy consumption so it dosent matter if the automation is still running. With this little tweak I dont have to adjust the departure time (I bet I am in hurry if I am late πŸ™‚ ). And the status information in Home assistant will also be correct which is nice

        1. Thanks for clarifying it, now I understand your needs πŸ™‚

          in car_heater.yaml at line 105 there’s a following condition that turns off the plug at departure time:
          value_template: ‘{{ now().time().strftime(“%H:%M:%S”) == states.input_datetime.car_heater_departure_time.state }}’

          If you add a static value in that same condition in that automatio (turning off the switch) you should get what you are looking for.. like this:
          value_template: ‘{{ (now().strftime(“%s”) | int + (60*60)) | timestamp_custom(“%H:%M:%S”, false) == states.input_datetime.car_heater_departure_time.state }}’

          60*60 is offset in seconds (60 seconds * 60 minutes = 1h).
          So by replacing the line 105 with code abofe, the plug turn off should be delayed by one hour from departure time.

          Ps. I did not test that, so please try it out before actually using it so you won’t get a cold car in the morning πŸ™‚

          1. So now I have had time to test the code but it gives me the following error:

            Logger: homeassistant.config
            Source: config.py:464
            First occurred: 12:30:06 PM (1 occurrences)
            Last logged: 12:30:06 PM

            Invalid config for [automation]: invalid template (TemplateSyntaxError: unexpected char ‘β€œ’ at 19) for dictionary value @ data[‘condition’][0][‘conditions’][0][‘value_template’]. Got None. (See ?, line ?).

            I have tried to find the error but no luck so far…do you see something that needs to be changed?

          2. Hi,

            If you copy-pasted my suggestion in previous reply, ensure that ‘ and ” marks are correct. It seems that WordPress seems to format those a bit wrong and are not actually proper quotes.

            If you still are having issues, could you send your car_heatear.yaml to creatingsmarthome (at) gmail.com and I’ll have a look πŸ™‚

  15. Hi,

    Thanks for the great automation!

    I tried to add this to my HA. But I keep gettings this error in my configuration:

    Error loading /config/configuration.yaml: while parsing a block mapping
    in “/config/packages/car_heater.yaml”, line 34, column 5
    expected , but found ‘-‘
    in “/config/packages/car_heater.yaml”, line 46, column 5

    What am I doing wrong? I can mail you my car_heater.yaml with my entites if tou want to take a look?

    1. Hi,

      Please send the configuration to me on creatingsmarthome (at) gmail.com and I’ll have a look πŸ™‚

  16. Thank you!!! Bumped in this exactly when looking to build a scheduler for car heating, in Finland as well πŸ™‚

Leave a Reply

Your email address will not be published.