A house as a system
Heating, ventilation, energy, display and internet times in a private home: fully local, with logic on the devices and reproducible operations. This manageable system shows how I design all layers together.
Starting point
A house is used for decades. Off-the-shelf smart home systems like to move decisions into a cloud. If the internet fails, the vendor ends support or changes its business model, the house stops working.
I wanted a system that works without a cloud and without a vendor account, that every resident can operate, and that I can still understand and change in a year. On a small scale, that is the same task as a business system in a company: it has to run day to day, even when something fails, and it has to stay manageable.
The system in four layers
The system consists of four layers. Each has a clear task and an equally clear list of things it must not do.
| Layer | Building blocks | Task | Must not |
|---|---|---|---|
| Field | Shelly scripts, sensors, electricity meters, ESP32 display | Switch and measure immediately, fail safely | Wait for central services or the internet |
| Transport | Mosquitto on the Raspberry Pi | Distribute messages, hold the latest values | Interpret business logic |
| Application | Six Go services on the Raspberry Pi | Automate, present, translate | Take over the tasks of other services |
| Observation | Prometheus on the home server | Collect time series | Control anything |
The point of this separation is simple: a failure in an upper layer must not paralyse the lower ones. If the dashboard crashes, the heating keeps running. If the broker is gone, the ventilation button still works. If Prometheus fails, only the history is missing.
The path of a command
The interplay is easiest to see in an example: someone sets a heating circuit to “Auto” in the dashboard.
Three things are typical here and recur throughout the system:
- The console does not decide the effect. It only publishes a setpoint. Whether the valve opens is decided by the Shelly, depending on temperature, local switch and season.
- The reply to the browser confirms acceptance, not the effect. The browser only sees the actual state with the next state value.
- The setpoint stays stored in the broker. When the Shelly restarts, it gets it back immediately.
Five decisions that shape the rest
In the developer handbook, every important decision is recorded with context, alternatives and consequences. Five of them shape the system the most.
E-01 Fully local operation
No basic function may require a cloud account, an external service or the internet. The weather service is an optional, read-only data source.Rejected: A ready-made system with cloud connection would be quicker to set up, but makes the house depend on other people’s operating decisions. Home Assistant would be local, but brings a large, generic platform whose behaviour changes with updates and whose configuration is hard to version.
Price: Every function is built, tested and operated by me.
E-02 MQTT as the only bus
All components talk to each other at runtime only through the broker. Each service can restart on its own without disturbing the others.Rejected: Direct HTTP interfaces between the services or a shared database. Both would have coupled the services: if the called service fails, the caller fails too.
Price: There are no synchronous replies. The effect of a command shows up as a new state.
E-06 Exactly one producer per state
Every state value belongs to exactly one producer. The origin of a value can be read from its path and the configuration, and the access rights at the broker enforce it technically.Rejected: “Last writer wins” would be easier to configure, but makes errors invisible.
Price: Every exception has to be declared explicitly.
E-08 Control on the device, derivation in the centre
Protection, operation and control logic runs on the devices. The centre only supplies setpoints and derived values. If the centre fails, buttons, humidity automation, heating override and valve protection keep working.Rejected: Keeping all logic central would be easier to change and test. But then every button press would depend on broker, Wi-Fi and Raspberry Pi.
Price: The logic lives in two languages (Go and Shelly JavaScript), and changes to the scripts have to be rolled out to the devices.
E-35 Architecture rules as a test
Rules that exist only in a document get broken sooner or later, usually out of convenience with one import. So they are an ordinary test that runs with every check: services do not import each other, the platform knows no service, every program uses the same command-line foundation.Rejected: External tools would be more powerful, but add another dependency with its own configuration language.
Price: I have to write new rules myself as Go code.
Operations
Operations are not an afterthought here, they are part of the design.
- One procedure for everything. An Ansible playbook rolls out broker, services and the scripts on all field devices. Tags allow rolling out only a part. Every rollout is repeatable and shows what changed.
- The Pi as an appliance. A minimal Buildroot Linux without a package manager. The Go programs are built statically and need nothing but the kernel.
- Strict configuration. Configuration consists of strictly validated files. Each service can validate it before starting, and the rollout validates before every restart.
- Restart without manual work. The broker holds all setpoints. After a restart every device finds its last setpoint again, and stale measurements are not treated as current.
- Observe without intervening. Prometheus collects time series but cannot control anything. The dashboard shows the time of receipt for every measurement and marks stale values.
- Diagnosis from the outside in. The handbook contains decision trees from the symptom (“heating does not respond”) to the check.
- Prepared for AI tools. The repository contains architecture rules, check commands and a handbook that explains decisions. Rule violations show up immediately as test failures. This way AI can propose code without the architecture being bent unnoticed.
What I take from this for businesses
A house is not a company, but the design questions are the same. The following table is a translation, not a client result.
| At home | In a company |
|---|---|
| Logic on the devices, the centre only supplies setpoints | A business process keeps running when the central system is down |
| MQTT as the only bus | One integration layer instead of many point-to-point connections |
| Exactly one producer per state | Clear data ownership: one leading system per master data item |
| Inventory and configuration in the repository | Configuration as code, changes are traceable |
| One Ansible playbook for everything | Reproducible rollout, even after a total failure |
| Prometheus separated from control | Monitoring without the ability to intervene, history separated from operations |
| Architecture rules as a test | Quality rules that check automatically instead of sitting in documents |