016 - Learning Home Assistant Blueprints

I've had a Home Assistant set up for a couple of years now. However, my automations have always been fairly trivial, except for my bathroom adventure, which I really should turn into either a Blueprint or perhaps a Pyscript. This post, though, is about my first adventure with writing a Blueprint.

Home Assistant

I've got a Home Assistant set up, but to be honest, I wasn't doing very much with it. Despite my best intentions, attempts to persuade by partner that electric blinds would be great, or monitoring the soil in the greenhouse would be amazing, none of it came to fruition.

Then, in the middle of last year (2025), an event occurred that allowed me to indulge my whims and create my biggest set of automations to date, and it involved a humidity sensor and a bathroom fan. The number of automations got a bit out of hand, along with helpers to store state, simply to switch on a fan when the humidity went up, and then turn it off after a set time. However, there's also a constraint of not allowing the fan to be on longer than a certain time. There are no less than 9 automations and 6 helpers that control the switch to a bathroom fan. It's not pretty. However, it does actually work.

So, this past holiday (Christmas 2025) I engineered another opportunity to "do" some Home Assistant automations. Well, several opportunities, because there is also a (future) set of integrations around my new Texecom alarm system and Home Assistant; a story for another day. Curiously, one of the drivers for automating the lights in the bedroom are to flash the lights if the alarm is triggered. I'm a little deaf and can't actually hear the alarm! As I said, a story for another day.

Anyway, the new requirements were retrofitting a dimmer to the bedroom light, and adding bedside lights. But not just any bedside lights. No, E27 Innr Smart Bulbs for the bedside lights, another Innr Smart Bulb for the main light and two-gang Candeo RD1P dimmer in remote (REM) mode where the old, retro, single switch used to be. Also added to the mix are two Sonoff Zigbee Wireless switches - SNZB-01P that are at the bedside tables.

So the interesting concept here is that the bulbs are always powered, as are the dimmers (which are in REM or Remote mode), and Home Assistant has to do the interfacing between someone pressing a dimmer (a single click) and a bulb somewhere switching on. In fact I had quite a few requirements scattered across the controls:

  • Single click on a dimmer toggles the associated light(s).
  • Rotating the dimmer switch dims or brightens the light(s).
  • Double clicking the dimmer changes the 'scene' for the lights (essentially, rotates through a set of presets.)

And for the bedside switches:

  • Single click toggles the light on that bedside table.
  • Double click 'smart' toggles the light on the other side. If mine is off, and the other is on, switch the other off, if they are both on or off, toggle them both.
  • Long press switches all remaining lights off (at least in a group specified).

The idea is, that, if you are in bed and you've forgotten to switch the hall lights off, just long press your single switch and it goes off, ditto for any other lights programmed. Plus, the thinking is. As you enter the bedroom, switch both sidelights on from the door way. In bed, switch each individual light off as desired, and if you or your partner are away, then you can also switch off their light from your switch. The ultimate in decadence.

Blueprints

As I approached programming the lights up, I looked at the 9 automations and 6 helper variables that it took for the fan, and thought, "there must be a better way". And it turns out there is not one, but at least four, better ways:

Each of these has pros and cons, and I may write up my thoughts on them later, but I decided for this project to go with a few Blueprints, as that's largely what Gemini "said" when I asked "In 2025, what's the normal way of writing more complex automations with Home Assistant." And it 'answered' that it's Scripts (not Pyscripts) and Blueprints. After a quick search on the difference between HA Scripts and Blueprints, I started writing a Blueprint.

I actually had an existing set of Blueprints to work from. Candeo produces a nice set of dimmers switches controls and other what-not that is very compatible with Home Assistant. They are also a British family business, which is a huge plus, as I live in the UK and like to support our local businesses. They also had a set of Blueprints that included a couple for the RD1P Dimmer, and so I used that as a base.

Writing Blueprints

Writing Blueprints is actually a bit tedious. It's a YAML file with Jinja2 templating. So, as an experience, it's a bit like writing Ansible playbooks. Which is also a bit tedious. I've written, and edited, a lot of YAML files in my life, and it's not particularly enjoyable. Embedding templates inside them so you can get 'code' into them just feels a bit like a kludge. A bit like Ansible playbooks probably seemed like a great idea, but in practice they are annoying to maintain, and you definitely need a syntax highlighting editor for it. However, sadly, there is no language server for HA Blueprints, so you end up using a yaml one, and the templates don't syntax highlight. Maybe it works better in VSCode?

For me, when I have a tedious coding job, I tend to reach for OpenCode.ai, and usually the Claude Sonnet 4.5 model. And it actually works quite well. I had to do a few edits, as sometimes Claude gets indentation off one 1 char, but it managed to analyse my Blueprint, and then iteratively improve it until we had something working.

The debug cycle goes something like this:

  • "Write" code with Claude
  • Fix obvious bugs.
  • Push to GitHub.
  • Import to Home Assistant
  • Wire up to control and lights.
  • Click, etc. to test it.
  • Work out what is wrong.
  • Repeat.

You can re-import the Blueprint, and then use the developer tools (in HA) to reload the YAML files. It's the very opposite of live debugging and very much akin to scattering log or print commands in your code and then staring at the output.

After a day of this I got pretty much everything working and the result is in my Github Home Assistant Blueprints repository.

What's next?

I've got another automation do to between Home Assistant and my new Texecom alarm system. I already have the integration done, so the integration is basically "with this set of conditions, do this set of actions." The conditions and the actions are not complicated, so it's probable that I will just do it again with a Blueprint and Claude filling in the blanks. It doesn't seem complicated enough to invoke using Pyscript or other approaches. Maybe I should re-write my Bathroom automation using Pyscript as that really is a lot more complicated.

Comments: