Appearance
Alerts
An alert is something the controller noticed that a person should know about, a device that stopped answering, a fault flag on a unit, schedules that could not be loaded. Alerts are stored by controlfreak-api, published over MQTT the moment they are stored, and shown in the app behind the bell on the home screen.
service ──publish_alert()──> POST /alerts ──> alerts table
└──> controller/alerts/status ──> app refetchesThe controller is the only store. AWS sees the MQTT message on its way to a remote app and keeps nothing.
Raising one
Every Python service raises an alert the same way, through cfp_shared.alerts:
python
from cfp_shared.alerts import publish_alert
publish_alert(
"rs485.heat_pump.not_responding", # code
"critical", # info, warning or critical
"Heat Pump is not responding", # title
"Port 2 failed 5 cycles in a row.", # description
device_uuid=device["uuid"], # optional
)- It never raises. A producer must keep running whatever happens to its alert. Failures are logged and
Falseis returned. - It always logs an
ALERT [severity] code device: titleline, so an alert that never reaches the API is still in the service's log. - It dedupes. The same code for the same device is sent at most once every 15 minutes (
DEDUPE_SECONDS). The window only starts once the API has stored the alert, so one the API missed is sent again next time. - Producers raise on a change of state, not on every cycle. Dedupe is a backstop for something flapping, not the main defence.
- The trace is automatic. Called inside an
exceptblock, the current exception's traceback goes along astrace. Passtrace=to override it. sourcecomes from theSERVICE_NAMEenv var, else the script's name.
Title is clipped to 80 characters, description to 500, and the trace keeps its last 4096, which is where the exception is.
An older database-api without the route answers 404. publish_alert logs that and moves on, so a service can ship before the API does.
Codes in use
Codes are dotted, area.subject.condition. The app does not branch on them, they are for logs and support.
| Code | Severity | Raised by | When |
|---|---|---|---|
scheduler.fetch_failed | warning | scheduler | Schedules or tethers failed to load 3 times in a row |
scheduler.no_topic | warning | scheduler | A schedule points at a device with no command topic, once per schedule |
rs485.<type>.not_responding | critical | subscriber-rs485 | A port failed 5 cycles in a row |
rs485.<type>.<alarm> | critical | subscriber-rs485 | A telemetry key starting alarm_ turns true |
rs485.<type>.no_flow | critical | subscriber-rs485 | A pump was stopped after no flow for its monitoring window |
relay.no_flow | critical | subscriber-hv-relay | A relay pump was switched off after no flow for its monitoring window |
flow.not_configured | warning | subscriber-rs485, subscriber-hv-relay | Flow monitoring is on with no usable sensor, once until it is fixed |
freeze.engaged | info | freeze-protection | A sensor read below its threshold and freeze protection started |
freeze.sensor_unreadable | critical | freeze-protection | A freeze sensor reads nothing or below -50F, once until it reads again |
updater.failed | warning | docker-updater | An update run failed and was reset |
updater.restore_failed | critical | docker-updater | A restore to the previous version failed |
<type> is the device type in snake case, heat_pump, salt_cell, pump.
RS485 alarms
Any driver can raise an alert by reporting an alarm_<name> telemetry key as true. The subscriber raises one alert on each false to true edge.
| Driver | Keys |
|---|---|
| Moov ClearSalt | alarm_high_temp, alarm_cell_fault, alarm_no_flow, alarm_low_salt |
| Fairland heat pump | alarm_fault_<code>, one per active fault |
The Fairland sheet lists fault flags at discrete inputs 48 to 91 by code only, E0 to ED, P0 to PA and F1 to Fb, with no meaning for any of them. The driver reports only the active ones, so a clear unit adds no keys. A unit that refuses the fault read keeps the rest of its telemetry.
REST
All under controlfreak-api, so local and remote clients reach them the same way.
| Method | Path | What it does |
|---|---|---|
POST | /alerts | Store an alert. 201, or 200 if that id is already stored. |
GET | /alerts | Newest first, without trace |
GET | /alerts/{id} | One alert with its trace. 404 if it is gone. |
POST | /alerts/{id}/acknowledge | Mark it read. Acknowledging twice keeps the first time. |
POST | /alerts/acknowledge | Mark every unread alert read, returns { "acknowledged": n } |
GET /alerts takes:
| Query | Default | |
|---|---|---|
limit | 50 | 1 to 50 |
before | ISO timestamp, for the next page | |
unacknowledged | false | Only unread alerts. The app always sends true. |
The list leaves trace out because fifty traces would pass the api-bridge response cap on the remote path.
The alert
json
{
"id": "1b9e4c7a-2f3d-4c8e-9a51-6d0f2b7e8c13",
"code": "rs485.heat_pump.not_responding",
"source": "subscriber_rs485",
"severity": "critical",
"title": "Heat Pump is not responding",
"description": "Port 2 failed 5 cycles in a row. Check the unit's power and its RS485 wiring.",
"trace": "Traceback (most recent call last): ...",
"device_uuid": "fdc76eaf-a000-4269-a203-fde91d1616ea",
"timestamp": "2026-10-29T14:02:11.402000+00:00",
"acknowledged_at": null
}id is made by the producer, so a retried POST is stored once. Timestamps are stored in UTC and always sent with their offset.
MQTT
Each stored alert is published to controller/alerts/status, QoS 1, not retained. The payload is the alert without trace. The topic matches the bridge's controller/+/status rule, so it reaches devices/{thing_name}/controller/alerts/status in AWS with no bridge change.
The app treats the message only as a signal to refetch GET /alerts. A missed message costs nothing, the list is fetched again on the next open.
Retention
Pruned on every POST /alerts, in this order:
| Cap | Default | Setting |
|---|---|---|
| Acknowledged alerts older than | 7 days | alert_ack_max_age_days |
| Any alert older than | 30 days | alert_max_age_days |
| Rows kept | 500 | alert_max_rows, oldest acknowledged go first |
All three live on controller_settings, are set through POST /controller-config, and must be at least 1.
The alerts migration switches SQLite to auto_vacuum = INCREMENTAL and the API runs PRAGMA incremental_vacuum after each prune, so pruned rows give their space back to the SD card. On an existing controller the switch costs one full VACUUM during the migration.
Alerts never clear themselves. A device that recovers leaves its alert in place until someone dismisses it.
In the app
- The bell in the home header opens the alerts list. A dot on it shows the worst unread severity.
- Dismissing removes the row at once and puts it back if the controller refuses.
- The detail screen shows the trace under Details for support in dev builds only.
- A controller without the route reads as no alerts, as does demo mode.