8.9 KiB
KidTime
What this add-on does
KidTime is a parental control server for your home network. It stores the time
limits and usage of your children's Windows devices, tells the KidTime client on
each device when to warn, lock or log off, and serves the admin web page. The
add-on runs on the host network so the devices find it as kidtime.local
(mDNS) without any extra setup. The add-on takes its timezone from Home
Assistant, and the server runs as the container's main process, so a crash or a
failed port makes the add-on stop with a clear line in its log.
Ports
| Port | Used for |
|---|---|
| 8080 | Admin web page and its API (plain HTTP, "Open Web UI") |
| 8443 | Connection from the kids' devices (gRPC over TLS) |
| 8444 | Admin web page and API over HTTPS (used by the mobile app) |
The add-on uses the host network, so these ports are open on the Home Assistant machine itself. Do not run another KidTime server on the same network at the same time.
Backups contain secrets
Home Assistant backups of this add-on contain the TLS private key
(certs/server.key) and the JWT secret (secrets/jwt.secret), together with the
database. Anyone who holds a backup can impersonate your server to the kids'
devices and sign in as an admin session. Store backups privately and do not share
them. The add-on is stopped while a backup runs (cold backup), so the database is
copied consistently.
Moving your data
You can move the Windows server's data into this add-on by copying its folders. The same copy is also your backup and restore method. With the same certificate, key and database, the kids' devices reconnect without being set up again.
The certificate is the important part. Every provisioned device remembers the
server's certificate and rejects a server that shows a different one. If the
add-on's config folder is empty when it starts, it creates a brand-new server
with a new certificate, so the copy, and the hash comparison of server.pem,
server.key and jwt.secret, must be finished before the first start. Follow
the order below.
Never start the add-on to make its config folder appear. It would start with a new certificate on your network. Create the folder by hand instead (step 4).
Where the Windows data lives
On this machine the Windows server keeps its data in server\data of the
KidTime project (D:\dev\kids-time\server\data), as set in
server\.localtest\config.yaml. Inside it are four folders:
| Folder | Holds |
|---|---|
db |
the database (db.sqlite) |
certs |
the TLS certificate and key |
secrets |
the JWT secret |
client |
the client installers used for updates |
Ignore the loose db.sqlite, db.sqlite-shm and db.sqlite-wal files at the top
of server\data. They are leftovers the server does not use; the real database is
db\db.sqlite. Do not copy them.
Rehearse first
Before you touch the Green, run scripts\addon-rehearse.ps1 on the PC. It does
the same move on a throwaway copy, on an isolated network, and shows PASS or FAIL
for each check. All checks must pass.
Steps
-
Stop the Windows server cleanly (stop the service or process, do not kill it), so SQLite writes everything to disk. Also turn off its auto-start while the add-on is in use: both servers claim
kidtime.local, so they must never run together. If you seedb.sqlite-walordb.sqlite-shmfiles insidedb, copy those too. -
Make an untouched safety copy. Copy the whole
server\datafolder to a safe place, for exampleserver\data-safe. Never edit it afterwards. This is your rollback. -
Install the add-on, but do not start it. Turn auto-start and watchdog off for now.
-
Open the add-on's config folder from your PC through the Samba or SSH add-on. It is the folder ending in
_kidtimein theapp_configsshare (older versions:addon_configs). Home Assistant may only create this folder when the add-on first starts, so it may not exist yet. Do not start the add-on to find out. If the folder is missing, create it by hand, named<id>_kidtime. The add-on's slug is<id>_kidtime, where<id>is the first 8 hex characters of the SHA-1 of the repository URL, lowercased, exactly as you entered it in Home Assistant (this is how Supervisor derives it; the slug is also shown in the add-on's details page or its URL, for exampleabcd1234_kidtime). A repository added under/addonsinstead gets the sluglocal_kidtime. That Home Assistant accepts and uses a hand-made folder is to be confirmed on the Green (plan Task 6); this has not been verified. -
Copy the four folders in:
db,certs,secretsandclient, so that you end up withdb\db.sqlite,certs\server.pem,certs\server.key,secrets\jwt.secretandclient\...directly inside the add-on's config folder. Copy from the safety copy or fromserver\data, as long as the Windows server stays stopped. -
Compare the hashes before the first start. In PowerShell, from the Windows source folder and then from the add-on's config folder (a network path through Samba), run:
Get-FileHash -Algorithm SHA256 certs\server.pem, certs\server.key, secrets\jwt.secret | Select-Object Hash, PathThe three hashes must be identical in both places. If any hash differs, or any of the three files is missing, do not start the add-on. Copy again and compare again.
-
Start the add-on for the first time and open its log. You should see "Certificates loaded". If you see "Certificates not found, generating new ones", the copy went to the wrong place: stop the add-on at once and follow "If the add-on generated a new certificate" below, because the kids' devices would reject the new certificate.
-
Check that the admin page opens and a kid's device reconnects.
-
Turn auto-start (and watchdog) on for the add-on, now that the move works.
The stored installer paths inside the database are Windows paths. The server
finds installers by file name inside the client folder, so this works without
changing the database.
If the add-on generated a new certificate
Stop the add-on. In its config folder, delete everything inside all four folders
(db, certs, secrets and client), including any -wal and -shm files in
db, because the add-on has already created a new empty database. Then copy all
four folders in again from the safety copy, compare the hashes (step 6) and
start it.
Rolling back
Stop the add-on and start the Windows server on its untouched safety copy (point
its configuration at it, or put it back as server\data). Usage recorded on the
add-on in the meantime is lost, which is acceptable for a test.
Also turn Start on boot and the watchdog off for the add-on, or uninstall it
while keeping its data. Otherwise a reboot of the Green starts it again beside
the Windows server, and both claim kidtime.local.
The Green's database has diverged from the Windows one by then. On any later re-migration, replace it with the data you copy in; never reuse the Green's old database.
Do not change the repository URL
In Home Assistant, add the repository
https://git.nc.kreapptivo.de/KidTime/home-assistant-addon. It is
public, and so is the add-on's image
(git.nc.kreapptivo.de/kidtime/kidtime-addon-aarch64): neither needs a token,
an account or a registry login.
The repository URL you entered in Home Assistant, including any #branch, is
the add-on's identity. Supervisor's repository id is the first 8 hex characters
of the SHA-1 of the lowercased URL as entered, and the slug is <id>_kidtime.
Changing the URL, adding #branch or switching to the /addons fallback
(local_kidtime) gives a different add-on with an empty config folder, which
would generate a new certificate if started. So do not change the URL.
If you must change it, treat it as a fresh install: install the new entry
without starting it, copy the four folders from the old <old-id>_kidtime
folder, compare the hashes (step 6), start the new one, and only then remove the
old entry.
Uninstalling deletes the certificate
When you uninstall the add-on, Home Assistant asks whether to delete its data. If you let it, the certificate, key and database are gone, and a new certificate would be generated on the next start. Every device would then reject the server. Keep an up-to-date copy of the four folders before uninstalling. To recover, reinstall the add-on without starting it, copy the four folders back in from a backup (a copy of the folders or a Home Assistant backup), compare the hashes, and then start it. Home Assistant backups contain the TLS key and JWT secret, so store them privately.