Appearance
MQTT API
Device state and commands move over MQTT on the controller's own broker, mosquitto. Services on the Pi, the mobile app on the LAN, and remote clients through AWS all use the same topics.
Connecting
| From | Address |
|---|---|
| Services on the Pi | MQTT_BROKER_URL and MQTT_BROKER_PORT, port 1515 |
| The LAN over TCP | controlfreak.local:1515 |
| The LAN over WebSocket | ws://controlfreak.local:8080 |
| Remote | AWS IoT Core, every topic prefixed with devices/<thing_name>/ |
The local broker allows anonymous connections. Remote access is limited by the IoT custom authorizer to controllers the account is paired with, and only the topics the bridge carries reach the Pi. See Architecture for the bridge topic list.
bash
mosquitto_sub -h controlfreak.local -p 1515 -t 'controller/#' -vTopic conventions
| Pattern | Direction | Meaning |
|---|---|---|
controller/<device>/status | Published by the controller | What the hardware is doing now |
controller/<device>/state | Published by clients and services | A command to the device |
controller/<feature>/<action> | Published by clients | A command to a feature service |
<device> is the port's topic name, such as pump1, hv_relay3 or thermistor2. The mapping from port to topic lives in the topics table and is served by GET /topics.
Status messages
Every device status message has the same envelope.
json
{
"name": "hv_relay1",
"timestamp": "2025-07-24 14:26:49",
"status": "active",
"meta": {}
}Status messages are published with retain set, so a new subscriber gets the current state of every device at once. A publisher only sends a message when the content changes, apart from the timestamp. When a service reconnects to the broker it forgets what it last sent and publishes everything again, in case the broker lost its retained messages.
Devices
Controller
controller/status, published every 60 seconds by publisher-alive. It is a presence signal only.
json
{
"name": "controller",
"timestamp": "2025-07-24 14:26:49",
"status": "active",
"meta": { "cpuTemperature": 82.8 }
}High voltage relays
Eight relays, hv_relay1 to hv_relay8. Used for lights and other mains equipment.
Command on controller/hv_relay<n>/state:
json
{
"state": "active",
"color_choice": "Royal Blue",
"sync": false,
"light_speed": 5,
"light_brightness": 80
}Only state is required. light_speed is 1 to 9 and light_brightness is 20, 40, 60, 80 or 100.
Status meta: relay_state, last_known_state, last_known_mode, last_known_light_speed, last_known_light_brightness.
Low voltage relays
Four relays, lv_relay1 to lv_relay4. Used for heaters and heat pumps.
Command on controller/lv_relay<n>/state:
json
{ "state": "heat", "temperature": "80", "temperature_units": "F" }state is heat, cool or hold.
Status meta: relay_state, relay_mode, temperature, temperature_units, cooldown_active.
Pumps
Five RS485 pump ports, pump1 to pump5. Commands are handled by subscriber-rs485 and status is published by publisher-pump.
Command on controller/pump<n>/state:
json
{ "pump_speed": 60, "mode": "pool" }pump_speed is 10 to 100 in steps of 10, and mode is pool, spa or spillover.
Status meta: pump_speed, rpm, mode. mode can also be priming.
RS485 devices
Five ports, rs485_1 to rs485_5, for RS485 devices other than pumps, such as heat pumps and salt cells. Handled by subscriber-rs485 and publisher-rs485.
Command on controller/rs485_<n>/state:
json
{ "state": "active", "mode": "heat", "temperature": 82, "temperature_units": "F" }state, mode, temperature and temperature_units are common to every device. Any other key is passed to the device's driver, which ignores keys it does not know.
Valves
Eight valves, valve1 to valve8.
Command on controller/valve<n>/state:
json
{ "state": "openon" }state | Effect |
|---|---|
openon, active, pool | Start opening |
openoff | Stop opening |
closeon, inactive, spa | Start closing |
closeoff | Stop closing |
Status meta: open_state, close_state, opening_state, closing_state, other_valves_running.
Thermistors
Four sensors, thermistor1 to thermistor4, status only.
Status meta: mode, ohm, temperature_f, temperature_c, freeze_protection. mode is nominal or freeze.
Flow sensors
Two sensors, flow_sensor1 and flow_sensor2, status only.
Status meta: active_flow.
Pressure sensor
One sensor, status only, on controller/pressure/status.
Status meta: pressure.
The sender field
A command can carry "sender", naming the service that sent it. Subscribers use it to tell a user's command from one a feature sent, for example so a valve moved by a pump is not treated as a manual change. Clients leave it out.
Feature topics
| Topic | Payload | Handled by |
|---|---|---|
controller/themes/start | { "uuid": "<theme uuid>" } | controlfreak-themer. Stops any running theme first. |
controller/themes/stop | {} | controlfreak-themer |
controller/themes/status | Published by the themer | The running theme |
controller/freeze/pause | { "uuid": "<freeze parent uuid>" } | controlfreak-freeze-protection. Turns the children off. |
controller/freeze/resume | { "uuid": "<freeze parent uuid>" } | controlfreak-freeze-protection |
controller/tether | { "device_setting_uuid", "current_state", "current_mode" } | controlfreak-tether. Published by subscribers on the Pi, never by clients. |
controller/pairing/status | { "status": "pairing" or "idle", "expires_at" } | Published by controlfreak-display |
controller/update/status | { "name": "updater", "status", "timestamp" } | Published by the updater, retained |
controller/update/restore | {} | The updater, while it is still running after a failed update |
The mobile app follows updates through GET /health, not controller/update/status. See Database API.
REST over MQTT
Remote clients reach the REST API through api-bridge.
| Topic | Direction | Payload |
|---|---|---|
controller/api/request | To the Pi | requestId, method, path, params, headers, body, and an optional timeoutMs |
controller/api/response/<requestId> | From the Pi | status, headers, body |
api-bridge waits 15 seconds for the API unless timeoutMs says otherwise, then answers 504. A response over 120 KB is replaced with a 413.
Adding a device topic
- Add the port and topic rows in the seed data in
database-api/app/main.py, and in a migration so existing controllers get them. - Publish status with
handle_device_publishfromcfp_shared.mqtt, which handles the envelope, retain and deduplication. - If the topic has to reach remote clients, make sure it matches a line in
aws-installer/scripts/03-mosquitto-bridge.sh.controller/<device>/statusandcontroller/<device>/statealready do.