Skip to content

Inheritance

WeSpeakEnglish edited this page Sep 25, 2026 · 1 revision

Inheritance (inherits_from)

Many sensors share a protocol (e.g. the whole Plantower PMSx003 family). Instead of copying the full definition, a sensor can inherit from another one and override only what differs.

Basic example

{
  "name": "Your New Sensor PM2.5",
  "inherits_from": "Plantower PMSA003-S",
  "data": {
    "Humidity": {
      "value": "(data[14] << 8) + data[15]",
      "unit": "%"
    }
  }
}

This keeps everything from Plantower PMSA003-S and adds a Humidity signal.

A real example from sensors.json — the SenseAir S8 004-0-0017 reports CO₂ ×10, so it only overrides the CO2 formula:

{
  "name": "SenseAir S8 004-0-0017",
  "inherits_from": "SenseAir S8 004-0-0053",
  "data": {
    "CO2": { "value": "((data[3] << 8) + data[4])*10", "unit": "ppm" }
  }
}

Merge rules

Field How it is merged
command, start_command, stop_command, send_cmd_period Child value wins if present, otherwise parent's
port, frame, checksum Shallow merge: child keys replace parent keys, other parent keys are kept
data Shallow merge by signal name: a child signal with the same name replaces the parent's; new names are added
commands Merged by position — see Per-command override

Notes:

  • Inheritance can be chained (C → B → A). Circular chains are detected and ignored with a console warning.
  • If the parent name is not found, the sensor is used as-is and a warning is logged.
  • Signals can be added or replaced but not removed; if you need fewer signals, define the sensor without inheritance.

Per-command override

When the parent uses a commands array, the child can change individual commands without repeating the whole list. Put an id on the child command — the 0-based position in the parent's array.

{
  "name": "MySensor Fast",
  "inherits_from": "MySensor",
  "commands": [
    { "id": 1, "postDelay_ms": 100 }
  ]
}
  • Only listed fields are overridden; everything else in that command is inherited.
  • A child command without id, or with an out-of-range id, is appended after the inherited commands.
  • Parent commands do not need an id.

Clone this wiki locally