Simple thermostat scheduler in Home Assistant

Ever since I moved, I wanted to replace my dumb heating thermostat with Home Assistant, because I would like to be able to turn the heating off when I go away for a few days, but mainly because it would be nice to be able to turn it on a few hours before coming back home.
The new Home Assistant's thermostat card

So, eventually I placed a few Xiaomi temperature sensors around the house, replaced the thermostat with a wifi relay, combined it all together with the Generic Thermostat component, but one important thing was missing: a way to schedule when the temperature should be set to high (comfort mode) or low (eco mode). In my dumb thermostat I was able to set an hourly schedule for each day of the week, since I don't want the heating to be running 24/7. Unfortunately, there is no component to do this in Home Assistant, but since we do have the Python Scripts component, I decided to write a simple Python script to handle my scheduling, along with a simple automation that runs it every 10 minutes:

At the beginning of the script there are two lists: one for weekdays and another for weekends. Each element on those list contains an hour interval where the thermostat target temperature should be set to high. Outside of those intervals, the temperature should be set to low.

If you want to use the script, just change the schedule according to your needs, set the correct TEMP_HIGH and TEMP_LOW values, and set the climate_entity with the entity_id of your thermostat in Home Assistant. No need for external calendars, AppDaemon (although it is great) or external services, just a simple Python script!

Comments

  1. Hi, thank you for this script. Is there a possibility to use the externe Xiaomi temp Sensor to set the „current_temp“ ?

    ReplyDelete
    Replies
    1. Yes, that's what I'm using. You just configure the Generic Thermostat integration to use it as target_sensor. See https://www.home-assistant.io/integrations/generic_thermostat#target_sensor

      Delete
  2. I had to modify the automation to use
    - platform: time_pattern

    instead of just time. I am not sure if that is a new thing in home assistant but it would not work until I made that change.

    ReplyDelete
    Replies
    1. Yes, it changed after I made this post. I've updated the post now. Thanks for letting me know!

      Delete
  3. The scheduler is working great. Thanks for the python script for the scheduler. I have found, however, that the notification does not work for me. I see it calls something called notifications_send but can't find it anywhere in home assistant. I can find a notify.notify service. By any chance has that also changed?

    ReplyDelete
    Replies
    1. The script.notifications_send is just a script I have that handles notifications for me. You can use any service you want to send notifications, since the format should be the same.

      Delete
  4. Indeed, I am no python coder (yet) but managed to bang out the changes. Using the HA notify service I got the following working.
    ```
    # also send a notification so that I know that it changed the temperature.
    hass.services.call('notify' , 'notify', {'title' : 'HA: Changing thermostat',
    'message': 'Changing temperature to {} (was at {})'.format(new_temp, current_temp)})
    ```

    Thanks again.

    ReplyDelete
  5. I'm looking to have one set temperature starting at sunrise, and another temperature starting at sunset. Would it be possible to use the script in that way ?

    ReplyDelete
    Replies
    1. If you just want to have those 2 points in time, you can just use an automation (or two, if you don't want to deal with conditions), that calls the climate.set_temperature service at those times. You have sunrise and sunset triggers already.

      Delete
  6. This article taught me some good tips when installing a water heater. Thanks for the guide.
    cosmopolitanmechanical.ca

    ReplyDelete
  7. if datetime.datetime.now().date().weekday() < 5:
    current_schedule = WEEK_SCHEDULE

    wouldn't this code only select week_schedule for days 1, 2, 3 and 4? After all, 5 is not smaller or grater than 5 :)

    ReplyDelete
  8. Thank you, i customized you program for me and work perfect! Because I work twelve hour shifts then i cant use standard schdule

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. Looks great, but where do I put the 2 files? Should they be called from configuration.yaml?
    Thanks!

    ReplyDelete

Post a Comment

Popular posts from this blog

How to trigger Alexa routines from Home Assistant

Home Assistant: Notify when a light was left on and no one is at home