How to Build Great Automations in Home Assistant

I am closing in on my 5th year of using Home Assistant for all of my smart home projects I have in my house. Out of all of the upgrades…

How to Build Great Automations in Home Assistant
Photo by R ARCHITECTURE on Unsplash

I am closing in on my 5th year of using Home Assistant for all of my smart home projects I have in my house. Out of all of the upgrades that have been made to the software, I think the automation feature has had some of the best improvement. When I first started using Home Assistant I struggled to find a lot of great use for the automations page, but now I find myself using it all the time to create useful things.

Overall I use the main automations page for most things, but I created a few scenes and scripts as well. The scenes can be very useful for creating quick actions on your Apple Watch, I will dive into this later.

Automating Lights

One of the most common automations I created is to automate the different lights throughout my house. The automations vary from having lights shut off after being on for a certain amount of time, having some lights turn off and on with sunset and sunrise, and other lights being controlled by smart buttons placed around the house.

Sunrise & Sunset Automations

I will start with a fairly simple automation, having lights turn off and on with the sunrise and sunset. I use this one to automate a light bulb on my front porch as well as the lights to my basement staircase so our dogs can navigate the stairs at night without falling and getting injured.

To create this automation:

  • Go to the automations page and click create new automation
  • Under the “When” section click “Add Trigger” and select “Time and Location” → “Sun”
  • Choose if you want sunrise or sunset
  • Next go to the “Then Do” section and select “Add Action” → “Light”
  • Select Either “Turn Off” or “Turn On” based on what you are trying to do
  • Next click “Choose Entity” and find the light you want to control with this automation
  • Click Save and give your automation an name
Your Automations should look similar to this.

This will create a basic automation for you that will tell a light to turn off or on at sunrise or sunset. You will need to create a second automation to change the light to a different state, so if you just automated a light to turn on at sunset, you will need to create a second automation to turn it off at sunrise.

Remote Button Automations

My house was not build with enough light switches to satisfy our needs. To solve this problem without having to hire an electrician to rewire our lights, I purchased wireless buttons that are connected to Home Assistant. These buttons have three modes. Single Press, Double Press, and Long Press. This allows you to create some simple but useful automations.

For example a single press on the button in our living room will turn on our lamps in the room, a double press will turn them off. With the third option of a long press I can turn on a third larger lamp in the room for extra lighting if we need it. The great thing about this is I don't need a fourth automation because the same automation for the double press to turn off the lamps will also turn off the larger lamp if it is on as well.

Here is what the automation to turn it off looks like:

HVAC Automations

Getting a little deeper into creating custom automations, I have set up some automations and scripts to control my thermostat and HVAC system in my house. My home is a little bit older and doesn't have the most efficient climate control. For example, my sons room will occasionally be colder than the rest of the house when the outside temperature is quite low. To prevent my toddler from becoming a popsicle I have a temperature sensor in his bedroom to automate the thermostat to turn on more heat.

Automate a Room Temperature

When his bedroom gets below 66 degrees Home Assistant sends me a notification via the mobile app and then turns up the heat for 15 minutes before setting it back to the normal setting.

Here is how the automation works:

  • The trigger for the automation is set as a temperature threshold for the sensor in his bedroom
  • Once the automation is triggered a notification is sent to my phone, This helps me keep an eye on how often his room is getting cold
  • Next Home Assistant sets the thermostat to 74 degrees
  • Then there is a 15 minute delay
  • The last step is for Home Assistant to set the thermostat back to 70 degrees which is our normal heat setting

HVAC Scripts

Another useful tool in the automations page of Home assistant is Scripts. A script can be built and then placed on your dashboard as a button to run it. I have created two scripts in Home Assistant for my HVAC system, they are both used to control the blower fan of my furnace. The entire process behind this is a bit more in depth than what I am covering in this article as it also uses Node Red behind the scenes to make this work.

The basic concept behind creating a script is very similar to creating an automation. After naming your script and selecting your mode, you build it just like you would an automation. The biggest difference is on your dashboard you can choose your script as an entity when creating a card.

Here is what mine looks like:

This is the Script Settings
This is how the entity card is setup
This is the entity card

This script allows me to turn on only the furnace fan for my house for a set amount of time to circulate air.

Controlling and Integrating 3rd Party Devices

Some of my newest integrations are using my Apple HomePod to announce when doors are opened, getting critical alerts on my iPhone, and using my Apple Watch to control scenes.

Text to Speech with an Apple HomePod

I recently purchased an Apple HomePod and installed new wireless door sensors on my exterior doors. This led to an idea of having the HomePod announce when a door was opened, which comes in very useful with a two year old running around the house.

To accomplish this you’ll need to install the Apple TV integration and setup your HomePod with it, it should be automatically discovered on your network after the integration is installed.

It's worth noting that if you have an Apple TV, you will most likely need to remove it from Home Assistant if you have it set-up already. I was not able to have both devices added to the integration.

Next you will need to create an automation that calls the TTS service after being triggered by another action.

My HomePod TTS Automation

Getting Critical Alerts on IOS

Another automation I setup for the door sensors was to get critical alerts on my phone if a door was opened and my wife nor I were home.

Critical alerts are alerts that can bypass any do not disturb or silent settings on your phone and will produce a loud alert no matter what.

To set up critical alerts in your automation you need to add some extra configuration to the notification section in the automation.

Here is the full yaml config for the alerts

alias: Door Open Phone Alert 
description: "" 
trigger: 
  - platform: state 
    entity_id: 
      - binary_sensor.front_door_sensor_opening 
      - binary_sensor.back_door_sensor_opening 
      - binary_sensor.kitchen_door_sensor_opening 
    from: "off" 
    to: "on" 
condition: 
  - condition: not 
    conditions: 
      - condition: zone 
        entity_id: person.grantsphone 
        zone: zone.home 
      - condition: zone 
        entity_id: person.wifesphone 
        zone: zone.home 
action: 
  - service: notify.mobile_app_grants_iphone 
    metadata: {} 
    data: 
      message: " A Door Was Opened at Home" 
      data: 
        push: 
          sound: 
            name: default 
            critical: 1 
            volume: 1 
mode: single

Using an Apple Watch to Control Scenes

Lastly, the last thing I want to cover is using an Apple Watch to control scenes in Home Assistant. With the Home Assistant app installed on your iPhone, you can set-up a watch complication for your Apple Watch that can run custom scenes in Home Assistant.

From the settings page of the app navigate to “Companion app” → “Apple Watch” and you can customize the watch complication from there.

You will need to have a scene created in Home Assistant for the watch to control. For example, I have a scene that when set will turn on a fan in our bedroom that I can quickly do from my Apple Watch while in bed.

Conclusion

These are just a few of the awesome things that you can do in Home Assistant. In the future will dive deeper into more customized integrations and how to configure them into Home Assistant. Such as: ESPHome, Node Red, and HACS integrations.