Okay, I started trying to extract more pieces of code from my base setup, but then decided to create a simplified version to share.
I’ve done this and put it on GitHub (because there are quite a few files and that’s the easiest way to share them).
I’ve updated my Home Automation topic with the details: