Home Assistant Automations – 2 Ways

“Smart-Home” and “Home Automation” are terms that seem to be used interchangeably often, though they really shouldn’t be. A Smart-Home is the all encompassing term for the home system that is connected to the devices in the house. It can be controlled using direct control, like using your smartphone, voice, or buttons. Home Automation is something a Smart-Home is capable of carrying out without direct control. Here are some examples:

  • Having your lights turn on or off with a timer
  • Having your stuff turn off when you leave the house.
  • Have your TV turn on when you get home for the day.

I’ll go over 2 ways to set up automations within Home Assistant. You can create them using the .yaml files, or with the Automations editor. To learn about everything automation, I recommend checking out the documentation. I find the .yaml files to be more efficient, but think it’s important to share both options. Both sections will create the same automations.

Creating Automations Using .yaml Files

  • First thing you’ll need to do is navigate to your automation.yaml file.

Screen Shot 2017-09-23 at 7.29.42 AM

  • Now, think of something you want to automate.
  • I have my fish tank’s light on a daily timer. It turns on around the time I leave work so it’s on when I get home.
  • This is a simple timed automation using a time trigger. It looks like this:

Screen Shot 2017-09-24 at 8.45.42 AM

  • Automations typically consist of 3 parts: a trigger, a condition, and an action. This first example, doesn’t have a condition. Instead, it turns on every day at 4:30pm no matter what.
  • Let’s do a simple automation and include a condition. At 6:00, if it’s a workday, the lights will turn on.

Screen Shot 2017-09-23 at 9.02.03 AM

  • Here I use a workday binary sensor as my condition. I added the sensor to my configuration.yaml file, and specified my region.

Screen Shot 2017-09-23 at 8.04.34 AM

  • After editing the .yaml files, remember to save, check your configuration, and restart Home Assistant.
  • A binary sensor simply shows “on” or “off.” You can see its state in your Developer Tool’s States section.

Screen Shot 2017-09-23 at 8.23.56 AM

  • Remember, new entities will be hidden if you’ve changed your default view. If you want to see your automation’s switches, you can create a group or tab for them.

Screen Shot 2017-09-23 at 8.33.27 AM

  • After checking your configuration and restarting, you’ll now see your automations in their assigned group.

Screen Shot 2017-09-23 at 9.14.27 AM

  • There ya have it! Now get started automating more stuff!

Creating Automations Using The Automation Editor

*Automations created using the Editor will not be reachable by your Custom Alexa Skills. You’ll need to build them in the YAML file due to naming issues from the Editor*

Hass.io introduced some new tools for configuring some files from the front end. One of those tools is the automation editor. It can be found in the configuration tab. I’ll show you how to use it by rebuilding the same automations I just made with the .yaml file.

Screen Shot 2017-09-23 at 9.26.10 AM

  • First up is a simple timed automation with no conditions. I have my fish tank’s light on a daily timer. It turns on around the time I leave work so it’s on when I get home.

Screen Shot 2017-09-23 at 9.31.43 AM

  • The service data is in JSON format.

Screen Shot 2017-09-23 at 9.33.32 AM

  • Save that and you’ve made your first timed automation!

Screen Shot 2017-09-23 at 9.33.43 AM

  • The next automation will use a condition. At 6:00, if it’s a workday, the lights will turn on.
  • Here I use a workday binary sensor as my condition. I added the sensor to my configuration.yaml file, and specified my region.

Screen Shot 2017-09-23 at 8.04.34 AM

  • A binary sensor simply shows “on” or “off.”
  • After adding it to your configuration.yaml, check your configuration and restart Home Assistant.
  • You can now see it’s state in your Developer Tool’s States section.

Screen Shot 2017-09-23 at 8.23.56 AM

  • Back in the Automation editor you can now use this binary sensor in your automations.

Screen Shot 2017-09-23 at 9.48.02 AM

Screen Shot 2017-09-23 at 9.48.20 AM

Screen Shot 2017-09-23 at 9.49.10 AM

Screen Shot 2017-09-23 at 9.49.15 AM

Screen Shot 2017-09-23 at 9.49.20 AM

  • After you’ve made your automations, you may want to be able to turn them on and off.
  • Remember, new entities will be hidden if you changed your default view. If you want to see your automation’s switches, you can create a group or tab for them.

Screen Shot 2017-09-23 at 8.33.27 AM

  • Check your configuration and after restarting Home Assistant, your can access your automations from the front end.

Screen Shot 2017-09-23 at 9.14.27 AM

  • Now you know the ins and outs of making automations within the .yaml files and using the Automation editor.
  • I think it’s helpful to know how to do both. Personally, I find using the .yaml files easier than the editor but wanted to provide both techniques.

The true power of automations really shine when utilizing sensors. Like having your lights turn on when you open the door. This makes direct interaction with the system less necessary. The Xiaomi mijia Smart-Home kit is probably the most affordable way to integrate sensors into your system.  Home Assistant has also been making great strides in supporting their devices. Keep an eye out for future posts using these devices.

Automations are only one way to control your devices. Scripts can also be used to fulfill different requirements. If these guides have been helpful to you , please share them! If you have any questions, please reach out to me in the comments. Thanks for visiting!

6 thoughts on “Home Assistant Automations – 2 Ways

  1. Can you also show how you would turn off your lamp or fish tank? (via automation)
    Would this be its own automation or part of the original?

    This guide was super helpful! It allowed me to have my exterior lights turn on at sunset. (Which is why I am asking about them turning off)

    Like

    1. My fish tank has it’s own “off” timer, but my entry light turns off with my bedtime script. Did you use the yaml files or the editor? In the yaml files it looks like this.

      - id: daily_fish_tank_off
      alias: Daily Fish Tank Off
      hide_entity: true
      trigger:
      platform: time
      at: "22:00:00"
      action:
      service: switch.turn_off
      entity_id: switch.fish_tank_light

      The formatting is weird in this comment. You can check out my automations.yaml file here: https://github.com/looknsharp/homeassistant/blob/master/automations.yaml

      Like

      1. Ive been using the editor but am comfortable in the YAML.
        This helped, I did just end up creating an automation for them to shut off. I am only in the beginning stages so only a couple options thus far. I am sure that I will create more groups like yours.

        Thanks for the links and the help!

        Liked by 1 person

  2. Stumbled upon your guide and found it super helpful! Well done and really appreciate you taking the time to create this tutorial to get us all started, up and running with our first automation scripts!

    The binary sensor stuff is great, never heard of “workday”, looking at all of the binary sensor components over at homeassistant.io I was wondering if you had any other favorites you find you use a lot?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s