MQTT Integration¶
SQMeter publishes its readings, the safety verdict and alerts to any MQTT broker, and can announce itself to Home Assistant automatically.
Enabling MQTT¶
In Settings → Network → MQTT, turn on Publish to a broker and set the broker, credentials, Base topic (default sqmeter) and how often readings are sent. The same settings over the API:
{
"mqtt": {
"enabled": true,
"broker": "192.168.1.10",
"port": 1883,
"username": "mqttuser",
"password": "mqttpass",
"topic": "sqmeter",
"publishIntervalMs": 60000,
"publish": { "sky": true, "environment": true, "clouds": true, "gps": true, "rain": true, "wind": true, "battery": true, "safety": true, "diagnostics": false },
"homeAssistant": { "enabled": true, "discoveryPrefix": "homeassistant" }
}
}
The base topic may use letters, numbers, _ and -, with / between levels.
Telemetry, not an interlock
MQTT is a plaintext LAN integration. Use it for telemetry and automation; keep physical safety interlocks independent.
Topics¶
| Topic | Retained | Payload | When |
|---|---|---|---|
<base>/availability |
Yes | online / offline (last will) |
On connect / disconnect |
<base>/state |
Yes | The readings document (below) | Every publish interval, and on reconnect |
<base>/safe |
Yes | 1 safe, 0 unsafe |
On every change, refreshed every minute |
<base>/safety |
Yes | The safety object - same as GET /api/safety, with the holds in effect and dewSuspected (Rain needs cloud) |
With <base>/safe |
<base>/alerts |
No | One message per alert (with Settings → Alerts → MQTT on): {"event","events"?,"title","message","level","device","timestamp"} |
Each alert |
<base>/alerts/armed |
Yes | 1 sending alerts, 0 paused |
On change and reconnect |
<base>/alerts/armed/set |
- | Subscribed: 1/0, on/off, true/false resume or pause alerts |
Command |
<base>/safety/hold/set |
- | Subscribed: {"id","reason","source"?,"expiresMin"?} sets a safety hold, {"id","clear":true} clears it |
Command |
<base>/diagnostics |
No | Light-sensor sample counts, RG-15 serial counters (rain sensor on) and the fuel gauge's registers and power policy (with a gauge) - same as /api/status → diagnostics |
Every publish interval, when enabled |
Booleans are 1/0; availability uses Home Assistant's online/offline.
flowchart LR
accTitle: MQTT topic map
accDescr: SQMeter listens on alerts/armed/set and safety/hold/set and publishes state, safe, safety, availability, alerts, alerts/armed and diagnostics under its base topic, plus Home Assistant discovery under the discovery prefix.
SET["alerts/armed/set<br/>1/0, on/off, true/false"] -->|command| D["SQMeter"]
HOLD["safety/hold/set<br/>JSON: set or clear a hold"] -->|command| D
D --> STATE["state<br/>retained, every publish interval<br/>and on reconnect"]
D --> SAFE["safe: 1 or 0<br/>retained, on change and every minute"]
D --> SAFETY["safety: verdict, reasons and holds<br/>retained, with safe"]
D --> AVAIL["availability: online or offline<br/>retained, last will"]
D --> ALERTS["alerts<br/>not retained, one message per alert"]
D --> ARMED["alerts/armed: 1 sending, 0 paused<br/>retained, on change and reconnect"]
D --> DIAG["diagnostics<br/>not retained, every interval, off by default"]
D --> DISC["homeassistant/.../config<br/>retained, when discovery is on;<br/>the Alerts switch only while alerts can go out"]
sqmeter.Diagram in words
Under the base topic (default sqmeter), SQMeter publishes:
state- the readings document, retained, every publish interval and on reconnect;safe(1/0) andsafety(the verdict with its reasons and safety holds), retained, on every change and refreshed every minute;availability-online, orofflineas the last will, retained;alerts- one message per alert, not retained (with the MQTT alert channel on);alerts/armed-1sending /0paused, retained, on change and on reconnect;diagnostics- not retained, every publish interval, only when switched on.
It listens on alerts/armed/set (1/0, on/off, true/false) to resume or pause alerts, and on safety/hold/set (JSON) to set or clear a safety hold.
With Home Assistant discovery on, it also publishes retained config topics under the discovery prefix (default homeassistant), and clears them when discovery is switched off or moved. The Alerts switch is only announced while alerts can go out (Send alerts on, or paired phones that can ring), and is removed otherwise.
Safety holds¶
<base>/safety/hold/set sets or clears a safety hold - the same as POST /api/safety/hold, for automations that already talk MQTT. The payload is JSON:
- Set (or update):
{"id": "smoke", "reason": "Smoke: PM2.5 85 µg/m³", "source": "Home Assistant", "expiresMin": 240}-sourcedefaults toMQTT,expiresMin(1-10080) is optional. - Clear:
{"id": "smoke", "clear": true}- that hold only; the other rules still decide.
Don't retain these messages: a retained set would set the hold again after every reconnect, even after it was cleared. A bad payload, or clearing a hold that doesn't exist, changes nothing and is only logged. The holds in effect are in <base>/safety → holds. MQTT has no device password: anyone who can publish to your broker can set holds, so use the broker's own access control.
mosquitto_pub -h <broker-ip> -t sqmeter/safety/hold/set -m '{"id":"smoke","reason":"Smoke: PM2.5 high"}'
mosquitto_pub -h <broker-ip> -t sqmeter/safety/hold/set -m '{"id":"smoke","clear":true}'
Choosing what's published¶
Settings → Network → MQTT → Publish switches each part on or off:
| Switch | Controls |
|---|---|
| Sky quality and light | light, sky and skySensors in <base>/state |
| Temperature, humidity, pressure | environment |
| IR and cloud cover | infrared and clouds |
| GPS, Rain, Wind | gps, rain, wind (only when that hardware is enabled) |
| Battery | battery (only does anything with a fuel gauge, D-49) |
| Safe / unsafe | <base>/safe and <base>/safety |
| Diagnostics | <base>/diagnostics (off by default) |
Readings (<base>/state)¶
The same document as GET /api/sensors and /ws/sensors, minus the safety object (it has its own topics) and any groups switched off:
{
"timestamp": 1791401772,
"timeValid": true,
"dataAgeMs": 412,
"dataStale": false,
"light": { "status": "ok", "ageMs": 400, "lux": 0.0003, "visible": 307, "infrared": 47, "full": 357, "gain": "MAX", "gainFactor": 9876, "integrationMs": 600, "saturated": false, "nightMode": true },
"sky": { "status": "ok", "source": "sqm", "sqm": 21.48, "rawSqm": 21.41, "nelm": 6.2, "bortle": 2, "description": "Typical truly dark site", "calibrated": false, "averagingWindowSeconds": 90 },
"skySensors": {
"sqm": { "status": "ok", "ageMs": 400, "sqm": 21.48, "rawSqm": 21.41, "nelm": 6.2, "bortle": 2, "description": "Typical truly dark site", "calibrated": false, "averagingWindowSeconds": 90, "lux": 0.000301, "gain": "MAX", "integrationMs": 600, "saturated": false, "nightMode": true },
"sqml": { "status": "ok", "ageMs": 380, "sqm": 21.73, "...": "the same fields" },
"deltaSqm": 0.25
},
"environment": { "status": "ok", "ageMs": 3100, "temperature": 12.3, "humidity": 64.7, "pressure": 1013.4, "dewpoint": 6.1 },
"infrared": { "status": "ok", "ageMs": 3100, "skyTemperature": -24.7, "ambientTemperature": 12.4 },
"clouds": { "status": "ok", "coverPercent": 3, "condition": "clear", "description": "Clear", "temperatureDelta": -37.1, "correctedDelta": -33.0, "humidity": 64.7, "humiditySource": "measured" },
"gps": { "status": "ok", "ageMs": 750, "fix": true, "satellites": 9, "latitude": 51.5074, "longitude": -0.1278, "altitude": 42.0, "hdop": 1.1 },
"rain": { "status": "ok", "ageMs": 40, "raining": false, "rainingNow": false, "intensity": 0.0, "eventAccumulation": 0.4, "sensorEventAccumulation": 0.4, "totalAccumulation": 12.6, "lensFault": false, "emitterSaturated": false },
"wind": { "status": "ok", "ageMs": 900, "speed": 3.3, "gust": 6.8, "direction": 246, "vaneFault": false },
"battery": { "present": true, "status": "ok", "ageMs": 1200, "estimating": false, "percent": 82.4, "voltage": 3.912, "ratePercentPerHour": -6.2, "state": "discharging", "usbPower": false, "fault": null, "timeToEmptyMinutes": 797, "timeToFullMinutes": null, "powerSaving": false }
}
timestampis Unix seconds;timeValidisfalse(andtimestamp0) until the clock is set.statusisok,missing(not detected or not responding),errororstale. A group whose status isn'tokcarries onlystatusandageMs(noageMswhenmissing- it has never answered) - never zeros that look like readings.gps,rain,windare only present when that hardware is enabled.lightandskyare the authoritative sky sensor;sky.source(sqmorsqml) says which.skySensorshas each sky sensor that is switched on under its own name (sqm, the wide sensor;sqml, the narrow SQM-L), with the samestatusrules, anddeltaSqm(SQM-L − SQM) while both areok. It is left out when neither is on. See Two sky sensors.- Units: °C, %, hPa, lux, mag/arcsec², m/s, degrees (0 = north), mm and mm/h (an RG-15 set to inches is converted).
wind.directionis left out when it's calm or there's no vane. rain.rainingis held for the rain clear delay after the last drop;rainingNowis instantaneous; while held,clearInSecondssays how long is left.eventAccumulationis cleared by the clear delay;sensorEventAccumulationis the RG-15's own event total.battery(spec 032) is{"present": false}without a fuel gauge (or with Monitor battery off). With one:percent(null whileestimating),voltage(V),ratePercentPerHour(positive when charging, null for the first minute),state(discharging,charging,charged,fault,no-battery),usbPower(null without the charger pins),fault(temperature),timeToEmptyMinutes/timeToFullMinutes(null when not known, at most 5940) andpowerSaving. See Battery.clouds.humiditySourceisassumedwhen there's no humidity sensor (53% is used).
The same in every language
Topics and payloads never change with the UI language, including Home Assistant discovery. Numbers are JSON numbers with . as the decimal point and no thousands separators (12.1, never "12,1"); units, topic names, field names and values such as status and condition are never translated. <base>/safety reasons and <base>/alerts titles and messages are English (or your own alert wording) for people to read: automate on <base>/safe, reasonFlags and the alert event.
Home Assistant¶
Turn on Settings → Network → MQTT → Home Assistant → MQTT discovery. SQMeter then appears as a device with:
- Sensors: sky quality, limiting magnitude, Bortle class, illuminance, temperature, humidity, pressure, dew point, sky temperature, cloud cover, rain intensity, wind speed, gust and direction - for the groups you publish
- Per sky sensor (spec 030): SQM (wide) and SQM-L (narrow) for each sky sensor that is switched on, and SQM-L − SQM while both are; Sky quality stays the authoritative reading
- Battery (spec 032, with a fuel gauge and the Battery group published): Battery (%), Battery voltage, Charging state (an enum: discharging, charging, charged, fault, no-battery) and Battery time to empty (minutes)
- Binary sensors: Raining (moisture), Observatory (safety: on = unsafe) and Dew suspected (problem: on while Rain needs cloud treats the rain sensor's rain as dew under a clear sky; read from
<base>/safety→dewSuspected, so it needs the rain group and the safety topic published). Dew suspected is never unsafe: Observatory stays the verdict - Switch: Alerts - on while sending, off while paused (see When to send)
Each entity is unavailable while the device is offline or its sensor isn't ok (SQM-L − SQM: while either isn't). Switching a group or a sky sensor off removes its entities. The discovery prefix defaults to homeassistant.
Without discovery, read <base>/state with a value_template:
mqtt:
sensor:
- name: "Sky quality"
state_topic: "sqmeter/state"
value_template: "{{ value_json.sky.sqm }}"
unit_of_measurement: "mag/arcsec²"
See Alerts for the alert events.