<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Infrastructure of my own - Alexey Krylov</title><description>Homelab, self-hosting, networks, privacy without the clouds.</description><link>https://alexey-krylov.dev</link><language>en</language><item><title>My own panel on a mobile router: one Go binary and 128 MB of memory</title><link>https://alexey-krylov.dev/blog/own-panel-on-a-mobile-router</link><guid isPermaLink="true">https://alexey-krylov.dev/blog/own-panel-on-a-mobile-router</guid><description>What I managed to do with a pocket LTE router, the Huawei E5885. A dependency-free panel in Go, ad blocking, a connection map, operator SMS and counters that lied.</description><pubDate>Sun, 11 Oct 2026 00:00:00 GMT</pubDate><content:encoded>A pocket LTE router, the Huawei E5885, travels with me: in a hotel, an airport or a cafe it shares internet from a SIM card or from someone else&apos;s Wi-Fi. This summer, including a vacation in Turkey, I built my own control panel for it. The result is a mobile router for a developer: I can see who is connected and how much they downloaded, how much is left of the data plan and of the battery, ads are blocked on the router itself, and client connections are drawn on a map, like in Little Snitch.

The code was written by agents under my direction. What to build, what to leave stock and what to give up was my call, and those decisions are recorded in the project documentation.

![Panel overview: system, network, interfaces, clients and storage](/images/panel-na-mobilnom-routere/obzor-en.webp)

## What is inside the box

The firmware on the router is the original one, with root access, not OpenWrt. The CPU is a dual-core ARMv7, but Linux sees one core: the second is taken by the modem. The frequency is no higher than 666 MHz. Out of 256 MB of memory, Linux gets 128.

Writing for it is inconvenient:

- the system partitions are mounted read-only, and the only partition for my own files that is mounted right after boot has about 10 MB free out of 61.5;
- packages do not install: `opkg install` fails, and the package archive has to be unpacked by hand;
- there is no compiler on the router, and no cron either;
- busybox is built in a way that does not resolve names: `ping` by name answers `bad address`.

So the panel is built on a laptop for `GOARCH=arm` and goes to the router as a single file.

## One binary with no dependencies

The panel is built into a single static Go binary, and there is nothing in it besides the standard library. The pages are embedded with `go:embed`, there are no external scripts or fonts, and it opens the same way without internet. Inside are 56 Go files and 38 test files, 17,845 lines without tests. The binary weighs about 8.8 MB.

Port 80 on the router is taken by the stock Huawei panel. I do not disable it: Wi-Fi and modem settings are changed through its API. My panel listens on a separate port, and the settings have a switch that swaps them: mine answers on 80, the stock one moves to 3000. If my process stops, the redirect rules are removed, and port 80 serves the stock panel again.

In the first version those rules had no destination address, and my panel received all transit traffic of the clients to port 80, not only requests to the router itself.

A watchdog looks after the process, a shell loop that runs every 15 seconds. It brings the panel up if it has crashed, and removes the DNS interception if its resolver has stopped listening, otherwise the clients would be left without name resolution.

## The page before login

No password is needed to find out whether the router works. Before login there is a status page: whether there is internet, the operator and signal level, speed, what is left of the data plan and the battery, how many clients are connected.

![Status page before login: internet is up, remaining traffic and battery, number of clients](/images/panel-na-mobilnom-routere/status-en.webp)

The set of fields on it is hardcoded: no client list, no serial numbers, no versions. There is a test for this: one extra field in the response, and it fails. The state snapshot is built on request and kept for 8 seconds, so frequent page refreshes do not load the router.

## Ad blocking and memory

Ads are blocked at the DNS level: a domain from a list gets a &quot;does not exist&quot; answer, and the log shows which list blocked it.

The first version kept 164 thousand domains in a `map`, the process took up to 42 MB, and the system killed it every 35 seconds. A sorted slice of strings with binary search cured that.

Then the lists grew to five and the domains to 450 thousand. In a slice of strings that is 450 thousand objects, which the garbage collector walked on every cycle. The heap has a ceiling of 22 MB, and the collector ran without a break, taking 40% of the CPU at full idle. What helped was laying the domains end to end in one byte block with a numeric index and searching directly in it. The collector has nothing to walk there: the CPU is busy at 2-3%, and the process takes 25 MB instead of 29.6.

The CPU also went into launching external commands. At 666 MHz every busybox call from a Go process is expensive, and when there were fewer polls, the load dropped from 6.5 to 2.4%.

## The connection map

The &quot;Map&quot; tab shows where the clients go: outgoing connections are drawn on a world map and refreshed every three seconds. Traffic is split into 15 categories.

The map needs a GeoIP database, and it weighs 65 MB with 128 MB of memory for everything. The database sits on a microSD card, and my own parser of the format reads it through `mmap`, so it is never loaded into memory in full. The map costs the process about 5 MB.

## SMS and USSD

The operator sends service SMS, and gives the remaining data plan in response to a USSD request. The stock panel can do both, and I moved this into mine. It reads, sends and deletes messages and sends a notification about a new SMS to the phone. After a USSD request it closes the dialog whatever the outcome, otherwise the modem would stay stuck in it. Before sending an SMS the panel asks for confirmation: in roaming it costs money.

![The &quot;Messages&quot; tab: a USSD balance request, incoming operator SMS, the send form](/images/panel-na-mobilnom-routere/soobshcheniya-en.webp)

The stock panel is designed for a single user. The session is bound to the client address and lasts five minutes without activity, and the panel answers frequent logins with an error. Login to it goes through SCRAM, and Huawei has the key and the message in HMAC swapped relative to RFC 5802: an implementation that follows the standard is rejected with the correct password.

## Someone else&apos;s Wi-Fi with a portal

In a hotel the router works as a repeater: it connects to the hotel network and shares it further. Such a network first requires opening a login page, and the clients behind the router do not see that, they just have no internet.

For this case the panel has a &quot;portal&quot; mode. Every two minutes it makes a probe request and tells four cases apart: there is internet, the network requires login, there is no uplink, DNS is spoofed. If the network requires login, the panel shows a link to the page and temporarily sends the clients&apos; DNS queries to the resolver of that network, because only it knows the name of the login page.

![The &quot;Network login&quot; card: the network requires login, a link to the portal page and the probe results](/images/panel-na-mobilnom-routere/vhod-v-set-en.webp)

The mode is built and covered with tests, but I have not tried it in a real hotel.

The repeater itself would not connect to any network at first: the panel process lacked the paths to the system utilities, and the stock service was managing the same interface at the same time. It started working through the stock profile API. There it turned out that the `Order` field sets not the priority but the slot number, while the priority is determined by the order of the blocks in the request.

Switching between the mobile network and Wi-Fi drops the router&apos;s own access point for 10-30 seconds: the firmware rebuilds the radio interfaces. In that time the laptop moves to another known network and does not come back. I now test such things over a cable.

## Counters that lied

Client traffic was first counted by iptables rules. Under load the counter showed 27 KB while 26.6 MB went through the router: it has a hardware accelerator, and the packets bypass netfilter. Now the bytes come from the Wi-Fi driver.

The driver counter is not monotonic, and the first version credited a phone with 125 GB uploaded overnight. Counting by radio frames also overstates the volume: a client downloaded 131.5 MB, and the counter grew by 158.8.

The load at idle stayed around 20. Twenty modem threads constantly hang waiting for I/O and end up in the load average, so the panel subtracts those twenty. And the uptime in the firmware log showed 9583 hours over 125 power-ons: the field turned out to be in minutes.

## A test bench without the router

Editing the layout right on the router is expensive: an ARM build, an upload and a restart for one line of CSS. So the panel has a bench mode. It runs on a laptop and serves API responses from files. A synthetic set lives in the repository, and a snapshot of the live router with real addresses does not get into it. The screenshots in this article were taken on the bench.

The bench helped in another way too. There is one router, and git worktrees do not isolate it. One agent session started from a stale copy of the code, and each of its uploads wiped out the map tab on the router, which another session was building at the same time.

In two months, from July to the end of August, the project collected 91 commits. A pocket router turned into a router that shows what is going on inside it: who is connected, where they go and how much of the data plan is left.</content:encoded><category>lab</category><category>linux</category><category>monitoring</category><category>networking</category><category>self-hosting</category></item><item><title>Two Home Assistants with nothing between them</title><link>https://alexey-krylov.dev/blog/two-home-assistants-with-nothing-between</link><guid isPermaLink="true">https://alexey-krylov.dev/blog/two-home-assistants-with-nothing-between</guid><description>The apartment and the country house each got their own Home Assistant with no bridge between them. How one vendor account is split into two homes, why the country house stood without devices for twenty-five days, and what layered diagnostics does about it.</description><pubDate>Sun, 11 Oct 2026 00:00:00 GMT</pubDate><content:encoded>I have smart devices in the apartment and in the country house, and the vendor accounts are shared, one for both homes. Each home has its own Home Assistant, and there is nothing between them: no MQTT bridge, no entity mirror, no shared database.

I set them up together with Claude. By then both homes were already described in a [registry](/blog/home-fleet-registry), the same way infrastructure is described in code. I built the smart home the way I am used to building systems: it is a direct consequence of my experience in IT, only with an agent as a pair.

## Why not one for two homes

The country house runs on its own power setup: the grid, an inverter, a generator. It needs to be controlled when something has gone wrong, and on such days the link to the apartment often goes down too. If the Home Assistant in the apartment controlled everything, the country house could not be controlled at the worst moment.

So the country house one runs on the country house server and must work without a link to the apartment, and the apartment one knows nothing about the country house. Two things connect them, and both work without either of them: a link tile to the panel of the neighboring home and an agent that has access to both.

As a bonus, I did not have to touch the firewall. The devices of each home talk to their own Home Assistant in their own network, and nothing has to be opened between the homes.

Both run in containers, each in the smart device segment of its home and under its own address. Devices find each other by broadcast, and broadcast does not cross segments. The configuration is done by scripts through the API, and the apartment has 33 scripts. After them the apartment has 429 entities and 24 automations, the country house 224 and 20.

## One account for two homes

Stock integrations pull in every device of the account and do not ask which home it is in. If nothing is done, one lamp will be toggled by two Home Assistants, and the question &quot;who turned off the light&quot; will have no answer.

Each vendor needed its own solution. From the Yandex smart home, the apartment one takes only devices whose name starts with the Russian word for &quot;apartment&quot;. Tuya has no filter, so each one disables the other home&apos;s devices on its own side. We worked out which device belongs where not by names: Tuya devices announce themselves in their network every few seconds, and it was enough to listen to both networks.

## Twenty-five days of a country house without devices

On October 3 the diagnostics showed 93 unavailable entities in the country house. They had been unavailable since September 8, since a routine restart of Home Assistant. The network, the broker, the containers and the vendor cloud were working, and there was not a single error in the log. There was nothing to notice it with earlier: I had no alerting for such a case.

In the eWeLink app devices are sorted into &quot;homes&quot;, and the integration has an option for which home to take. An empty option means &quot;the current home of the account&quot;. That time the current one was the apartment. The country house Home Assistant received four apartment devices and did not receive its own twenty-five.

The fix took a minute: I pinned the home in the options explicitly, and the devices came back. It is now pinned in both homes, and switching in the app does not affect anything.

## The router that stopped being polled

In the apartment, presence is tracked by the router integration. On September 3 the router failed to answer once, and right after that refused authorization once with the correct password. Home Assistant opened a reauthentication request and stopped polling the router altogether. The integration entry was listed as loaded, the entities were unavailable, and one line remained in the log. Nobody saw this for three weeks, for the same reason as in the country house. Then the same thing happened again after a single timeout, for six more days.

I did not find out why the router refused: it keeps its log in memory. Reloading the integration entry helps, and an automation now does that. Ten minutes without data from the router, and it reloads the entry; if that fails, it retries in half an hour.

The leak sensor is not cured by a reload. After a network failure it began accepting a connection and closing it without an answer, and the only thing that helps is cutting its power. The integration was writing about a thousand errors a week, which is 99% of the log, and I disabled it. The sensor shuts off the water on a leak by itself, without Home Assistant; only the voice and the notification do not work.

## Layered diagnostics

These failures have one thing in common: they are silent. There is no error, the entry is &quot;loaded&quot;, and the devices are gone. A &quot;Home Assistant responds&quot; check does not see that.

So in both homes you can ask &quot;what is going on with the house&quot;. The check goes layer by layer, from the house down to the hardware: the country house has nine of them, from the electrical system and heating to the server and Home Assistant itself, the apartment has eight. A layer answers with one of four words: normal, warning, failure or &quot;no data&quot;. &quot;No data&quot; counts the same as a failure: there is no source, so the layer is not checked.

After the router story the diagnostics got a line about integrations whose entities all disappeared at once. The count is by physical devices, not by entities.

The answer comes by voice, one line per layer, and the full report with numbers goes to a notification. It was the diagnostics that found the country house without devices.

## What Home Assistant does by itself

An event is caught by whoever sees it. The loss of power is detected by the [power monitor](/blog/power-monitor-for-a-country-house), and Home Assistant only voices what arrived [over the event bus](/blog/home-event-bus). It keeps its own thresholds only for appliances that nobody but it knows about.

In the country house that is load shedding. When the house switches to the inverter, Home Assistant turns off the water heater and both stages of the boiler: the battery cannot carry them. When the current at the mains input approaches the limit, it acts in steps:

| Input current | What happens |
|---|---|
| 40 A | announces the current and the margin before cutoff |
| 45 A | turns off the water heater |
| 48 A | turns off the heating cables |
| below 35 A for ten minutes | turns back on what was turned off |

The first threshold is a voice one: a person has a chance to turn off the kettle themselves. The input protection does not touch the boilers at any current: in winter they are the heating of the house.

In the apartment Home Assistant talks more than it acts. It talks about stuffy and dry air and switches nothing by itself. It does not interfere with the water shutoff at all.

## The agent asks for permission

The agent kept its access to both Home Assistants. At home I have my own DevOps engineer who is on call around the clock: an agent on a Mac mini.

In the country house there are rules on the mains input relay, the inverter line, the boilers, the water heater, the heating cables and the boiler room ventilation. A call goes into a queue and waits until I press &quot;approve&quot; or &quot;reject&quot;; if I stay silent for 120 seconds, the call is not executed. There are no rules on reads, otherwise I would have to approve even a look at the boiler state.

The tool that edits the rules themselves is disabled for the agent: it must not change the restrictions that are placed on itself.

Two things are still ahead. The first: for the agent to go through both homes once a week by itself, look for anomalies and propose solutions, instead of waiting for the question &quot;what is going on with the house&quot;. The second: the main thing, for the sake of which everything was split in two, I have not tested yet, namely how the country house works with the link to the apartment cut.</content:encoded><category>lab</category><category>architecture</category><category>automation</category><category>diagnostics</category><category>self-hosting</category></item><item><title>A home event bus: why have one when notifications already exist</title><link>https://alexey-krylov.dev/blog/home-event-bus</link><guid isPermaLink="true">https://alexey-krylov.dev/blog/home-event-bus</guid><description>One stream of events for the phone, voice and the bot. Why an event describes a fact, not a text, and how the broker died for twelve days unnoticed.</description><pubDate>Tue, 22 Sep 2026 00:00:00 GMT</pubDate><content:encoded>The power monitor at the country house, which I have already written about, sends notifications to the phone, and for a long time that was enough.

Then I wanted more: for the house to announce a power outage by voice, for the family bot to write about it in the shared chat, and for the home automation to be able to react to it. Every new recipient required a separate integration with every source, and so the house got a shared event bus.

## An event describes a fact

A source publishes an event once, and recipients subscribe to what they need. The transport is an ordinary MQTT broker.

More important than the broker was the decision about what counts as an event. An event describes a fact: what happened, to what, and how urgent it is. The wording for a human is produced by the recipient.

Simplified, an event looks like this:

```json
{&quot;key&quot;: &quot;msg_on_inverter&quot;, &quot;priority&quot;: &quot;high&quot;}
```

I did not arrive at this form right away. At first the router sent Russian text, and it arrived as spaces: the router loses Cyrillic. Now the router sends only machine fields, and the recipient assembles the text. In substance this turned out to be more correct than the original version.

## Who publishes and who listens

Two publish right now: the power monitor and the router. The monitor has 25 kinds of events and a separate topic with the current state, which the broker retains for new subscribers. The router sends events about the state of the communication links.

The home automation listens, and it has a single point of voice output. The priority is set by the source, the automation only routes:

| Priority | What happens |
|---|---|
| urgent | by voice, loudly, twice, even during quiet hours |
| high | by voice once, silent at night |
| the rest | not spoken by voice |

The decision &quot;whether to wake the house&quot; is made by the one who knows the substance of the event, not by the one who speaks it.

## Why the old notifications stayed

It would seem that once there is a broker, a separate service for phone notifications is not needed. But these channels fail in different ways.

In a long power outage the server with the broker will shut down when the battery is drained, while the monitor runs on the router with its own UPS and keeps running. The notification channel has a queue of undelivered messages, the bus does not. On the other hand, the broker is local and survives a break in the link between the home and the country house, and the notification service does not. The channels complement each other, and I did not remove either one.

For the same reason the detection itself stayed in the monitor. It was tempting to move it into the home automation, but that gets updated, restarted and dies together with the house.

## My own client and a place for the broker

The power monitor has a &quot;zero external dependencies&quot; principle, so a ready-made library did not fit. One-way publishing is done by a small module on the standard library.

There turned out to be exactly one place for the broker in the network. Both the monitor from the trusted segment and the automation from the untrusted one have to reach it, and the router does not let traffic through in the opposite direction.

## Twelve days of silence

At the beginning of September the owner of the broker&apos;s files changed. The password file became unreadable for the broker, but the broker kept working on the already open file until it was restarted.

After the restart it went into a crash loop, and two days later it stopped completely. This was found twelve days later: the router&apos;s log was packed with messages about an unreachable broker. Nobody was watching the broker, and its absence did not show itself in any way.

Since then the broker runs as the user who owns its files, and monitoring got a check of the broker itself. I never found out who changed the owner of the files: in time it coincided with work on quotas on the server.

## Downsides

- the broker became one more component that has to be watched;
- there is no queue of undelivered messages. A recipient that was switched off will miss the event, only the current state will remain;
- events are not encrypted, the bus is designed for a home network;
- the list of event kinds lives in the source&apos;s code. A new recipient has to look into it.

While there is one recipient, the phone, ordinary notifications are enough. The bus became necessary when voice and the bot were added to the phone.</content:encoded><category>lab</category><category>architecture</category><category>events</category><category>monitoring</category><category>self-hosting</category></item><item><title>A registry of the home fleet: what goes down together with this service</title><link>https://alexey-krylov.dev/blog/home-fleet-registry</link><guid isPermaLink="true">https://alexey-krylov.dev/blog/home-fleet-registry</guid><description>121 documentation files described every node, but the dependency graph was not assembled anywhere. How a machine-readable registry appeared, and the three checks that keep it from lying.</description><pubDate>Sun, 30 Aug 2026 00:00:00 GMT</pubDate><content:encoded>By the end of the summer I had accumulated 121 documentation files for the home and the country house. Every node was described in detail: what runs on it, what pitfalls there were, how to fix it.

But this documentation answered simple questions only by rereading:

- what goes down together with this service;
- which ports are already taken on this node;
- where this tool is deployed and under what name.

That is how the registry appeared, which answers such questions right away.

## Structure apart from prose

The registry takes the structure of the setup out of the prose: sites, nodes, services, ports, names, dependencies, hardware. History and repair procedures stay in the prose.

I took the model from the data center world, where equipment inventory has long been a solved problem:

```text
registry/
  sites/&lt;site&gt;/nodes/         nodes: we run things on them and manage them ourselves
  sites/&lt;site&gt;/devices/       devices: on the network, but not managed by us
  sites/&lt;site&gt;/power/         utility hardware without a network
  networks.yaml               segments and names
```

Only nodes have services. A TV or a vacuum cleaner has, instead of services, what it is controlled by, and a distribution board or a generator has what it consists of.

The main rule: one fact is written in one place. Structure in the registry, prose in the documentation.

## What is generated from the registry

From the registry I generate a &quot;what lives where&quot; summary, a dependency diagram with a &quot;what goes down together&quot; table, and a single page with search across the whole fleet.

The page opens with a double click and works without a network: it is needed most often when something is already down. Typing a port, a name or a piece of a title is enough. A click on a service shows what it depends on and what will fall together with it.

## Three checks

A registry filled in by hand drifts away from reality over time. So three checks hold it in place:

| Check | What is compared with what | When |
|---|---|---|
| first | the registry and the configuration repositories | automatically, before every commit |
| second | the registry and what is actually running on the nodes | by hand, periodically |
| third | the service tables in the node documentation | generated from the registry |

The first check does not let me commit a new service or name that is missing from the registry, so the registry is updated in the same change, not &quot;later&quot;.

The second one is safe by design. It reaches the nodes through a proxy on which all modifying requests are forbidden: it is physically unable to start or stop anything.

## What the first run found

The very first run of the second check found five containers on the home server that were not in any documentation file, this blog among them.

This is what it was all done for: the documentation and the live nodes drift apart silently. A container is started, it works, and nobody remembers it until the first incident.

## Where the registry is incomplete

The routers did not make it into the live check: containers on them are visible over a different protocol, and for now I compare the list by hand. Some of the services that were found are still without a description. They are in the table, but what they are and what they are for is not written anywhere.

Names turned up that lead nowhere: there is an entry in the documentation, but no such name on the network, and the other way round. Household devices had to be entered in groups based on the router&apos;s records, and for some of them I do not know the exact models.

## What the registry costs

- it is one more repository that has to be maintained;
- the first check gets in the way. Quickly fixing something and committing no longer works, the registry comes first;
- the second check is run by hand, and so it is easy to forget about;
- the registry describes structure, not state. It does not know whether a service is alive, monitoring is there for that.

Keeping a registry makes sense when there are many nodes and they are on different sites: then it quickly answers the question &quot;what goes down together with this&quot;. For a single server one file is enough.</content:encoded><category>lab</category><category>architecture</category><category>automation</category><category>documentation</category><category>self-hosting</category></item><item><title>A power monitor for a country house: grid, inverter, generator</title><link>https://alexey-krylov.dev/blog/power-monitor-for-a-country-house</link><guid isPermaLink="true">https://alexey-krylov.dev/blog/power-monitor-for-a-country-house</guid><description>How to find out that the house has lost power, what it is running on right now and how long the battery will last, when half of the sensors go dark together with the house.</description><pubDate>Sat, 22 Aug 2026 00:00:00 GMT</pubDate><content:encoded>The power at my country house goes out from time to time. The house then switches to the inverter, and when the battery runs down, I have to start the generator. I needed to know that the power is out, what the house is running on right now and how much longer the battery will hold. A power monitor now keeps track of that.

![Dashboard overview: grid state, main feed load, yearly totals and a map of outages by day](/images/monitor-sveta-na-dache/obzor-god-en.webp)

## A relay on the main feed instead of a sensor

The catch is that the sensor that should report a grid failure is itself powered from that grid. That became the signal: there is a smart relay in the distribution board, powered from the incoming line, and the monitor simply checks whether it responds. If the relay does not respond, there is no power on the main feed. The monitor itself runs on the router, which has its own UPS, so it survives the outage and sees it.

At first I could not read measurements from the relay: its local protocol is encrypted with a key from the vendor&apos;s cloud. Outage tracking did not need that anyway, reachability was enough.

## Three sources without a single sensor on the generator

Nothing monitors my generator, but I still managed to detect when it is running. What helped was an access point that is powered from a wall socket, not from the UPS.

| Grid | Inverter | Access point | Source |
|---|---|---|---|
| up | does not matter | does not matter | normal |
| down | responds | does not matter | on inverter |
| down | silent | responds | on generator |
| down | silent | silent | blackout |

A notification goes out on every transition, and when the grid comes back a summary arrives: how long the house stayed on each source.

## What the monitor has grown

The monitor caught its first real outage on the day of the rollout, July 24, 2026. After that it gradually grew features. An outage log appeared with a timeline of phases: when the grid went down, when we moved to the generator, when everything came back. The monitor accumulates generator engine hours and reminds me about the oil change when fewer than 30 hours are left before it, and for every outage it estimates the fuel burned.

![Outage card: time on the inverter, on the generator and without power, fuel consumption, a power chart and a timeline of sources](/images/monitor-sveta-na-dache/kartochka-otklyucheniya-en.webp)

To see real volts, amps and kilowatt-hours, I had to reflash the inverter relay and put a meter with open firmware on the main feed. The forecast of how long the battery will last and the main feed protection both rest on these measurements.

## How long the battery will last

Battery capacity cannot be described by a single number: by my measurements it delivers 2.63 kWh at a 600 W load and only 2.27 kWh at 1150 W. So the forecast is calculated for the current load. The monitor takes all &quot;from full charge to cutoff&quot; sessions, builds a dependency from them and gets roughly this picture:

- 500 W: 5.3 hours;
- 1 kW: 2.3 hours;
- 3.5 kW: 38 minutes.

![Dashboard block with the forecast: how long the battery will last at different loads](/images/monitor-sveta-na-dache/prognoz-batarei-en.webp)

It is also a measurement of battery health: degradation shows up in the trend of these sessions.

## Main feed protection

The house hangs on a 50 A main breaker. If it trips, that means a request to the grid company and a house without power until the crew arrives. So my meter on the main feed breaks the circuit earlier, at 53 A, and then restoring power becomes a button in the dashboard.

![Main feed load in the dashboard: present current, share of the breaker rating and the cutoff threshold](/images/monitor-sveta-na-dache/nagruzka-vvoda-en.webp)

The threshold is set by current, not by power: the breaker trips on current, while the voltage on the main feed drifts from 202 to 243 V, and a threshold in watts is off by ten percent. It is set above the breaker rating on purpose. The thermal release holds 56.5 A for an hour and longer, so the breaker will not notice 53 A, and the pump&apos;s inrush currents will not cut the main feed.

The cutoff is done by the meter, not by the monitor. It survives a crash of the container, the router and Wi-Fi. There is no automatic restore: with the load still connected it would produce a cycle of switching on and off. A cutoff must not end up in the outage log. Its numbers are needed for reconciliation with the supplier, so cutoffs are recorded separately.

## The monitor&apos;s mistakes and one mistake by the agent

Devices on the country house Wi-Fi silently disappear for minutes while still powered. A failure is now accepted only after three failed probes one minute apart, while a return is recorded quickly: a false &quot;the power is back&quot; is harmless.

Because of the same Wi-Fi, an outage could start straight from the generator. The relay is silent, the inverter is silent, the access point is alive: formally that is &quot;on generator&quot;. In reality the generator is started by hand a couple of hours later, and the radio took down two devices at once. Such a start now waits 10 minutes.

The first version had a check based on the server&apos;s network cable, and it lied: the inverter powers the whole house together with the switch, so the cable always showed &quot;power is present&quot;. I had to cut it out.

Capacity was calculated in two places, and one of the functions did not discard junk measurements: a one-minute session of 0.02 kWh got into the calculation, and &quot;0 minutes left&quot; went out in a notification with a live battery. The voltage sag threshold was hardcoded as 198 V, and the monitor missed real sags down to 202 V.

After a trial trip of the cutoff the meter disappeared from the network. The agent concluded that the meter is powered downstream of its own relay and that the cutoff is pointless, cancelled the task and wrote that into the documentation. I objected: since the meter could be switched back on, that theory is wrong. The check took one command: the meter&apos;s uptime had not reset, power had not been lost, and it had disappeared because of Wi-Fi. The cutoff was enabled the same day.

## What the monitor does not see

There is no perfect detection by reachability: the log has a &quot;false alarm&quot; button, and it is needed. If the meter goes silent because of Wi-Fi, the monitor will see the same thing as with a grid failure. There is no measuring device on the generator phase, and the voltage in the house during that time is unknown.

A monitor like this is for a house with backup power, where it matters to know the source and the remaining charge, not only the fact of an outage. How its events spread across the house, to the phone, to voice and to the family bot, I will describe in the next article.</content:encoded><category>lab</category><category>diagnostics</category><category>monitoring</category><category>power</category><category>self-hosting</category></item><item><title>Where a network anomaly detector should live</title><link>https://alexey-krylov.dev/blog/where-the-anomaly-detector-belongs</link><guid isPermaLink="true">https://alexey-krylov.dev/blog/where-the-anomaly-detector-belongs</guid><description>A script on the router or logic in a flow collector that is already running - how the plan shrank by half and what a run over the history showed.</description><pubDate>Sat, 22 Aug 2026 00:00:00 GMT</pubDate><content:encoded>After the story with the set-top box that held 5051 connections, I needed alerts about anomalous device behaviour in my home network. The first plan for the detector turned out to be twice as complex as it needed to be.

## A plan built around a RouterOS script

The task in the tracker carried a requirement: the detector is written as a RouterOS script. The argument sounded convincing: the detector should run inside the thing being watched, not inside the watcher.

The agent accepted this requirement and built a plan around it:

- a new firewall rule;
- a script of about 300 lines that parses conntrack on its own;
- state between runs kept in the comments of address-list entries;
- a day of dry run to calibrate the thresholds.

The plan would have worked, but it redid something I already had.

## A flow collector instead of a script

By that time both sites had a flow collector running. It keeps a permanent session with the router over the binary API, refreshes the &quot;who talks to whom&quot; map every 10 seconds, and stores the history in SQLite.

I asked the agent what would happen if we gave this to the collector. Parsing conntrack with a script would have been a second, worse copy of the same work, and it would have loaded the router exactly at the moment of an incident. I gave the detectors to the collector.

## What moving it to the collector gave me

The plan shrank by about half, but the savings were not the main result:

- the thresholds are picked from history. The collector had 48 hours of flows, and I ran the same detector code over them in `-backtest` mode. I could see what would have fired and on whom before turning anything on;
- the alert text now has the country, the ASN and the domain of the target. A script on the router would not have had this data at all;
- no changes to the production firewall were needed at all. Rollout is `docker compose`, rollback is the previous image;
- one of the planned detectors turned out to be pointless. On the history, the &quot;wide scan&quot; could not tell scanning from an ordinary P2P client, and the threshold from the task could not be reproduced.

I consider the last point the most useful one. On the router this would have surfaced only after a week of false alerts. Now, if the history is already there, a new detector is first run over it, and the report gets numbers: over 48 hours it would have fired N times, and here is on whom.

## The price of the move

- the detector sees the network with a delay of up to 10 seconds;
- the collector became a critical component, before that its failure cost only an empty map;
- 48 hours of history do not cover weekly cycles, so the thresholds will have to be rechecked.

If the collector goes down, the network is left unattended. But covering that is cheaper than moving the logic to the router: an Uptime Kuma monitor watches the collectors themselves. If a collector goes silent, a separate alert arrives.

## What I now ask before adding a new watchdog

1. Who already collects the data I need?
2. What will the watched system pay for doing the computation itself, especially at the moment of an incident?
3. How do I cover the failure of the watcher?

This time the answers were these. The flow collector was already gathering the data. Doing the computation itself would have cost the router load exactly at the moment of an incident. And a separate monitor watches the collector.</content:encoded><category>lab</category><category>diagnostics</category><category>mikrotik</category><category>monitoring</category><category>networking</category></item><item><title>Segmenting a home network on MikroTik without VLANs</title><link>https://alexey-krylov.dev/blog/service-moves-to-the-viewer</link><guid isPermaLink="true">https://alexey-krylov.dev/blog/service-moves-to-the-viewer</guid><description>A second subnet on the same bridge, trusted devices by list, and services with their own address in the segment of the people who use them.</description><pubDate>Fri, 21 Aug 2026 00:00:00 GMT</pubDate><content:encoded>In this post I want to describe how I split my home network into trusted and untrusted devices without setting up VLANs. The need itself came up after an incident at the country house: one TV box was holding 5051 connections, and it became clear that any device in the subnet counted as &quot;one of ours&quot; on my network.

The TV, the smart speaker, the robot vacuum and the cat&apos;s water fountain had the same access to the home server and to the router&apos;s admin interface as my laptop.

VLANs were the first option I considered, and I rejected it because it brings switch reconfiguration and new SSIDs with it. A second subnet requires neither.

## The idea

Isolation is done at L3: a second subnet on the same bridge. The switch, the access points and the SSIDs are left untouched, only the addresses change.

![Two segments on one router bridge](/images/service-moves-to-the-viewer/segments.svg)

- `10.0.1.0/24` - trusted: computers, phones, the server, the printer. Static leases only, there is no pool;
- `10.0.2.0/24` - untrusted: TVs, speakers, lamps, family members&apos; devices, guests. The DHCP pool lives here as well.

The addresses here and below are placeholders. An unfamiliar device ends up in the untrusted segment on its own, because free addresses exist only there. Becoming trusted requires an explicit static lease.

There is still only one DHCP server: RouterOS does not allow two of them on the same interface. The segment is determined by the lease address.

## What came out of it

The trusted list is filled by DHCP itself. A lease has an `address-lists` parameter, and the address is added to the list at the moment it is handed out:

```text
/ip dhcp-server lease set [find address=10.0.1.50] address-lists=trusted-devices
```

Then come five filter rules, all restricted to `in-interface=bridge`:

- a limit on concurrent connections for an untrusted device, and a trace in a separate list for an hour;
- the actual drop of connections above the limit;
- an allow rule for a short list of addresses in the trusted subnet;
- a drop of everything else from the untrusted segment into the protected networks;
- a drop of the router&apos;s own admin ports.

The key one looks like this:

```text
add chain=forward in-interface=bridge src-address-list=!trusted-devices \
    dst-address-list=protected-nets connection-state=new action=drop
```

In addition, there is a mandatory setting without which the router itself will tell an untrusted client to reach its neighbour on the bridge directly, past the filter:

```text
/ip settings set send-redirects=no
```

Two points about the rules themselves are worth noting.

The threshold of 500 was not found on the first try. At the country house it was initially set to 200, and within the first 20 minutes a phone and a laptop belonging to family members tripped it. Even so, 500 is still ten times lower than the number that started all this.

The `connection-state=new` condition on the drop rule is mandatory. Without it the rule cuts the reply packets of connections that a trusted host initiated: monitoring checks, a stream from the server to the TV.

## Services for untrusted devices

One catch remained: the TV needs the media server, and the media server lives on the server in the trusted subnet.

I considered opening a port on the server to untrusted devices a bad solution: behind port 80 there is a reverse proxy with all the internal sites, and separation by the `Host` header does not count as protection.

I decided to move the services themselves. A container gets its own address in `10.0.2.0/24`: a Docker network in macvlan mode on top of the server&apos;s network card, with the address issued by the router&apos;s DHCP for the MAC pinned to the container.

The viewer and the service end up in the same subnet, `forward` takes no part in their communication at all, and the `trusted-allowed-for-untrusted` list still contains a single printer.

This is how the media server, the photo archive, music, the wiki and several more services moved. Later this blog moved there too.

## Problems along the way

Almost all of them looked the same: the rule is correct and there is no traffic.

- the server did not get onto the trusted list. Its address is configured in the OS itself, it does not request one over DHCP, and its lease on the router had been sitting in `waiting` since 2024. I had to add the only static entry in the list. The check is simple: if a device is present in `/ip arp print` while its lease is `waiting`, the address is set on the device;
- the container-level `mac_address` is ignored in Docker 29, and only the `networks.&lt;network&gt;.mac_address` form works. It also works only in a Compose file without a `version:` line;
- BBR. While the service lived in `network_mode: host`, it inherited `tcp_congestion_control=bbr` from the host. In its own netns the default is `cubic`. It was BBR that once raised a single video stream between home and the country house from 10 to 76 Mbit/s, so the `sysctls` line in the stack is mandatory;
- port publishing. Docker attaches a container&apos;s networks in alphabetical order and puts the port mapping on the first of them. If `lan` comes first, the port on the host silently does not open, although `docker ps` shows it as published. The network&apos;s `priority` parameter does not change this order;
- `set address=` on an active lease erases its `dhcp-option-set`. I caught it by eye in `print detail`, and now I set the option set on the next line;
- device discovery. I wrote in the documentation that mDNS would not travel between segments, and I was wrong: 17 devices answered a query, five of them from the neighbouring subnet, because L2 is shared. At the same time, the app of one of the speakers discards a foreign subnet by itself, and the speaker had to be returned to the trusted devices.

## Downsides

The downsides of this approach are the following:

- there is no isolation within a single L2, neighbours in a subnet talk through the switch, past the router;
- `trusted-allowed-for-untrusted` opens a whole address rather than a port;
- the migration window is up to 30 minutes, until the devices renew their leases.

The right use case for this solution is protection against household appliances with someone else&apos;s firmware that scan the network by the usual rules. It will not protect against a person who is deliberately aiming at the network.

I rolled it out in stages: each stage is a separate `.rsc` file imported as a single transaction, with its own rollback file. I did the acceptance from the devices themselves rather than from the rules, because half of the problems in the list above are not visible in the rules.

I hope someone finds this useful.</content:encoded><category>lab</category><category>docker</category><category>mikrotik</category><category>networking</category><category>self-hosting</category></item></channel></rss>