Contents
- What we bought and what each part does
- How the data flows
- Can you use another operating system
- Example files and your own settings
- Step 1 Connect the coordinator
- Step 2 Install Docker and the Python environments
- Step 3 Set up Mosquitto
- Step 4 Start Zigbee2MQTT
- Step 5 Pair the first sensor
- Step 6 Create the database and API
- Step 7 Connect the MQTT receiver
- Step 8 Confirm that the report is in the database
- Step 9 Check the SensorThrust feed
- Step 10 Give the feed an HTTPS address
- Step 11 Show readings on your phone
- Add the remaining sensors
- Optional extra Grafana for your own charts
- Services and logs
- When something does not work
- Back up before you need to
- What you can change later
- Sources and versions
Your own sensor readings in SensorThrust
How we built our temperature and humidity monitoring system
We wanted small battery-powered sensors in our rooms, readings stored in our own database, and temperatures visible on a phone and in widgets. We built the collection system with Zigbee sensors and software running on an ordinary Linux computer. This guide follows the same chain, starting with one sensor.
This is one working approach. SensorThrust does not require these particular sensors, Debian, MQTT or PostgreSQL. The app only needs a compatible HTTPS feed and its read key. You can collect, store and serve the data using other tools.
Our server ran 64-bit Debian 12 Bookworm. The installation commands below are written for that system. Use them for a new installation prepared for this purpose. Do not replace the settings of an existing home automation system with these examples.
The milestones are:
- See your first sensor's temperature in Zigbee2MQTT.
- See that sensor's report in MQTT.
- Store the report in PostgreSQL.
- Access the feed with a read key.
- See your own readings in SensorThrust and a widget.
What we bought and what each part does
| Part | Our choice | Purpose |
|---|---|---|
| Indoor sensor | SONOFF SNZB-02P | Measures temperature and relative humidity; powered by a CR2477 battery |
| Zigbee coordinator | SMLIGHT SLZB-06P7U | Creates the sensors' Zigbee network and forwards radio traffic to the server |
| Coordinator network connection | Ethernet cable | Connects the coordinator to the local network |
| Coordinator power | A USB power supply or PoE supply suitable for the model | Choose the cable and power supply according to your device's instructions |
| Collection computer | An existing Debian computer | Runs the collection software and database continuously |
| Viewing device | iPhone and SensorThrust | Displays readings in the app and widgets |
Start with an installed operating system, a working local network and an administrator account with sudo access. Installing the operating system on an empty disk is outside these steps.
Begin with one sensor. Adding more is easier once the whole chain works.
The SNZB-02P is an indoor sensor. The manufacturer specifies an operating range of −10 to +60 °C and 5–95% humidity, without condensation. This does not make it suitable for rain, condensation or severe Finnish winter temperatures. Choose a model designed for outdoor use if you want outdoor readings. SONOFF user manual
This setup does not need a separate SONOFF bridge: SMLIGHT acts as the Zigbee coordinator and Zigbee2MQTT interprets the sensor's messages. Zigbee2MQTT support for this sensor
Your server does not have to match our hardware. An older mini PC or a Raspberry Pi running 64-bit Linux is a possible starting point. Choose a power supply and storage suited to continuous use. A laptop does not collect readings while it is asleep.
How the data flows
SONOFF sensor
│ Zigbee radio
▼
SMLIGHT coordinator
│ Ethernet, TCP 6638
▼
Zigbee2MQTT
│ JSON message on MQTT topic zigbee2mqtt/Office
▼
Mosquitto
│ MQTT subscription
▼
mqtt_to_api.py
│ local delivery queue, then HTTP POST /temperatures
▼
FastAPI → PostgreSQL
│ GET /v1/feed, separate read key
▼
HTTPS connection → SensorThrust → widget
Zigbee is the sensors' radio network. MQTT carries messages between programs. They are different things. In this setup, the sensor has neither a Wi-Fi connection nor its own HTTP API.
Mosquitto is the MQTT broker. It passes messages from Zigbee2MQTT to subscribers. PostgreSQL stores the historical readings. The Python program's small SQLite file is a delivery queue for API outages, not a second main readings database.
The API separates the collector from the database: the collector receives a write key, but not the database password. The phone receives a different key that only permits reading.
Can you use another operating system
| Option | How it relates to this guide |
|---|---|
| Debian | Our actual environment and the main path for the commands in this guide |
| Ubuntu or another Linux distribution | The same system is possible; adapt package installation, Docker's package source and database settings to the distribution |
| Raspberry Pi OS 64-bit | The same architecture is possible; choose 64-bit packages and a container image suitable for the hardware |
| Windows | Zigbee2MQTT has official Windows installation instructions. Mosquitto, Python and PostgreSQL are also available for Windows. The Linux commands in this guide do not run unchanged on Windows |
| Windows with a Linux virtual machine | You can install Debian in a virtual machine and follow the Linux path. The VM must reach the coordinator on the local network and start and keep running with its host |
| Home Assistant or an existing system | You can use your existing collection system and turn its data into a SensorThrust v1 feed. You do not need to rebuild the separate collection chain below |
Running natively on Windows requires different instructions for environment variables, directories and automatic startup. systemctl is not a Windows command. Likewise, this guide's Docker network_mode: host and 127.0.0.1 addresses cannot simply be copied into Docker Desktop's separate network environment. We did not use Windows or the other alternatives as test platforms. Zigbee2MQTT installation options · Windows instructions
Example files and your own settings
The guide includes sensor-diy.zip. It contains the API, MQTT receiver, configuration templates, database schema and service definitions. Extract it in your home directory on the server so that you have ~/sensor-diy/files.
You can copy the archive from your own computer to the server like this. Replace omauser and 192.168.1.50 with your own username and server address. Run this transfer command on your own computer, not on the server.
scp sensor-diy.zip omauser@192.168.1.50:~/
On the server:
sudo apt update
sudo apt install unzip nano openssh-server python3 python3-venv mosquitto mosquitto-clients postgresql curl ca-certificates
cd ~
unzip sensor-diy.zip
cd ~/sensor-diy/files
Read the commands before running them. In this guide, sudo means running a command with administrator privileges. Run all following Linux commands on the server unless stated otherwise. When an instruction opens sudoedit, save the changes and close the editor before continuing.
The templates contain none of our passwords, network keys or sensor identifiers. Record these details from your own setup:
- the server's local network address and your username;
- the coordinator's local network address;
- each sensor's IEEE address and MQTT topic;
- later, your own HTTPS address and read key.
In the examples, 192.168.1.50 is the server and 192.168.1.60 is the coordinator. These are not automatically the correct addresses for your network. Replace api.omadomain.example with your actual domain name.
Our receiver originally lived in the user's home directory and the API in its own /opt directory. The shared example places both programs under /opt and gives each its own service account. The API listens only on the server's local address. The data flow, database table and SensorThrust feed contract match our implementation.
Step 1 Connect the coordinator
Connect the SLZB-06P7U to Ethernet and power it according to its instructions. Find its address in your router's device list and open the device's management page in a browser.
Select Zigbee coordinator and Ethernet mode. USB does not need to carry the Zigbee connection in this setup. Check the connection address and adapter on the device's Zigbee2MQTT settings page: our CC2652P7 chip used zstack and TCP port 6638.
The coordinator firmware already installed on our device worked. We did not update it just because an update was available. Use coordinator firmware intended for your model; Zigbee Router and Matter-over-Thread serve different purposes. SMLIGHT Ethernet instructions
Keep the coordinator's address stable, for example with a DHCP reservation if that fits your network administration. If its address changes, update the Zigbee2MQTT configuration too.
Success: the management page opens, Ethernet is connected and the radio is in coordinator mode. Socket connected: No is expected at this stage: Zigbee2MQTT has not started yet.
Step 2 Install Docker and the Python environments
We run Zigbee2MQTT in Docker. Mosquitto, PostgreSQL and the Python programs run as ordinary services on the same Linux computer.
Install Docker Engine and Compose using Docker's official instructions for your distribution. Below are the repository installation commands for a new Debian setup. If the computer already has Docker or Podman, first check the official instructions about existing installations. Do not remove working services for this guide. Docker's Debian instructions
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
sudo tee /etc/apt/sources.list.d/docker.sources > /dev/null <<EOF_DOCKER
Types: deb
URIs: https://download.docker.com/linux/debian
Suites: $(. /etc/os-release && echo "$VERSION_CODENAME")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF_DOCKER
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl enable --now docker
sudo docker run --rm hello-world
sudo docker compose version
Hello from Docker! confirms that a container can start. It does not yet test the sensor.
Create service accounts and separate Python environments. These accounts are not PostgreSQL users or MQTT credentials, even though the names are similar.
sudo useradd --system --user-group --home-dir /opt/sensor-api --shell /usr/sbin/nologin sensor-api
sudo useradd --system --user-group --home-dir /opt/sensor-mqtt --shell /usr/sbin/nologin sensor-mqtt
sudo install -d -m 0755 /opt/sensor-api /opt/sensor-mqtt
sudo python3 -m venv /opt/sensor-api/.venv
sudo python3 -m venv /opt/sensor-mqtt/.venv
sudo /opt/sensor-api/.venv/bin/pip install -r requirements-api.txt
sudo /opt/sensor-mqtt/.venv/bin/pip install -r requirements-mqtt.txt
Installed packages stay in these environments, separate from the system Python. Do not run a general sudo pip install into the system Python.
Step 3 Set up Mosquitto
Create the MQTT user zigbee2mqtt. Choose a long password that you will also give to the configuration preparation program shortly. The command asks for the password without displaying it. The branch below preserves other users in an existing password file.
if sudo test -e /etc/mosquitto/passwd; then
sudo mosquitto_passwd /etc/mosquitto/passwd zigbee2mqtt
else
sudo mosquitto_passwd -c /etc/mosquitto/passwd zigbee2mqtt
fi
sudo chown root:mosquitto /etc/mosquitto/passwd
sudo chmod 0640 /etc/mosquitto/passwd
sudo install -m 0644 mosquitto.conf /etc/mosquitto/conf.d/sensors.conf
sudo systemctl enable --now mosquitto
sudo systemctl restart mosquitto
sudo systemctl status mosquitto --no-pager
sudo ss -ltnp 'sport = :1883'
Success: Mosquitto is active (running) and port 1883 listens on 127.0.0.1. You do not need to open the MQTT port to the local network or the internet. Mosquitto authentication instructions
Next, prepare your settings:
python3 prepare.py
The program asks for the coordinator's IP address and the same MQTT password you just set in Mosquitto. Its prompts are in Finnish: enter the coordinator address first, then enter and confirm the MQTT password. It creates a database password, separate read and write keys, and the Zigbee2MQTT configuration file in the private directory. It does not print keys or start services. It refuses to overwrite an existing private directory.
Do not share the generated private directory. The original example archive and your own live settings are different things.
Step 4 Start Zigbee2MQTT
Choose a Zigbee channel before the first start. Our two Hue networks used channels 11 and 25, so we chose channel 20 for the sensors. It is not automatically the best channel for every network: consider your Wi-Fi and other Zigbee networks. Set it before pairing; changing it later may require devices to rejoin.
The template uses channel 20. If needed, change advanced.channel in private/configuration.yaml with a plain text editor.
sudo install -d -m 0755 /opt/zigbee2mqtt
sudo install -d -m 0700 /opt/zigbee2mqtt/data
sudo install -m 0644 compose.yaml /opt/zigbee2mqtt/compose.yaml
sudo install -m 0600 private/configuration.yaml /opt/zigbee2mqtt/data/configuration.yaml
cd /opt/zigbee2mqtt
sudo docker compose up -d
sudo docker logs --tail=80 zigbee2mqtt
The container uses Linux host networking here. Its 127.0.0.1:1883 therefore refers to the same local Mosquitto as on the server. This is not true in a normal isolated container network.
The example uses version 2.14.2, which was used in our installation. A pinned version makes the installation more repeatable than a changing latest tag. Before updating later, back up data and check the migration notes for the version you choose. Zigbee2MQTT in Docker
The log should show a successful coordinator TCP connection, Zigbee-herdsman startup, MQTT connection and frontend startup. Socket connected alone does not prove that the whole chain works.
If you use SSH, enable it on the server with sudo systemctl enable --now ssh. Use your local network connection here; no internet port forwarding on the router is needed.
The frontend listens only on the server's 127.0.0.1:8080. If your browser is on another computer, open an SSH tunnel on that computer:
ssh -N -L 8080:127.0.0.1:8080 omauser@192.168.1.50
Then open http://127.0.0.1:8080/ in that computer's browser. Keep the tunnel's terminal window open. The first 8080 is the port on your computer; the last 8080 is the server port. If your computer's port is already in use, change the first one to, for example, 18080 and open http://127.0.0.1:18080/.
Success: the Zigbee2MQTT frontend opens. Zero joined sensors is correct at this stage.
Step 5 Pair the first sensor
Remove the battery insulation tab if present. Bring the sensor close to the coordinator for its first pairing.
- Enable Permit join in Zigbee2MQTT.
Allbeneath the button does not mean joining is already enabled. - Hold the SNZB-02P pairing button for about five seconds, until its light flashes.
- Wait for the device to appear and its Interview to finish.
- Confirm the model is SNZB-02P and set its Friendly name in Zigbee2MQTT to, for example, Office.
- Disable joining after the sensor has joined.
According to the manufacturer, holding the button for five seconds opens pairing mode for 180 seconds. A flashing light alone does not confirm a successful join. Pairing button behaviour
Record the sensor's IEEE Address, its stable identifier. Here, the MQTT topic follows the Friendly name: Office produces zigbee2mqtt/Office. Case and accented characters matter. You can use simple MQTT names and separate display names in your own language.
Open another terminal on the server and listen to the sensor's topic:
cd ~/sensor-diy/files
/opt/sensor-mqtt/.venv/bin/python watch_mqtt.py
Accept the default zigbee2mqtt/Office and enter the MQTT password. The helper's prompts are in Finnish; it asks for the topic first and the password next. It does not put the password on the command line. An example report looks like this:
zigbee2mqtt/Office {"temperature":21.7,"humidity":44.2,"battery":100,"linkquality":138}
If you do not know the correct topic, temporarily enter zigbee2mqtt/#. You will also see other messages, such as Zigbee2MQTT logs. Stop listening with Ctrl+C.
Success: the correct topic contains numeric temperature and humidity values. Values do not necessarily change with every report. Give the sensor a moment, or gently warm it in your hand; avoid condensation.
Step 6 Create the database and API
Return to ~/sensor-diy/files. The two SQL commands below create a new PostgreSQL role, database and table. They are for an initial installation. If sensor_api or sensordata already exists, stop and adapt the installation to that database. Do not delete an existing database just to make the commands succeed.
cd ~/sensor-diy/files
sudo systemctl enable --now postgresql
sudo -u postgres psql -v ON_ERROR_STOP=1 < private/bootstrap.sql
sudo -u postgres psql -v ON_ERROR_STOP=1 < schema.sql
Your shell reads the files and passes their contents to PostgreSQL. This means the postgres user does not need access to your private home directory. A possible could not change directory ... Permission denied notice concerns the working directory; an actual SQL error is a separate matter. ON_ERROR_STOP stops execution on an SQL error.
The table is public.temperature_readings:
| Field | Meaning |
|---|---|
| sensor_id | Stable sensor identifier |
| room | Room or location name to display |
| measured_at | In this collector, the time the MQTT report was received, in UTC |
| received_at | Time the report was stored in the database |
| temperature_c | Temperature in degrees Celsius, NUMERIC(5,2) |
| humidity_percent | Relative humidity as a percentage, NUMERIC(4,1); NULL when missing |
The combination of sensor and report time is unique. Retrying a queued report after a response is lost will not create a second historical row.
Install the API and its service:
sudo install -m 0644 main.py /opt/sensor-api/main.py
sudo install -m 0600 private/sensor-api.env /etc/sensor-api.env
sudo install -m 0644 sensor-api.service /etc/systemd/system/sensor-api.service
sudo systemctl daemon-reload
sudo systemctl enable --now sensor-api
sudo systemctl status sensor-api --no-pager
curl -sS --fail http://127.0.0.1:8000/health
Success: /health returns {"status":"ok"}. This checks the HTTP service. A real report in the next step and a database query are needed to confirm that storage works.
Step 7 Connect the MQTT receiver
Create your sensor mapping:
cp sensors.example.json sensors.json
nano sensors.json
Replace the example identifier OMA_IEEE_OSOITE with your sensor's own IEEE address. JSON uses straight quotation marks and no comma after the final member. Työhuone is our Finnish display name for the office; choose your own room name.
{
"zigbee2mqtt/Office": {
"sensor_id": "OMA_IEEE_OSOITE",
"room": "Työhuone"
}
}
The MQTT topic matches the Zigbee2MQTT name. room is the name shown in SensorThrust, so it does not have to match the MQTT name. This solved our first collection problem: we were subscribing to a different topic from the one the sensor actually published to.
python3 -m json.tool sensors.json > /dev/null
sudo install -m 0644 mqtt_to_api.py /opt/sensor-mqtt/mqtt_to_api.py
sudo install -m 0644 sensors.json /opt/sensor-mqtt/sensors.json
sudo install -m 0600 private/sensor-mqtt.env /etc/sensor-mqtt.env
sudo install -m 0644 sensor-mqtt.service /etc/systemd/system/sensor-mqtt.service
sudo systemctl daemon-reload
sudo systemctl enable --now sensor-mqtt
sudo journalctl -u sensor-mqtt -n 30 --no-pager
Success: the log shows an MQTT connection, followed by the room's reading and HTTP 201 after the next new report. If conditions are stable, you may need to wait for a report. The collector does not record a previously published snapshot as a new measurement.
The receiver first saves a new report in /var/lib/sensor-mqtt/pending.sqlite3. During an API outage, the report stays there and delivery is retried. Retrying a report already accepted by the API may return HTTP 409, which the receiver treats as success. During a long API outage, the queue grows on disk; check available space with df -h if needed.
This does not guarantee that every radio measurement is preserved. When the entire collection computer is off, not all reports generated during that time can be recovered later. A disk failure can also destroy both the history and the local queue; a backup is different from a queue.
Step 8 Confirm that the report is in the database
sudo -u postgres psql -d sensordata -c "
SELECT room, measured_at, received_at, temperature_c, humidity_percent
FROM public.temperature_readings
ORDER BY received_at DESC
LIMIT 10;"
Compare the room and readings with the MQTT message. The timestamp should belong to the correct moment. PostgreSQL may show a timestamp in the local timezone while the API shows the same moment in UTC. For example, 12:00+02 in winter and 10:00Z are the same instant.
Also check that the computer's clock is synchronised:
timedatectl status
Success: the query shows the correct sensor's report and new reports add rows to the table. Check this before troubleshooting HTTPS access or phone settings.
Step 9 Check the SensorThrust feed
The read key is in private/read.env, created by the preparation program. It is different from the collector's write key. The following command reads the key from the file into a subshell, so the key itself does not end up in shell history:
cd ~/sensor-diy/files
(
. ./private/read.env
curl -sS --fail-with-body --max-time 15 \
-H "X-API-Key: $READ_API_KEY" \
-H 'User-Agent: SensorThrust/1.0' \
http://127.0.0.1:8000/v1/feed
)
The response starts with schema_version, generated_at and items. One sensor produces two items, temperature and humidity. The API returns each sensor's latest report, not its full history. An empty items array means the database has no reports yet.
Reported does not necessarily mean just measured. Zigbee2MQTT can send a new humidity value and a previously received temperature in the same state message. We do not know the exact original measurement time of each value. The feed therefore sets measured_at to null; reported_at is the report's receipt time and received_at is its storage time. generated_at only indicates when this HTTP response was generated.
One read key can see all sensors in this service. This is a personal feed, not a ready-made service with isolated accounts for multiple customers. Feed format
Step 10 Give the feed an HTTPS address
At this point, collection works locally. SensorThrust needs an HTTPS address; plain http://192.168... is not accepted by the app. We used Cloudflare Tunnel to publish only the read feed to the internet. You can also use another properly secured HTTPS proxy, or a VPN setup with a valid HTTPS address.
The Cloudflare approach requires your own account, a domain managed in that account, and a running cloudflared tunnel connection on the server. It does not require opening a port forward on your router. If you already have a tunnel for another service, you can add a separate route to it. Cloudflare tunnel publishing instructions
Install cloudflared from the official source, create a tunnel in Cloudflare's dashboard and install its service using the command provided for that machine. The tunnel token in the command is secret: do not paste it into conversations or example screenshots. Confirm the connection with systemctl status cloudflared.
Add a published application route:
| Setting | Value for this single-computer example |
|---|---|
| Hostname | Your own domain name, for example api.omadomain.example |
| Path | ^/v1/feed$ |
| Service URL | http://127.0.0.1:8000 |
127.0.0.1 works here because cloudflared and the API run on the same Linux computer in the same network environment. If the tunnel program runs on another computer or in an isolated container, its localhost is a different place. Do not simply copy the table's Service URL in that case.
With the path restriction in place, /health, /temperatures and other paths must not be routed to the API through this public hostname. Check the tunnel's other routes: there must not be a broader fallback route exposing the entire service on the same hostname. Do not publish MQTT, PostgreSQL or the coordinator's radio socket.
Check the public feed from the server or another computer using the correct read key. If running on another computer, read the key there with hidden input or protect a local key file; the server's private/read.env is not automatically available there.
cd ~/sensor-diy/files
(
. ./private/read.env
curl -sS --fail-with-body --max-time 15 \
-H "X-API-Key: $READ_API_KEY" \
-H 'User-Agent: SensorThrust/1.0' \
https://api.omadomain.example/v1/feed
)
curl -i --max-time 15 https://api.omadomain.example/v1/feed
curl -i --max-time 15 https://api.omadomain.example/health
curl -i --max-time 15 https://api.omadomain.example/temperatures
Success: the correct key returns HTTP 200 and your JSON. Without a key, the feed must not return readings; the API returns 401, or a protection layer in front may reject the request earlier. The other two paths return 404. If you get 502, compare the local API test with the tunnel's destination address. For Cloudflare 403/1010 errors, check the protection settings for the restricted API route; working in a browser alone does not prove the app's request will be accepted.
A tunnel does not replace a read key or provide complete protection against malicious traffic. Keep software updated and watch how the public route is used. A small collection system like this does not need a separate server cluster or extensive monitoring system to get started.
Step 11 Show readings on your phone
Open SensorThrust and add a data source. Enter the feed's final HTTPS URL and READ_API_KEY, not the collector's write key. You can find the read key in your own private/read.env file on the server. Keep it private.
Choose Test and save. Once readings appear by room, choose a reading for the main card. Next, add the medium Home Screen widget and select one to four readings. The rectangular Lock Screen widget displays one reading; two separate widgets can show, for example, temperature and humidity side by side.
iOS decides when widgets refresh. Waking the screen does not guarantee a new network request. Even a successful fetch can return the same report, in which case its age correctly continues to increase. SensorThrust displays data but does not send threshold alerts.
Add the remaining sensors
Pair each new sensor in the same way, name it in Zigbee2MQTT and add its own IEEE identifier under its MQTT topic in sensors.json. Each sensor needs a different identifier. Do not reuse one sensor's identifier for another, even if they share a room.
Replace both placeholder identifiers below with your own. Työhuone and Olohuone are example display names for the office and living room.
{
"zigbee2mqtt/Office": {
"sensor_id": "TYOHUONEEN_OMA_IEEE",
"room": "Työhuone"
},
"zigbee2mqtt/Livingroom": {
"sensor_id": "OLOHUONEEN_OMA_IEEE",
"room": "Olohuone"
}
}
cd ~/sensor-diy/files
python3 -m json.tool sensors.json > /dev/null
sudo install -m 0644 sensors.json /opt/sensor-mqtt/sensors.json
sudo systemctl restart sensor-mqtt
sudo journalctl -u sensor-mqtt -n 20 --no-pager
There is no need to change the API code or database table. Once the first report is stored, the sensor appears in /v1/feed. Refresh SensorThrust and select the new reading in a widget if you wish. If you later rename a device in Zigbee2MQTT, also update the MQTT topic in the mapping.
Optional extra Grafana for your own charts
We also used Grafana to create temperature and humidity charts from measurements stored in the database. It is a useful extra for your own internal use: you can compare rooms or look at how the temperature changed overnight or over a week. The same readings can become attractive charts and dashboards.
Grafana is not required to use SensorThrust. SensorThrust gets its readings directly from your API's /v1/feed. Collection, storage, the app and widgets all work without Grafana. You can add it later to explore historical data and keep its dashboards on your local network.
Services and logs
| Component | Restart | Log |
|---|---|---|
| Zigbee2MQTT | sudo docker restart zigbee2mqtt |
sudo docker logs --tail=80 zigbee2mqtt |
| Mosquitto | sudo systemctl restart mosquitto |
sudo journalctl -u mosquitto -n 50 --no-pager; on Debian also /var/log/mosquitto/mosquitto.log if file logging is enabled |
| MQTT receiver | sudo systemctl restart sensor-mqtt |
sudo journalctl -u sensor-mqtt -n 50 --no-pager |
| API | sudo systemctl restart sensor-api |
sudo journalctl -u sensor-api -n 50 --no-pager |
| PostgreSQL | sudo systemctl restart postgresql |
sudo journalctl -u 'postgresql@*' -n 50 --no-pager; Debian also has logs in /var/log/postgresql/ |
| Cloudflare Tunnel | sudo systemctl restart cloudflared |
sudo journalctl -u cloudflared -n 50 --no-pager |
Do not restart the database just because a sensor report is old. Follow the chain to the first point where data is missing. systemctl daemon-reload is required after changing a .service file; after editing Python code or sensors.json, restarting that service is enough.
Reboot the computer at a suitable time, then check:
systemctl --failed
systemctl is-active docker mosquitto sensor-api sensor-mqtt postgresql
sudo docker ps
sudo journalctl -u sensor-mqtt --since '10 minutes ago' --no-pager
Also run the database query from step 8. An active service alone does not prove new reports are arriving from a sensor.
Keep the server updated. We enabled Debian's automatic security updates with unattended-upgrades. A kernel update may require a planned reboot. Afterwards, use the commands above to check that collection resumes.
When something does not work
| Symptom | First check |
|---|---|
| Sensor flashes but will not join | Permit join enabled, button held for about 5 s, sensor close to coordinator, Interview log |
| MQTT connects but no readings arrive | Actual topic using watch_mqtt.py; Office and office are different topics |
| Frontend does not open on your computer | SSH tunnel open and browser using its local port |
| Cannot connect to coordinator | IP, Ethernet, coordinator mode and Zigbee2MQTT log; do not open the same radio socket from another program while it is in use |
| API will not start | Environment file, PostgreSQL running and sensor-api log |
| Receiver stops on HTTP 401 | Write key matches the API's API_KEY; queue remains, correct the setting and restart receiver |
| API returns 422 | JSON fields, value types and a timestamp with timezone; check receiver and API logs |
| Database grows but app does not work | Read key, local /v1/feed, public HTTPS route and its response, in that order |
| Value does not change | Compare report time, receiver log and database; a stable temperature may be correct |
| Reading looks old after a successful refresh | A successful network fetch does not change an old report's timestamp |
Our SNZB-02P Reporting view showed a minimum of 10 s, a maximum of 3600 s and a change threshold of 100 raw units for temperature and humidity. Those thresholds represented 1 °C and one percentage point of humidity. This was not a fixed ten-minute reporting interval. Your device firmware and whether settings are accepted affect behaviour; start with working defaults and check actual messages before adjusting them.
Back up before you need to
Copying history to the same disk can help recover from accidental changes but not from disk failure. Keep at least one other copy on another device or elsewhere under your control. Protect configuration files containing secrets.
Create a consistent backup while the database is running:
mkdir -p ~/sensor-backups
chmod 0700 ~/sensor-backups
(umask 077; sudo -u postgres pg_dump -Fc sensordata > ~/sensor-backups/sensordata-$(date +%Y%m%d-%H%M%S).dump)
Also save:
/opt/zigbee2mqtt/data: Zigbee network configuration, devices and coordinator backup;/etc/mosquitto/conf.d/sensors.confand/etc/mosquitto/passwd;/etc/sensor-api.envand/etc/sensor-mqtt.env;- API and receiver source code,
sensors.jsonand service definitions; - the unsent SQLite queue in
/var/lib/sensor-mqtt, if it contains reports; - your own administrative details needed to restore the tunnel.
Copy Zigbee2MQTT's state during a planned stop, and copy the SQLite queue files while the receiver is stopped. Restart them afterwards. Collection is interrupted during the stop. Python virtual environments do not need to be moved to another operating system: reinstall dependencies there.
Try restoring the database into a separate empty test database. For example, on the same server before practising other recovery steps. Replace VALITSE_OMA_VARAKOPIO.dump with the backup file you actually want to restore:
sudo -u postgres createdb sensordata_restore_test
sudo -u postgres pg_restore --exit-on-error --no-owner \
-d sensordata_restore_test < ~/sensor-backups/VALITSE_OMA_VARAKOPIO.dump
sudo -u postgres psql -d sensordata_restore_test \
-c 'SELECT count(*) FROM public.temperature_readings;'
This does not replace the production database; the test database has a different name. A file's existence does not yet prove a restore will work. If the whole computer fails, install the software on a replacement, restore roles, settings and database, and check one real report through the entire chain. The local delivery queue does not replace this backup.
What you can change later
You can switch to another sensor model supported by Zigbee2MQTT, use a USB coordinator or build a collector for Wi-Fi sensors. A Wi-Fi sensor generally does not need this chain's Zigbee coordinator. The device's output determines how to build the collector.
SQLite can replace PostgreSQL in a small setup, and Home Assistant can replace several parts of the chain. Adapt SQL, service installation and data conversion to the solution you choose. This package deliberately uses PostgreSQL, as our original implementation did.
For SensorThrust, the stable interface is SensorThrust v1 JSON. You can implement it using any language or database. Other numeric data can use the same contract; this guide's collector and API are limited to temperature and humidity. The app does not guess arbitrary JSON structures or automatically turn an MQTT topic into a feed.
Once your first sensor appears in your own widget, you have built a complete chain from a radio message to your own storage and display. Expand it to suit your needs.
Sources and versions
This guide is based on our Debian 12 setup and its Python programs. The shared package's directories and service accounts have been standardised as described above. A fresh Debian installation and alternative operating systems were not run through as part of writing this guide. Checking the examples and testing a real hardware installation are different things.
External instructions checked on 7 November 2026. Use instructions that match your device model and chosen software version.