Home Automation Config Updates

Home Assistant Home Automation

Back Home

This may not be worth an update, but I think the ides is really cool, so I’m gonna write an update about it.

Previously, my config files for the home assistant configuration were a series of large flat files that were more than about 400 lines of yaml configurations. Who want’s to go through that when you’re adding removing, or even debugging an automation for that matter?

Introduce !include. Include does exactly what it sounds like, It includes another file that can be used in the template you’re editing.

I’ve used includes in 2 main ways:

For use within automations.yaml

This file is the main configuration file for all automations within Home Assistant. Previously, as I mentioned, this file was more than 400 lines of code. I’ve broken each automation into its own file and placed it in it’s own automations directory. This has taken the main file from 400 lines of code down to 16, because as of this post, I have 16 automations. Of course If I move over to Home Assistant as my main automation platform, I’ll have many more automations.

The next way I used !include is…

For use within condition blocks

Instead of having the same condition in multiple places, I write the condition yaml and stored it in it’s own easy-to-read file. This way, when I’m writing the conditions for an automation, I don’t have to re-write the same logic over and over and over again: code re-use at it’s finest!

You can see an example below where I’m changing the House Mode from Night to Morning. The [easy-to-read] conditions say that we only want to transition the house if there are no guests, the house is in “Night” mode and we’re not in “Movie”. However writing this, I realize this is a bit redundant to be sure we’re in “Night” and not “Movie”… I’ll be sure to fix that next.