NRNetRelay × MQTT
APPLICATION AND HARDWARE GUIDE · v2.0 · AUGUST 2026

Monitor and control NetRelay with MQTT.

Control four relay outputs, monitor four digital inputs in real time, and securely manage multiple branches from one local server and web panel.

4 × digital inputsReal-time 0/1 event monitoring
4 × relay outputsTargeted and grouped control
Ethernet · Wi-Fi · PoELocal-network operation
MQTT · REST · WebSocketFlexible integration layer
01 · OVERVIEW

One panel, many branches, real-time control.

Each NetRelay card connects to the MQTT broker with its own account. The server shows online devices, sends commands only to the selected device, stores state changes in SQLite, and isolates each account to its own topic namespace.

!
Electrical safety

Work involving mains voltage must only be performed by qualified personnel. Disconnect power, use suitable protection and enclosures, and verify the electrical limits of your exact hardware model.

LOCAL CONTROL

No mandatory cloud

The broker, panel and devices can operate entirely on the local network.

TARGETED COMMANDS

Per-device topics

Each card listens only to netrelay/<username>/command.

LIVE TELEMETRY

Input and relay events

State, uptime, hostname, IP, voltage and temperature are normalized by the server.

PERSISTENT HISTORY

Changes, not heartbeat noise

Repeated five-second status packets are ignored unless a meaningful value changes.

02 · ARCHITECTURE

How data moves through the system.

ComponentResponsibility
NetRelay firmwareConnects to the broker, publishes status/events, receives QoS 1 commands and prevents duplicate commandId execution.
MQTT ServerAuthenticates accounts, enforces topic ACLs, processes automation and exposes the web panel and REST API.
SQLiteStores MQTT/web users, history, audit records, rules, schedules, groups, API keys and settings.
Web/mobile clientsRead authorized state and issue commands without direct access to device credentials.
i
Default ports

MQTT: 1883, MQTT TLS: 8883, web panel/API: 3000 unless changed in the environment settings.

03 · DEVICE SETUP

Connect every card with a unique identity.

1

Create an MQTT user

Open System → MQTT Users, create a strong unique username/password and keep the account enabled.

2

Configure the card

Enter the broker IP or hostname, port, username and password in the NetRelay MQTT settings. Use a different account for every branch/card.

3

Verify connectivity

The device must appear under Online Devices. Open Device I/O to inspect relays, inputs, voltage, temperature and the last JSON packet.

4

Test safely

Use a safe low-voltage test load first. Toggle Relay 1, trigger an input and verify both state changes in the panel and History page.

04 · MQTT SETTINGS

Accounts and topic contract.

TopicPurpose
netrelay/<username>/commandQoS 1 relay, sync, restart, queue and OTA commands sent to one device.
netrelay/<username>/eventsDevice status, relay event and input event messages published by the card.
homeassistant/.../configRetained MQTT Discovery definitions published by the server.

Topic enforcement should remain enabled. A normal device account cannot publish commands to, or subscribe to events from, another username. The configured Home Assistant account receives only the additional integration permissions it requires.

05 · RELAY AND DEVICE COMMANDS

Reliable, targeted JSON commands.

Relay command
{
  "type": "netrelay",
  "command": "set",
  "commandId": "unique-id",
  "targetUsername": "biga_sube",
  "relays": [1, 2],
  "position": 1,
  "delay": 0
}

Relay numbers are 1–4, position is 0 or 1, and delay is measured in seconds. Restart and sync use the same envelope with command: "restart" or command: "sync". Commands use QoS 1; current firmware uses commandId to avoid applying redelivered commands twice.

06 · INPUT AND RELAY EVENTS

State changes are normalized and stored.

Input event example
{
  "type": "netrelay_input_event",
  "mqttUsername": "biga_sube",
  "input": 1,
  "inputName": "Door Contact",
  "io": 1,
  "voltage": 12.42,
  "deviceUptimeMs": 724500
}
FieldMeaning
ioActual digital input level, 0 or 1.
positionActual relay output level, 0 or 1.
deviceUptimeMsMilliseconds since device boot.
serverReceivedAtISO timestamp added by the server.
07 · MANAGEMENT PANEL

Operations, automation and security in one interface.

MONITORING

Dashboard and Device I/O

Online state, stale-device detection, uptime, inputs, relays, voltage, temperature, sync and restart.

AUTOMATION

Schedules and rules

Cron/sunrise/sunset tasks and input, temperature or voltage rules with relay, e-mail and Netgsm SMS actions.

GROUPS

Group control and queues

Send one command to several branches and queue commands for offline devices.

HISTORY

Events and audit records

Filter SQLite history by multiple MQTT users, export CSV, and track who changed settings or sent commands.

OPERATIONS

Backup and log rotation

Download/restore database settings, archive old logs and run the server as a Windows service.

ACCESS

Role-based panel users

Section permissions, login lockout and an invariant that always keeps at least one active administrator.

08 · REST API AND MOBILE APP

Build a group-scoped mobile control application.

The API base URL is https://server-address/api/v1. Create a device group first, then create a read or control key under System → REST API. A key can see and control only cards belonging to its assigned groups.

Authentication
Authorization: Bearer nr_YOUR_TOKEN
EndpointPurpose
GET /healthPublic server health/version check.
GET /devicesOnline devices within the key's groups.
GET /devices/:usernameLive state of one authorized device.
GET /historyAuthorized device event history.
GET /device-groupsGroups assigned to the key.
POST /devices/:username/relaysRelay control; requires control.
POST /devices/:username/syncRequest current device state.
POST /devices/:username/restartRestart an online device.
POST /device-groups/:id/relaysGroup command with optional offline queue.
Mobile/JavaScript relay request
await fetch(`${baseUrl}/devices/biga_sube/relays`, {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ relays: [1], position: 1, delay: 0 })
});
!
Protect mobile tokens

Use Android Keystore or iOS Keychain. Never hard-code a shared token in a publicly distributed app. Use a user-authenticated backend for public app-store deployments. Requests are limited to 120 per minute; handle 401, 403, 404, 409 and 429 responses explicitly.

09 · HOME ASSISTANT CONNECTION

Discover four relays and four inputs automatically.

No Home Assistant-specific value is entered in the NetRelay card. The device only needs current firmware, its own MQTT account, and working status/event publishing.

1

Create the integration account

Under System → MQTT Users, create an enabled user named homeassistant with a strong password.

2

Publish Discovery

Open System → REST API. In the Home Assistant card, keep the recommended homeassistant Discovery prefix, enable Discovery and click Save and publish.

3

Add MQTT to Home Assistant

Go to Settings → Devices & services → Add integration → MQTT. Enter the NetRelay broker IP/hostname, port 1883 or TLS port 8883, and the homeassistant credentials.

4

Verify entities

Under the MQTT integration, each NetRelay <username> device should contain Relay 1–4 switches and Input 1–4 binary sensors.

ProblemCheck
Connection rejectedAccount enabled state, password, broker address/port and blacklist logs.
Devices missingDiscovery enabled, matching prefix, then Save and publish again and reload MQTT.
Relay state staleDevice online/current firmware; send Sync from Device I/O and inspect event messages.
Inputs not updatingVerify netrelay_device_status and netrelay_input_event traffic.
i
Automatic least-privilege ACL

The configured Home Assistant MQTT user receives only Discovery subscription, NetRelay event subscription and command publication permissions. Do not add every device password to Home Assistant.

10 · DOWNLOADS

Server source and current firmware.

NODE.JS MQTT SERVER

MQTT Server source

Source, release history and installation documents are available on GitHub.

Open GitHub ↗

NETRELAY FIRMWARE

Current device software

Download the correct firmware for your hardware/partition model from the official software page.

NetRelay Software ↗

11 · SECURITY

Protect field control systems.

ACCOUNTS

Unique credentials

Use a separate strong MQTT account for each device and rotate exposed secrets.

NETWORK

IoT VLAN and VPN

Isolate devices and never expose port 1883 directly to the internet.

TLS / mTLS

Verify certificates

Use MQTT TLS 1.2+, CA validation and optional client certificates; use HTTPS for the panel/API.

TOPIC ACL

Keep device namespaces isolated

Leave topic enforcement enabled so one branch cannot see or control another.

SECRETS

Protect backups

Never commit .env, SQLite databases, private keys or backup archives to Git.

API

Least privilege

Assign only required groups and scopes, revoke unused keys and never log full tokens.

12 · TROUBLESHOOTING

Quick diagnostic checklist.

SymptomCheck
Device not onlineBroker address/port, gateway, cable/PoE, MQTT mode and credentials.
Not authorizedAccount enabled state, password and whether the device uses only its own topic namespace.
Command not receivedCurrent firmware, command topic subscription, QoS 1 and server logs.
Wrong device receives commandUnique usernames per branch and the selected target in the panel/API.
Input event missingInput wiring, input name configuration, event messages and the 30 ms stability filter.
API returns 404The device/group may be outside the key's assigned group scope; this is intentional isolation.