RS-485 home sensors
Radon sensors, power meters and temperature/humidity sensors on RS-485/Modbus, bridged to MQTT by Wemos D1 Mini boards and shown in Homey. This page covers wiring, flashing and setup for every part, and how to move it all to a new server or Homey.
At runtime the server only runs the MQTT broker. The radon sensors work on their own (the LCD shows ID, status and radon level) with no network at all. Build tools are only needed to flash firmware or install the Homey app.
Folder in ~/arduino/arduino/ | Contents |
|---|---|
RadonSensorArduino_v2/ | Uno firmware, setup guide, meter manuals |
WemosD1MiniRS485ModbusMqtt/ | Bridge firmware, one codebase for every bridge (git) |
com.radonsensor.mqtt/ | Homey app (git) |
MQTT server
Mosquitto receives everything the bridges publish and passes it to Homey. It needs a fixed address and a login for every client.
- Give the server a fixed IP.
The bridges and the Homey app store the broker address, so it must never change: use a DHCP reservation in the router, or a static IP. This guide writes it as
<broker-ip>. Avoid addresses ending in.0or.255: on a typical /24 network those are not usable host addresses. - Install Mosquitto.
sudo apt update sudo apt install mosquitto mosquitto-clients sudo systemctl enable --now mosquitto
- Listen on the LAN and require a login.
Create
/etc/mosquitto/conf.d/local.conf:listener 1883 allow_anonymous false password_file /etc/mosquitto/passwd
Leave the package's
mosquitto.confas is: it already enables persistence, so retained messages (link state, backlight, WiFi signal) survive a broker restart. - Create one user per client.
One for the bridges, one for Homey, so either can be revoked on its own.
# -c only for the first user: it creates the file sudo mosquitto_passwd -c /etc/mosquitto/passwd wemos sudo mosquitto_passwd /etc/mosquitto/passwd homey sudo chown mosquitto:mosquitto /etc/mosquitto/passwd sudo chmod 640 /etc/mosquitto/passwd sudo systemctl restart mosquitto - Allow MQTT from the LAN only.
If
ufwis active, with your LAN subnet in place of<lan-subnet>. Never expose port 1883 to the internet: it is unencrypted.sudo ufw allow from <lan-subnet> to any port 1883 proto tcp # e.g. 192.168.1.0/24 - Install the build tools (only on the machine you flash from).
sudo usermod -aG dialout $USER # serial ports; log in again curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh arduino-cli config init arduino-cli config set directories.user ~/arduino/arduino arduino-cli config add board_manager.additional_urls \ https://arduino.esp8266.com/stable/package_esp8266com_index.json arduino-cli core update-index arduino-cli core install arduino:avr@1.8.8 esp8266:esp8266@3.1.2 arduino-cli lib install "ModbusMaster@2.0.1" "PubSubClient@2.8" # Homey CLI via Node.js 24 curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash nvm install 24 && npm install -g homey
The Uno needs the fmalpartida "New LiquidCrystal" library, which is not in the Library Manager: copy
~/arduino/arduino/libraries/LCDfrom the old machine.
Check
Anonymous access must be refused (not authorised). With a login, every bridge's messages appear within a minute:
mosquitto_sub -h <broker-ip> -u homey -P '<password>' -t 'rs485/#' -v
Topics
Everything is under rs485/<bridge>/. A device state always carries link (1/0); other fields appear only when read successfully in that poll, otherwise error says what failed.
| Topic | Payload | Retained |
|---|---|---|
status | online / offline (last will) | yes |
name | the bridge's BRIDGE_NAME, e.g. Power bridge (Homey's pairing name) | yes |
wifi/rssi | signal in dBm, e.g. -57 | yes |
button/<1-3> | pressed | no |
inventory | boot scan result, e.g. {"radon":[7],"unknown":[12]} | yes |
radon/<id>/state | {"link":1,"radon":85.9,"backlight":"on"} | yes |
dtsu666/<id>/state | power, energy_import/export, voltage_l1–l3, current_l1–l3 | yes |
sdm120/<id>/state | power, energy_import/export, voltage, current | yes |
renke_th/<id>/state | {"link":1,"temperature":21.5,"humidity":68.3} | yes |
radon/<id>/backlight/set | on / off (command to the bridge) | no |
Radon sensor
A standalone sensor that shows its ID, status and radon level on the LCD, and answers as a Modbus slave on the radon bus.
| Signal | Uno pin | Notes |
|---|---|---|
| RD200M TX → Uno | D2 | SoftwareSerial RX, 19200 baud |
| Uno → RD200M RX | D3 | SoftwareSerial TX |
| LCD SDA / SCL | A4 / A5 | I2C address 0x27 |
| MAX485 DE + RE (tied) | D7 | HIGH = transmit |
| MAX485 RO → Uno | D8 | SoftwareSerial RX, 9600 8N1 |
| Uno → MAX485 DI | D9 | SoftwareSerial TX |
| ID straps | D10–D12 ↔ D13 | read once at boot |
- Set the bus ID with the straps.
Use IDs 1–7, unique on the bus. Never use ID 0: it is the Modbus broadcast address and can never answer.
- Flash the firmware.
arduino-cli board list # find the port, e.g. /dev/ttyACM0 cd ~/arduino/arduino/RadonSensorArduino_v2 arduino-cli compile --fqbn arduino:avr:uno . arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:avr:uno .The firmware needs no configuration.
- Wire it onto the radon bus.
A to A, B to B, with a common ground between all nodes. Terminate the two physical ends of the bus with 120 Ω.
- Restart the radon bridge. Its boot scan finds the new ID by itself (see Wemos bridge). Radon sensors must use an ID from 1 to 7.
Check
After boot, line 1 shows the status and the ID as its last character, and line 2 shows the radon level in Bq/m³. The RD200M only updates every 10 minutes, so the value changes slowly.
Wemos bridge
The Modbus master for exactly one bus. At boot it finds the devices on that bus, then polls them, publishes their state to MQTT, and has three pushbuttons for Homey flows. Every bridge runs the same firmware; one small committed file per bridge makes each one different.
| Signal | Wemos pin | Notes |
|---|---|---|
| MAX485 DE + RE (tied) | D0 | HIGH = transmit |
| MAX485 RO → Wemos | D1 | SoftwareSerial RX, must be 3.3 V |
| Wemos → MAX485 DI | D2 | SoftwareSerial TX |
| Optional OLED SDA / SCL (SCK) | D3 / D4 | SSD1306, 0.96" 128×64 or 0.91" 128×32 (set DISPLAY_HEIGHT), I2C 0x3C or 0x3D. VCC to 3V3, GND to GND; 3.3 V module only. Some modules label SCL as SCK. Detected at boot; without one the bridge runs as normal |
| Status LED | D8 | active high: D8 → 220–1000 Ω → LED → GND. Blinks on polls, errors and presses |
| Buttons 1 / 2 / 3 | D5 / D6 / D7 | to GND, 10 kΩ pull-up to 3V3 |
| USB serial | RX / TX | kept free for the debug log, 115200 baud |
Plan the buses and bridges
Planning the Modbus side is up to you. The bridge configures nothing on the devices: it only finds devices that are already set up and wired. Before a bridge can find a device, give it a Modbus ID that is unique on its bus (straps on a radon Uno, menu or setup registers on a meter), set its serial format to match the rest of its bus, and wire it on (A to A, B to B, common ground, 120 Ω at both ends).
One bus, one serial format. A bridge talks to its whole bus with one baud rate, parity and stop-bit setting, so every device on the bus must use the same. When devices can't agree, they go on separate buses, and each bus gets its own bridge.
| You need another bridge when | Example |
|---|---|
| Devices can't share a serial format | Radon Unos only speak 9600 8N1; the meters and climate sensors here run 4800 8N1. Two buses, two bridges. |
| A device must be alone on its bus | Radon Unos react to stray bytes in other devices' traffic, so they never share a bus with meters. The build refuses a config that mixes them. |
| There is no cable route between devices | A meter in a detached garage and one in the house: give each building its own short bus and bridge instead of running cable between them. WiFi carries the rest. |
| IDs run out or clash | A radon Uno can only use IDs 1–7, so an 8th radon sensor needs a second radon bus. Two devices with the same fixed ID also need separate buses. |
Extra bridges cost nothing in Homey: each has its own BRIDGE_ID, and devices are keyed by bridge + type + ID, so the same ID can exist on two buses. At the extreme you could give every device its own bridge. That works, but a single bus carries many devices, so one bridge per bus is the normal setup; add bridges where formats, building layout or ID ranges call for it.
Examples
| Setup | Bridges | Bridge file (src/bridges/) | BRIDGE_ID |
|---|---|---|---|
| Radon sensors only | 1 | radon.h: 9600 8N1, types 1 | "radon" |
| Radon sensors plus meters and climate sensors (this house today) | 2 | radon.h: 9600 8N1, types 1power.h: 4800 8N1, types 2, 3, 4 | "radon""power" |
| DTSU666 in the house, SDM120 in a detached garage, no cable between | 2 | two files with the same bus settings, types 2, 3 | "power""garage" |
| One bridge per device | 1 each | e.g. types 3, scan range narrowed to the meter's own ID | one per bridge |
Every bridge also needs its own MQTT_CLIENT_ID. With the scan range narrowed to a single ID, the boot scan takes well under a second.
The config files
| File | Per bridge? | What it holds |
|---|---|---|
src/bridges/<name>.h | yes, one file each | The bridge's ID (BRIDGE_ID) and Homey name (BRIDGE_NAME), its MQTT_CLIENT_ID, the OLED size (DISPLAY_HEIGHT), and its bus: serial format, boot scan settings, and which device types to look for. Committed. |
secrets.h | no, shared | WiFi and MQTT login. Gitignored. |
bus_config.h | no | Picks the bridge file from the name given to build.sh. |
device_catalog.h | no | Every device type the firmware knows, by number. Changes only when support for a new type is added. |
The catalogue is the dictionary that turns a short number in a bridge file into a device type. Numbers are never reused or changed.
| Number | Type | IDs | Polled every |
|---|---|---|---|
1 | Radon sensor (Arduino Uno + RD200M) | 1–7 | 60 s |
2 | Chint DTSU666 3-phase meter | 1–247 | 10 s |
3 | Eastron SDM120-M 1-phase meter | 1–247 | 10 s |
4 | Renke RS-WS-N01-2 temperature/humidity transmitter | 1–247 | 30 s |
How the boot scan works. Each catalogue entry holds two requests: a presence request sent to every ID the type allows (any reply, even a Modbus error reply, means "something answers here"), and an identify request that only that type answers correctly: a DTSU666 reports its own ID in register 0x002E, an SDM120 a mains voltage, and the Renke, which answers every unknown register with 0, is checked last by its humidity. The bridge sends the presence request to each ID in the scan range, retries silent IDs in later passes, identifies every ID that answered, logs the result and publishes it as its inventory. The scan takes roughly silent IDs × timeout × passes: a few seconds for the radon bus, about 105 s for the full 1–247 scan of the power bus, so narrow the range to the IDs you use. A bridge holds up to 32 devices.
Adding a new device type is a firmware change, not just a config edit: it needs a catalogue entry, code that reads and publishes the device's values (meters.cpp and pollDevice() in the .ino), and a matching driver in the Homey app.
- Create the shared
secrets.h(once, for all bridges).cd ~/arduino/arduino/WemosD1MiniRS485ModbusMqtt cp secrets.example.h secrets.h # gitignored, never commit itSetting Set to WIFI_SSID,WIFI_PASSWORDyour WiFi network MQTT_HOST<broker-ip>, the broker's fixed IPMQTT_USERNAME,MQTT_PASSWORDthe wemosuser - Set up the bridge's file in
src/bridges/.radon.handpower.hexist; for a new bridge, copy one.Setting radon.hpower.hBRIDGE_NAME"Radon bridge""Power bridge"BRIDGE_ID"radon""power"MQTT_CLIENT_IDhome-esp8266-rs485-01home-esp8266-rs485-02BUS_BAUD96004800BUS_DATA_BITS,BUS_PARITY,BUS_STOP_BITS8,'N',1BUS_SCAN_FIRST_ID,BUS_SCAN_LAST_ID1,247(narrow it to shorten the scan)BUS_SCAN_TIMEOUT_MS,BUS_SCAN_PASSES300,3200,2BUS_DEVICE_TYPES12, 3, 4DISPLAY_HEIGHTnot set (64) 32(0.91" OLED fitted)BRIDGE_NAME(1–32 characters) is the name Homey gives the bridge when it is paired; renaming later is done in Homey.DISPLAY_HEIGHTis the OLED's pixel height, 32 or 64 (the default); on a 128×32 display the bridge shows only its ID, the MQTT state and three device lines.BRIDGE_IDbecomes the topic prefixrs485/<BRIDGE_ID>/; don't change it after pairing in Homey. Every bridge needs its ownMQTT_CLIENT_ID, or the broker keeps disconnecting one of them. No slave IDs are listed anywhere: at every boot the bridge scans the bus, identifies each device that answers, and polls only those. Radon sensors only answer on IDs 1–7 and must be alone on their 8N1 bus; the build fails if a bridge file breaks that rule. A device added later is found at the next bridge restart.For a new bridge, also add a
BRIDGE_<NAME>line tobus_config.hand the board's USB serial number (fromls -l /dev/serial/by-id/) tobuild.sh. - Build and flash it.
build.shpicks the bridge file and flashes only that bridge's own board, found by its USB serial number, so firmware can't land on the wrong bridge even with both plugged in. It refuses to upload while a serial monitor holds the port: an upload that competes for the port can report success while the board keeps the old firmware../build.sh radon # compile only ./build.sh radon upload # compile and flash the radon bridge ./build.sh power upload # compile and flash the power bridge
A plain
arduino-cli compilestops with "No bridge selected" instead of guessing.
Check
The serial log (115200 baud) shows the bridge ID and bus format, then the boot scan:
[Scan] Looking for types: 1=radon [Scan] Probing IDs 1-7, 3 pass(es), timeout 300 ms [Scan] ID 7 answers [Scan] 1 device found in 6.9 s [Scan] ID 7: radon [Scan] Done: 1 matched, 0 unknown
then WiFi with signal strength and the MQTT connection. The LED blinks once when WiFi connects and three times when MQTT does. Opening the serial port restarts the board, and with it the boot scan. On the broker you should see rs485/<bridge>/status online, the inventory, wifi/rssi every minute, a state per device, and button/<n> pressed for each press. For button trouble, set kButtonPinDiagnostics = true in the .ino to log raw pin levels.
Power meters and climate sensors
Three-phase and single-phase DIN-rail meters, read every 10 seconds, and wall-mounted temperature/humidity transmitters, read every 30 seconds, share one bus at 4800 8N1 behind the power bridge.
One-time device setup
Every device on the power bus must run 4800 baud, 8 data bits, no parity, 1 stop bit, with a unique ID (1–247). Change IDs with only that one device connected: every device ships with ID 1.
- DTSU666: switch it to Modbus.
It ships in DL/T 645 mode, not Modbus. In the meter's menu (password
701, thenConn) setAddrto its ID andbAudto 4800. The protocol register0x002Cselects Modbus and the framing:3= n.1 (no parity, 1 stop bit), which the power bus uses. - SDM120: set baud, framing and ID.
It ships at 2400 baud, ID 1. Hold its button for 3 s until the display shows
-SET-, then write the holding registers over Modbus at its current 2400 baud, for example from the server with a USB-RS485 adapter andmbpoll:Register Value Meaning 4002914800 baud 400190no parity, 1 stop bit 40021new ID 1–247 Values are 32-bit floats, written with function 0x10. Power-cycle the meter afterwards. UNKNOWN The manual gives both "none" and "even" as the default parity; check the display.
- Renke: set the ID.
It ships at 4800 8N1, ID 1, which already matches the bus. Change the ID with Renke's "485 parameter configuration software" from the manufacturer's data package, with only that one transmitter connected. It only supports function 0x03: register
0x0000is humidity ×10 (%RH),0x0001temperature ×10 (°C, negative below zero). - Flash the power bridge (
./build.sh power upload). Its boot scan finds every device at the ID you set and names its type in the serial log; tested with 5 DTSU666, 6 SDM120 and 6 Renke transmitters on one bus. - Compare the first readings with each meter's own display.
Verified on real meters: the DTSU666 answers function 0x03, sends floats high word first, and its voltage, current and power scaling is right. One detail is still open, a one-line switch at the top of
meters.cpp:- UNKNOWN Energy scaling: 1.0 assumed (
kDtsuEnergyScale). Correct it if the kWh reading differs from the display.
- UNKNOWN Energy scaling: 1.0 assumed (
What each device reports
| Value | DTSU666 (3-phase) | SDM120 (1-phase) | Renke |
|---|---|---|---|
| Power now | total W, negative when exporting | W | – |
| Energy imported / exported | kWh / kWh | kWh / kWh | – |
| Voltage | L1, L2, L3 (V) | V | – |
| Current | L1, L2, L3 (A) | A | – |
| Temperature / humidity | – | – | °C / %RH |
| Registers read | 0x2006–0x2013, 0x401E–0x4029 | 0x0000–0x000D, 0x0048–0x004B (FC 04) | 0x0000–0x0001 |
| Raw scaling | V ×0.1, A ×0.001, W ×0.1 (direct connection, no CT) | none, already in units | ×0.1, temperature signed |
With external current transformers on the DTSU666, current and power must also be multiplied by the CT ratio.
Homey
The "RS-485 Bridge (MQTT)" app turns every bridge and device into a Homey device. It needs a Homey Pro on the same LAN as the broker; Homey Cloud cannot run it.
- Point the app at the broker.
Set
MQTT_HOSTinconfig.jsto<broker-ip>, and create the gitignoredenv.jsonwith thehomeyuser. Keep it out of anything you share.{ "MQTT_USERNAME": "homey", "MQTT_PASSWORD": "<password>" } - Install it on a Homey. To move to another Homey, run the same commands with that Homey selected. Devices, flows and Insights history do not move with the app.
cd ~/arduino/arduino/com.radonsensor.mqtt npm install homey login homey select homey app validate --level debug homey app install
- Pair the devices (Add device → RS-485 Bridge (MQTT)). The bridges must already be running: pairing lists the devices in each bridge's boot scan inventory, so allow a minute. A paired device that a later scan no longer finds shows as unavailable ("Not found on the bus at the bridge's last boot").
Driver Pairs as Shows Radon sensor Radon sensor 7 (radon)radon Bq/m³, LCD backlight on/off 3-phase power meter Power meter 3 (power)power, energy in/out, V and A per phase 1-phase power meter Power meter 60 (power)power, energy in/out, V, A Temperature/humidity sensor (Renke) Climate sensor 10 (power)temperature, humidity RS-485 bridge Radon bridge(itsBRIDGE_NAME)buttons 1–3, WiFi signal, online state
Check
Each device becomes available once its first state arrives, and shows "Link lost" when its bus stops answering, or "Not found on the bus at the bridge's last boot" when the bridge's scan no longer finds it. The bridge device's flow card Button [1/2/3] was pressed fires on a physical press and on a tap on the tile.