Adding a device
The hub speaks Home Assistant MQTT discovery. It holds no per-device code. Each device reaches the hub as discovery configs on the MQTT broker, and each discovered component becomes an entity of a Kind. MQTT discovery is the plugin API, so adding a device usually means changing whatever publishes its discovery, not the hub.
Which path?
| Situation | Path | Where the change goes |
|---|---|---|
| A Zigbee device Zigbee2MQTT does not know | Fix it in Zigbee2MQTT | External converter, then upstream PR. Not a Nidoo change. |
| The device is not Zigbee (cloud API, Wi-Fi, vendor protocol) | Write a bridge | Separate process, any language, own repo. It publishes discovery to the broker. |
The device publishes discovery for a component Nidoo does not read (the config is on the broker, but no entity appears and GET /api/v1/ignored does not list it) | Add a type or a kind | Usually a JSON entry in crates/nidoo-core/src/types/table.json. A Rust kind only when the table cannot describe it. PR to Nidoo, one per component, never per device. |
| The device is a type Nidoo describes but reports no state for the primary field | Type table | Bridge or firmware: publish the state topic of the primary field, retained. A requires_state type is rejected without it. |
| The device works but looks wrong (wrong room, wrong name, a relay that is really a heater or light) | Override | No code. Web device sheet, PATCH /api/v1/entities/{id}/override, or MCP set_override. |
Some firmwares already publish discovery when their MQTT discovery option is on, Tasmota, ESPHome and Valetudo among them. Those devices need no bridge.
Zigbee devices unknown to Zigbee2MQTT
Zigbee2MQTT (Z2M) holds the per-device code for thousands of Zigbee devices. When Z2M does not know a device:
- Write an external converter for local use. It is a JavaScript file referenced in Z2M's configuration.
- Contribute it upstream to
Koenkk/zigbee-herdsman-convertersso every user gets it.
Z2M publishes discovery under the nidoo prefix. Once Z2M exposes the device, Nidoo picks it up with no change. See Zigbee2MQTT.
Writing a bridge
A bridge is a separate process. It reads a non-Zigbee device and publishes that device's discovery and state to the MQTT broker. The bridge can be written in any language and lives in its own repository. The hub needs no change.
The contract
Discovery topic:
<prefix>/<component>/[<node_id>/]<object_id>/config
Between the component and config there is one or two segments. None may be empty. The default prefix is nidoo.
A bridge that publishes under homeassistant works once the hub lists that prefix: add "homeassistant" to topics.discovery_prefixes in the advanced section (["nidoo", "homeassistant"]), with PUT /api/v1/settings/advanced or the set_settings MCP tool. See the Settings reference.
Rules:
- Publish the config retained, as a UTF-8 JSON object.
- The hub expands Home Assistant abbreviations (
stat_t,cmd_t,dev,~, and so on). - Device-based discovery is supported: component
devicewith acmpsorcomponentsmap, one entry per entity, each with aplatform. - Remove an entity by publishing an empty retained payload on its config topic.
ui,automation,virtualandpushdirectly under the prefix are reserved.nidoo/ui/<id>holds overrides,nidoo/automation/<id>holds flows,nidoo/virtual/<id>the state of virtual entities andnidoo/push/...the push topics. Never publish discovery there. See MQTT topics.
Hand-written kinds (each becomes an entity):
light, switch, cover, climate, sensor, binary_sensor, alarm_control_panel, number, select, button, vacuum, water_heater, media_player.
Type-table components (each becomes an entity from its table entry, no Rust needed):
camera, device_automation, device_tracker, event, fan, humidifier, image, lawn_mower, lock, notify, scene, siren, tag, text, update, valve.
The hub does not read any other component. Its config topic is not treated as discovery, so it shows neither as an entity nor under GET /api/v1/ignored.
Fields the hub reads
| Field | What the hub does with it |
|---|---|
unique_id | The entity id. Set it and keep it stable. Without it the hub uses <component>.<node_id>.<object_id>. |
device.identifiers | The first string is the entity's device_id. Entities sharing it form one device. |
device.name | The device part of the display name. |
name | The entity label. null makes the entity the device itself, named after the device. |
device.suggested_area | The room. |
state_topic | Required for sensor and binary_sensor. The config is rejected without it. Publish state retained so the hub has a value after a restart. |
availability_topic | Online and offline payloads come from payload_available and payload_not_available (defaults online and offline). |
availability | A list of topics, combined by availability_mode (all, any or latest). |
entity_category | diagnostic or config hides the entity from the default entity list. |
enabled_by_default | false hides the entity from the default entity list. |
device_class, unit_of_measurement, icon | Passed through to the UI. |
Display name: <device name> <label>. A device.name with three or more / segments, such as rooms/kitchen/kettle, gives the short name kettle and the room kitchen.
Room priority: user override, then suggested_area, then the room from the / path, then Unassigned.
Without an availability topic, availability stays unknown. Pair availability_topic with an MQTT last will so the hub shows the device offline when the bridge dies.
Worked example: Roborock2Mqtt
Roborock2Mqtt (https://github.com/Gekkotron/Roborock2Mqtt) talks to an S5 vacuum and publishes this config (as the hub stores it):
{
"unique_id": "roborock_40313ca8b964",
"object_id": "roborock_40313ca8b964",
"name": null,
"device": {
"identifiers": ["roborock_40313ca8b964"],
"manufacturer": "Roborock",
"model": "roborock.vacuum.s5",
"name": "Roborock",
"sw_version": "3.5.8_002034"
},
"availability_topic": "roborock/alive",
"payload_available": "1",
"payload_not_available": "0",
"state_topic": "roborock/ha/state",
"command_topic": "roborock/ha/command",
"set_fan_speed_topic": "roborock/ha/fan_speed/set",
"fan_speed_list": ["Silent", "Standard", "Medium", "Turbo", "Gentle", "Auto"],
"supported_features": ["start", "pause", "stop", "return_home", "locate", "fan_speed", "battery", "status"]
}
name: nullmakes the entity "Roborock".supported_featuresandfan_speed_listtell the hub which actions and fan speeds exist.roborock/alivewith1and0drives online and offline.- The hub has no Roborock code.
Vacuum wire format:
state_topiccarries JSON{"state", "battery_level", "fan_speed"}.stateis one ofcleaning,docked,paused,idle,returning,error.- Commands are published on
command_topicasstart,pause,stop,return_to_baseorlocate. Each payload can be overridden (payload_startand so on). - A fan speed is published as the plain speed name on
set_fan_speed_topic.
A second example is Suez2Mqtt (https://github.com/Gekkotron/Suez2Mqtt). It reads a water meter from the Suez cloud and publishes sensor entities with device_class: water. It publishes no availability topic, so its availability shows unknown.
A device whose firmware already speaks MQTT but publishes no discovery needs no bridge at all: publish its discovery once, retained, by hand. WaterHeaterController (https://github.com/Gekkotron/WaterHeaterController) works this way; WaterHeaterController holds its one-line mosquitto_pub. Its water_heater entity derives everything from the firmware's water-heater/data JSON with templates: the tank temperature, a mode of heat or off, and the card attributes below.
Water heater card attributes, read from json_attributes_topic (after json_attributes_template) when present:
power: the heating power, 0 to 100 %. The card shows "Heating · N %" when it is above 0 and "Idle" otherwise.inlet_temperature: the cold-water inlet in °C, shown under the tank temperature.
Without them the card falls back to the mode. The target stepper appears only with a target temperature, and the mode picker only with modes.
Restarts
With mqtt.send_ha_birth on (off by default; set it in the mqtt object of data/hub.json while the hub is stopped, or with NIDOO_MQTT__SEND_HA_BIRTH=true), the hub publishes online (not retained) on mqtt.ha_status_topic (default homeassistant/status) each time it connects. A bridge subscribes to that topic and re-publishes its discovery and state when it sees online.
Retained configs cover most restarts. The birth message covers a broker that lost its retained messages.
Checking it
GET /api/v1/ignored: every discovery topic of a known component that did not become an entity, with the reason (bad JSON,sensor without state_topic, a table type without its state topic, and so on).- A config that shows in neither list uses a component Nidoo does not read. Confirm it is on the broker with
mosquitto_sub -v -t 'nidoo/<component>/#', then see Adding a component kind to Nidoo. GET /api/v1/snapshot: the entity underentities, with state and availability. The snapshot'sdeviceslist holds Zigbee2MQTT devices only. A bridge's device appears through its entities'device_id.- MCP
get_entity: the entity with itsbindings(the expanded discovery config). Use it to confirm abbreviations expanded as expected.
Security: bindings are readable by anything on the LAN. Never put credentials in topics or templates.
Adding a component kind to Nidoo
Two routes. Most components need only a type-table entry. Write a Rust kind only when the component needs behaviour the table cannot express: a new state model, a command mapping of its own, or energy reporting.
A type-table entry (JSON, no Rust)
Find or add the entry in crates/nidoo-core/src/types/table.json (the covered components are listed in Entity types). Entries sit under the top-level types object, keyed by component name, inside a file shaped {"version": 1, "types": {"<component>": {...}}}:
| Key | Meaning |
|---|---|
placement | Where the entity shows: card (Home), signal (a trigger for flows), target (something flows can send to) or update (a firmware mark). |
icon | A glyph name for the card. |
primary | The field name shown on the card, or null. |
requires_state | When true, discovery is rejected without the primary field's topic. |
fields | A map of field_name to { shape, topic, template?, values?, options?, range?, on? }. shape is on_off, number, choice, text, picture or version. topic is the config key holding the state topic, template the config key holding its value template. values lists the allowed values, each with the config key that may override its payload and the Home Assistant default. options names a list in the config (such as preset_modes). range is {min, max, step}, the defaults, plus optional min_key, max_key and step_key naming config keys that override them. on is the value that counts as on. json_path, for a text or version shape, reads one top-level key when the rendered template produces a JSON object. |
controls | A map of control_name to { shape, topic, template?, field?, press?, payload?, payload_on?, payload_off?, json_key?, requires?, labels? }. topic is the config key of the command topic. press: true makes a button, which has no state. payload is a WordDef {value, default}, which may also carry an optional key as the other WordDefs do. field ties the control to a field it changes. json_key sends {"<json_key>": value} instead of the bare value. requires names a config key that must be present for the control to be announced. labels is {on, off}, the card's button words for an on_off control. |
main | The default main control, in preference order. |
alerts | [{field, any_of}]: field values that put the card in alert style. |
history | {field, map}. map turns the field's text values into numbers, such as {"on": 1.0, "off": 0.0}. An empty map keeps a number as it is. |
A short example, the device_tracker entry:
"device_tracker": {
"placement": "card",
"icon": "tracker",
"primary": "state",
"requires_state": true,
"fields": {
"state": {
"shape": "choice",
"topic": "state_topic",
"template": "value_template",
"values": [
{"value": "home", "key": "payload_home", "default": "home"},
{"value": "not_home", "key": "payload_not_home", "default": "not_home"}
]
}
},
"history": {"field": "state", "map": {"home": 1.0, "not_home": 0.0}}
}
The hub publishes the whole table retained on nidoo/ui/_types ({ui_prefix}/_types) on every connection, so the Android app reads the same vocabulary. Its own echo is ignored. Camera and image entities carry their picture in the picture field. GET /api/v1/entities/{id}/picture serves the stored bytes, or the bytes of its URL fetched by the hub now (10 s timeout, 5 MiB cap, no redirects followed).
A card entry shows on Home as the generic card (crates/nidoo-web/src/cards/generic.rs), which draws its primary field and a button or input per announced control; lock is the one table type with a card of its own. signal, target and update entries do not show on Home. In the web UI:
iconis a name, not a drawing. Map it to a glyph ingeneric_icon(crates/nidoo-web/src/icons.rs); an unmapped name draws the sensor glyph.- A field name reads as its words, capitalised (
battery_levelshows as "Battery level"). Add an English and French label tofield_label(crates/nidoo-web/src/i18n/flows.rs) when that reads badly.
A type-table entry needs no other change to appear in the flow editor: nidoo_core::vocabulary turns its announced controls into actions and its primary field into the values an if card offers.
Check it:
cargo test -p nidoo-core types:every_reference_in_the_table_resolvesfails whenprimary,main,history, an alert or a control'sfieldnames something the entry does not define, or apresscontrol has nopayload.- On a hub,
GET /api/v1/snapshotmust list the entity with its primary field, andGET /api/v1/ignoredmust not list its topic. Arequires_stateentry whose config lacks the primary field's topic is listed there with the reason.
A hand-written kind (Rust)
Base the PR on how media_player, the newest kind, was added: commits 2de8cffb (kind and state), ed6f1612 (commands, capabilities, flow fields) and 1727041b (web card). A hand-written kind wins over a table entry of the same name, so delete the component's entry from table.json if it has one.
Start with the Kind variant: the compiler then points at most of the other places. cargo check --workspace --all-targets and cargo check -p nidoo-web --target wasm32-unknown-unknown list every match on Kind that no longer covers all the variants. Some matches end in _ => and stay silent; search for Kind::MediaPlayer to find them all.
Core (crates/nidoo-core):
| File | Change |
|---|---|
src/model/kind.rs | The Kind variant, its component name in Kind::component, and the variant in Kind::ALL. |
src/discovery/capabilities.rs | What the kind can do, read from the config. |
src/model/state.rs, src/state/kinds/<kind>.rs, src/state/kinds/mod.rs | The kind's state model and how its state topics are read. |
src/model/command.rs, src/command/kinds.rs | New command variants, if any, and how each command becomes a publish. src/command/echo.rs only when the device's echo does not match the command (the media player's does not). |
src/flow/scalar.rs, src/flow/field.rs | The kind's main value and its other fields, as flows and if cards read them. |
src/vocabulary.rs | What the kind accepts (actions) and reports (reports): the flow editor's Action and Value lists and the ambiance device action read them. |
src/history/mod.rs | How the state is recorded, if it is not a single number or on/off. |
src/dashboard/model.rs | A WidgetKind and its allowed sizes, if the kind gets a dashboard card. |
src/energy/units.rs | Only if the kind reports energy. |
Hub, API and assistant:
| File | Change |
|---|---|
crates/nidoo-api/src/search.rs | The words that find the kind in search (kind_words), in English and French. |
crates/nidoo/src/groups/discovery.rs, groups/state.rs, groups/topics.rs | Whether entities of the kind can be grouped, and how a group's state is combined. A kind that cannot be grouped is listed with the others that cannot. |
crates/nidoo/src/dashboards/store.rs | Which widget config the new WidgetKind accepts. |
crates/nidoo-assist/src/plan.rs | Only for voice phrases of its own (the media player has music phrases). |
Web (crates/nidoo-web):
| File | Change |
|---|---|
src/cards/<kind>.rs, src/cards/mod.rs | The card. |
src/screens/home.rs | card_for picks the card for the kind (and a group card if the kind can be grouped). |
src/icons.rs, src/format.rs | The kind's glyph (kind_icon) and how its state reads as text. |
src/i18n/states.rs, src/i18n/groups.rs, src/i18n/devices.rs | The kind's name, its state words and its count ("2 chauffe-eau"), in English and French. |
src/flow_text.rs, src/if_value.rs | Which state words the flow editor uses for the kind. |
src/dashboards/library.rs, src/dashboards/widget.rs | The kind's section in the card library and the card a dashboard draws for it. |
src/screens/group_wizard.rs | Whether the group wizard offers the kind. |
styles/cards.css | The card's styles. |
Every word a person reads goes through the FR/EN table in src/i18n/, never a bare literal in a view. tests/bare_text.rs fails on a bare literal; a literal that is not a word (a class, a key name, a code shown as code) goes in tests/bare_text_allow.txt with a comment. Run cargo test -p nidoo-web (not only --lib) to include that check.
The Android app (Nidoo-app) needs the matching card.
Tests:
crates/nidoo-core/tests/discovery.rs: a config of the new component becomes an entity of the kind.crates/nidoo-core/tests/state.rs: state messages, against the recorded broker messages incrates/nidoo-core/tests/fixtures.crates/nidoo-core/tests/command.rs: each command's publish.crates/nidoo-core/tests/vocabulary.rsruns every actionvocabulary::actionslists through the command mapper, so the editors never offer a command the hub refuses; add a hand-written config there when the recording has no entity of the new kind.crates/nidoo-web/tests/rich_cards.rs: a headless-browser test of the card. Run that one file, not the whole set: see Development.
Before opening the PR, run the commands in Development: cargo test, clippy -D warnings, fmt --check, and the wasm32 checks for nidoo-core, nidoo-api and nidoo-web.
Overrides
The override has twenty-one fields (name, area, hidden, order, cardStyle, favorite, energyRole, energyInvert, securityHidden, energyIcon, energyMeter, homePinned, securityAction, securityAsk, ungrouped, showAs, lightOnPreset, lightOnBrightness, climatePresets, mainControl, invert). showAs makes a switch show as a light, door, siren, chime, plug or TV; mainControl is the name of an announced control, or "none" to hide the main control; invert swaps on and off for a switch wired the other way round. Entity types lists every field with its values.
Overrides are retained messages under nidoo/ui/<entity id>. Set them from the web device sheet, PATCH /api/v1/entities/{id}/override, or MCP set_override.
Virtual entities
A virtual entity (see also Groups and virtual entities) is a switch, a number or a button the hub owns, with no device behind it: a "force heating" flag, a setpoint, a manual trigger for a flow. Create one with PUT /api/v1/virtual/{id} (body {"kind": "switch" | "number" | "button", "name": "…"}, plus min, max, step, unit for a number and initial for either state) or MCP set_virtual; remove it with DELETE /api/v1/virtual/{id} or delete_virtual. The id is 1 to 48 characters of a-z, 0-9 and _, and the entity becomes virtual_<id>, on the device Virtual.
Under the first discovery prefix P (normally nidoo), the hub publishes, retained:
| What | Topic |
|---|---|
| Config | P/<switch|number|button>/virtual/<id>/config |
| State and command (switch, number) | P/virtual/<id> |
| Command (button) | P/virtual/<id> |
A switch (ON / OFF) and a number echo on their own topic and are retained (retain: true in the config), so a command is its own state and survives a restart. A number takes min, max and step (0, 100 and 1 by default). A button has no state and is not retained: a press is an event, not a value.
The hub publishes the initial state, retained, only the first time the entity is created: OFF for a switch, min for a number, or initial. A flow's trigger needs a known previous value to see a change, so a first tap would otherwise go unnoticed. Calling PUT again on an existing entity republishes its config (a rename, other bounds) and keeps its state. virtual is a reserved sub-tree: its topics never show in GET /api/v1/ignored.
A virtual entity is an ordinary entity otherwise: commands go through send_command, and it moves to a room with the usual override (PATCH /api/v1/entities/virtual_<id>/override, or the web device sheet).
Bridge catalogue
| Bridge | Devices | Repo |
|---|---|---|
| Suez2Mqtt | Suez water meter (cloud) | https://github.com/Gekkotron/Suez2Mqtt |
| Roborock2Mqtt | Roborock vacuums (S5 tested) | https://github.com/Gekkotron/Roborock2Mqtt |
To list a bridge, open a PR that adds one row. The bridge's code stays in its own repository.