#Using State Machines and DigitalAlchemy to handle tricky automations

1 messages · Page 1 of 1 (latest)

limpid sparrow
#

I was dissatisfied with the flakiness of some of my automations around my 3D printer yesterday afternoon, so I sat down and rewrote them using a neat little Finite State Machine system

I wrote up a (far too long) blogpost about it here: https://pdx.su/blog/2025-06-15-improving-my-homeassistant-automations-with-state-machines/

pdx.su

A little over a year ago, I migrated the bulk of my HomeAssistant automations from NodeRED to DigitalAlchemy, a TypeScript based automation system. Since then, I've slowly been adding more and more automations, of varying complexity…

#

tl;dr: Xstate and DigitalAlchemy let you do some pretty cool things, with flowcharts!

bright ridge
#

that looks great!

#

making mental note for my overly complicated weather-and-calendar-and-alerts-and-time-of-day lighting scheme

limpid sparrow
#

It took a little bit of time to get the hang of xState, mostly because I was trying to make it do what I'd do with an elixir gen_statem, but once i stopped trying to do that and did things the way xState wanted me to, it was shocking how fast it was to iterate and get something working.

#

And no matter how many times I tried to break it (in a fake env) i couldn't get it to lock itself into a corner

bright ridge
#

oh excellent

limpid sparrow
#

There were a few things that were sparsely documented, but obvious once you understand how it all works. The one that gave me the biggest pause was the "global" powerOff transition. Eventually I realized that the top level state machine is just that, a state machine, and accepts on just like the child states would

bright ridge
#

furious scribblings

limpid sparrow
#

If you do get it set up, i'd love to see what you come up with, or help rubber-duck the tricky parts haha

#

I'm trying to think about how to fix my roof trim sports lights feature; wanted it to go to team color when my team wins and off when they lose, but never got it working how i wanted and gave up.

kind of in the "everything is a nail" phase haha

bright ridge
#

literally the best phase

#

almost a year in, that's where I'm at with both HA and 3D printing 🙂