Home Assistant[1] is the best approach I've found for this. It's pretty amazing but has a pretty steep learning curve (although they're getting better and better at this). The real power of HA is the rich integration ecosystem[2], the Community Store[3], and that it runs locally (more reliable and much faster for things like motion sensors, etc).

It expresses everything from every integration as an entity in various device classes so as long as some random tech is supported by an integration you can group them seamlessly. For example - I have Z-wave based motion detectors but I can control Hue lights and Wemo switches for motion detection - but only if I'm home as reported by the zone feature in their iOS companion application.

Their supervisor/docker based install for Raspberry Pi is pretty slick[4]. Write an image to disk as you usually would and you get a bare-bones OS with Home Assistant running in docker. Then there are additional docker-based add-ons you can install for stuff like MQTT, Z-Wave, Let's Encrypt, SSH access, nginx, and more. All managed in the web ui. Pretty cool.

[1] https://www.home-assistant.io/

[2] https://www.home-assistant.io/integrations/

[3] https://hacs.xyz/

[4] https://www.home-assistant.io/installation/raspberrypi

I'm still figuring out Home Assistant. I love that it has a real ecosystem and that it seems to have a decent HTTP/WebSocket API (that I just started playing with).

Some things I don't love:

* A lot of the integrations seem half-baked or to not quite fit the generic Lovelace cards. I think to some extent this is an inherent problem in supporting a lot of devices that have crappy, non-standardized APIs. Example: if I bump up the low temp on my Venstar thermostat on the Home Assistant dashboard, Home Assistant will immediately set it back. If I dig through logs, I see the thermostat complained that in auto mode (heating or cooling as needed), the low set point and the high set point have to be (at least) six degrees apart. When I adjust the thermostat through its own touch screen, the high set point automatically raises to meet that constraint. Home Assistant should do the same. I've been meaning to look into fixing it myself, but there seem to be weird things like this on every integration.

* You need multiple automation rules to do almost anything. I think it's common to want the state of one thing to match another (for example, garage door open => sticky notification on my phone, person in driveway after sunset within last 5 minutes or switch on => driveway light on). You need a rule in their YAML DSL to for the off->on transition and another for the on->off. It'd be nice to set a rule that defines a level rather than an edge and have it internally do the transformation. It'd also be nice to define the actions of a notification's buttons inline, rather than as a separate automation.

* The companion Android app's notifications seem to be flaky. At least, they're sometimes slow. I think they can be delivered out of order and possibly are lossy, which aggravates the problem with not having something that just sets the state reliably. I assume it's pretty hopeless to have it reliably be in the right state if your phone was off when a notification was supposed to be delivered or Home Assistant was down on state transition or the like.

* Some things seem to be only checked at startup, so my house has race conditions after power outages. For example, if Home Assistant starts up more quickly than my Yamaha AV receiver (+ network switch + DHCP server), I can't control my home theater setup until I restart Home Assistant.

> ... for the off->on transition and another for the on->off. It'd be nice to set a rule that defines a level rather than an edge and have it internally do the transformation

The "solution" I found was to poll, and use "choose", and sometimes some helper switches for state, to do what is needed. But, I think at any reasonable level of complexity, you're better off using one of the three python components: the one built into Home Assistant, pyscript, or AppDaemon.

Home Assistant Python: https://www.home-assistant.io/integrations/python_script/ No imports.

pyscript: https://github.com/custom-components/pyscript Full python. Supports Jupyter. Straightforward.

AppDaemon: https://appdaemon.readthedocs.io/en/latest/HASS_TUTORIAL.htm... Full python. A little lower level. Allows the creation of dashboards.

Related, the Matter protocol is on its way. I'm waiting for these devices before I redo my house, or put much more effort into any of this: https://en.wikipedia.org/wiki/Matter_(standard)