Home Assistant is amazing for building a smart home out of many different systems and one of the most important features of the platform are automations. However, even after the uiupdates in the recent releases, the editor still isn’t great. Especially with more complex setups that require complicated workflows, the simple, block-based ui gets cluttered quickly.
For many people, the solution to this haven other automation tools such as NodeRED. While they are amazing for complex tasks, the simple and repetitive things aren’t that efficient to maintain either.
What are Blueprints?
That’s where Home Assistant Blueprints come in: Blueprints are, as the name suggests, templates for automations or scripts in Home Assistant. They are defined and maintained as YAML files that define all the triggers, conditions and actions (just like automations). The significant difference is that you can create such a blueprint once and use is multiple times. No need to maintain 10 different automations, just one blueprint!
How to create a Blueprint?
Creating a blueprint is as simple as creating a YAML file that follows this structure:
blueprint:
name: <NAME>
description: <DESCRIPTION>
domain: automation
input: <LIST OF INPUTS>
trigger: <LIST OF TRIGGERS>
condition: <LIST OF CONDITIONS>
action: <LIST OF ACTIONS>
The exact syntax can be found in the official documentation but at a glance, you need to give some metadata, set the triggers and conditions and finally define the actions to run in the automation.
The
input:
tag defines the devices or entities that are passed to the automation that runs underneath. That’s because blueprints work by saving all devices, entities and settings as variables that are replaced with the actual devices once you create an automation (or a script) out of them.
Once your blueprint file is ready, you need to import it into Home Assistant. The easiest way to do this is to use GitHub Gist. Gist is a code snippet platform that allows you to easily share code through a private (or public) URL.
Create a new Gist, name it and pase you blueprint YAML code. Then, once you have a URL that looks something like https://gist.github.com/j4n-e4t/<some random hash>, you can open your Home Assistant and navigate to Settings > Automations & Scenes > Blueprints. When you click the “Import Blueprint” button and paste you URL, you should see you new Blueprint in the list. From here, you can now use it by just clicking on it to create a new automation.
To update the blueprint inside of Home Assistant, first update your Gist and then click the “Re-import Blueprint” in the Menu in Home Assistant.
What automations should be built using blueprints?
Generally speaking, every repetitive automation should use blueprints. An example from our current setup are motion sensors: While it might seem simple that a motion sensor turns on a light, there are many variable factors that need to be considered. Such as:
- Is it dark outside?
- Are windows open?
Since, in our house, we have many motion sensors, creating as especially maintaining those complex automations is really hard. Thanks to a blueprint, I was able to write the logic once and re-use it for every single motion sensor.
These are the basics of Home Assistant blueprints. What do you think of this solution? Are you using Home Assistant to automate your smart home?
P.S.: If you are looking for inspiration, you can check out the Awsome Home Assistant Blueprints project, a collection of many different useful blueprints for automations and scripts.
And as an addition, here in the YAML code for my example blueprint: https://github.com/e4t-home/home-assistant-blueprints
🙏 Thanks for reading.