Skip to content

Architecture and internals

Tom-Bom-badil edited this page Sep 15, 2026 · 1 revision

This page is the developer-oriented technical reference for the SAMSON TROVIS 557x Home Assistant integration.

It explains how the Home Assistant integration, the trovis-modbus device library, modbus-connection, and the selected Modbus backend fit together; how a controller is discovered and represented; and where new functionality should be implemented.

Note

This page documents the integration boundary and Home Assistant architecture. Detailed TROVIS device-model internals are maintained in the trovis-modbus wiki so the same controller knowledge is not documented twice.


🧭 Architecture at a glance

The important boundaries in the following dependency chart are:

  • Home Assistant knows how devices and entities are presented and handled.
  • trovis-modbus-hass knows how TROVIS data become HA devices and entities.
  • trovis-modbus knows what each TROVIS register and coil means ("the data").
  • modbus-connection knows how Modbus access is abstracted and streamlined.
  • tmodbus knows how the actual Modbus communication is performed.

No Home Assistant entity should need to know a TROVIS register address, and no TROVIS datapoint should need to know whether Home Assistant is talking through Modbus TCP to a gateway, RTU over TCP, a remote serial proxy, or a directly attached serial device.

flowchart TD

    %%{init: {"themeCSS": ".edgeLabel, .edgeLabel p { font-size: 12px !important; line-height: 1.2 !important; background-color: transparent !important; } .labelBkg { background-color: transparent !important; } .edgeLabel rect { fill: transparent !important; opacity: 0 !important; }"}}%%

    HA["Home Assistant
    devices, entities, config entries"]

    HASS["trovis-modbus-hass
    TROVIS integration"]

    LIB["trovis-modbus
    TROVIS device library"]

    subgraph MC["modbus-connection"]

        MODEL["model framework"]

        UNIT["ModbusUnit
        backend-neutral API"]

        ADAPTER["tmodbus adapter modbus_connection.tmodbus"]

        MODEL --> UNIT
        ADAPTER --> UNIT

    end

    TM["tmodbus
    Modbus backend"]

    SERIALX["serialx
    serial transport"]

    TCPGW["Modbus TCP ↔ RTU gateway"]

    REMOTE["Remote serial bridge"]

    LOCAL["Local serial interface / adapter"]

    TROVIS["TROVIS controller
    (Modbus RTU)"]

    HA --> HASS

    HASS --> LIB
    LIB --> MODEL
    LIB --> UNIT

    HASS --> ADAPTER
    ADAPTER --> TM

    TM --> TCPGW
    TM --> SERIALX

    SERIALX --> REMOTE
    SERIALX --> LOCAL

    TCPGW -->|"Modbus RTU"| TROVIS
    REMOTE -->|"Modbus RTU"| TROVIS
    LOCAL -->|"Modbus RTU"| TROVIS
Loading



🧩 Project and dependency layers

trovis-modbus-hass

Repository:

https://github.com/Tom-Bom-badil/trovis-modbus-hass

This is the Home Assistant integration.

It owns:

  • the Home Assistant config flow,
  • connection settings stored in the TROVIS config entry,
  • creation and lifetime of the runtime Modbus connection,
  • controller probing during setup and reconfiguration,
  • Home Assistant devices and linked subdevices,
  • entity platforms,
  • translations,
  • the DataUpdateCoordinator,
  • entity availability,
  • the controller-specific entity-ID prefix,
  • the Home Assistant Write access safety switch,
  • mapping neutral library metadata to Home Assistant entity descriptions.

It should not own:

  • raw TROVIS register or coil definitions,
  • manufacturer-address conversion,
  • value scaling,
  • invalid-value handling,
  • controller-specific min/max limits,
  • enum values,
  • hydronic topology,
  • TROVIS-specific write sequences,
  • low-level Modbus protocol implementation.

trovis-modbus

Repository:

https://github.com/Tom-Bom-badil/trovis-modbus

This is the backend-neutral TROVIS device library and the authoritative source for controller-specific knowledge.

It owns:

  • supported SAMSON and compatible OEM controller profiles,
  • controller probing,
  • hydronic system definitions,
  • Rk roles and optional subsystems,
  • physical sensor/input definitions,
  • holding-register and coil definitions,
  • manufacturer-reference to zero-based Modbus/PDU address conversion,
  • model-specific readable ranges,
  • grouped-read planning constraints,
  • data types,
  • units,
  • scaling,
  • invalid/sentinel values,
  • neutral datapoint metadata,
  • enum options,
  • numeric limits and steps,
  • derived TROVIS values and states,
  • validated reads and writes,
  • TROVIS write-access handling,
  • controller-specific write preconditions.

It does not own:

  • Home Assistant devices,
  • Home Assistant entity IDs,
  • config entries,
  • Home Assistant translations,
  • physical connection creation,
  • a concrete Modbus backend.

The library receives a modbus_connection.ModbusUnit from its caller.

That dependency direction is intentional:

application
    │
    ├── creates a connection using any supported backend
    │
    └── passes ModbusUnit
              │
              ▼
         trovis-modbus

The same TROVIS model can therefore be used by Home Assistant, the command-line query tool, automated tests, or another application without changing the controller model.

modbus-connection

Repository:

https://github.com/home-assistant-libs/modbus-connection

Documentation:

https://home-assistant-libs.github.io/modbus-connection/

modbus-connection provides the common Modbus abstraction used between the device model and the backend.

Its most important concepts for this project are:

  • ModbusConnection
  • ModbusUnit
  • backend-neutral connection parameters
  • a common exception hierarchy
  • modbus_connection.model
  • typed register and coil fields
  • pooled/grouped read planning
  • an in-memory test backend

A physical Modbus connection can address multiple unit IDs. A ModbusUnit represents one selected unit on that connection:

unit = connection.for_unit(unit_id)
device = Trovis557x(unit, ...)

trovis-modbus only needs the resulting unit.

This is the key abstraction that keeps the TROVIS device model independent from tmodbus, pymodbus, TCP sockets, serial devices, and future Home Assistant connection helpers.

tmodbus

Home Assistant currently uses the tmodbus backend through modbus-connection.

tmodbus provides the actual asynchronous Modbus client implementation used at runtime by the integration.

It supports, among other transports relevant here:

  • Modbus TCP,
  • Modbus RTU over TCP,
  • Modbus RTU over serial.

Its asynchronous serial support uses serialx, which also makes remote serial targets possible.

The TROVIS library itself does not import or depend on tmodbus directly.

serialx

serialx is below the Modbus layer.

For this project it is relevant for:

  • locally attached serial interfaces,
  • remote serial targets,
  • socket://...,
  • esphome://....

The important distinction is that these remain serial Modbus RTU connections. Only the serial transport is remote.



🔀 Why modbus-connection is useful here

Tip

If you are adapting another Home Assistant Modbus integration, this is the reusable pattern to look for: keep the device model behind ModbusUnit, let the integration create the connection from backend-neutral parameters, and avoid teaching the device model about tmodbus, pymodbus, sockets, or serial transports.

TROVIS controllers are a good example of why a separate connection abstraction is valuable.

The project has to support different physical paths:

Modbus TCP to a TCP↔RTU gateway
RTU over TCP using the Network connection path
remote Modbus RTU through socket://
remote Modbus RTU through ESPHome
local Modbus RTU

The controller model should not contain branches such as:

if tcp:
    ...
elif socket_serial:
    ...
elif esphome:
    ...

Instead, all transport-specific work ends before the device model is constructed:

connection settings
        │
        ▼
concrete ModbusConnection
        │
        ▼
connection.for_unit(246)
        │
        ▼
ModbusUnit
        │
        ▼
Trovis557x

From that point onward, the TROVIS code sees the same interface for every transport.

This also makes the backend replaceable:

Consumer Concrete backend
Home Assistant integration tmodbus
trovis-modbus command-line query tool normally pymodbus
Library tests in-memory/mock ModbusUnit
Future consumers any implementation compatible with ModbusUnit

That split is deliberate. A change in the Home Assistant transport stack should not require changes to register definitions, hydronic configurations, or entity logic.




🧠 Library model boundary

The Home Assistant integration deliberately does not reproduce the TROVIS controller model internally.

trovis-modbus is responsible for resolving the controller-side structure, including controller profiles, hydronic system information, Rk roles, physical sensor/input assignments, available subsystems, datapoint metadata, and the rules required to read or write those datapoints safely.

The integration consumes that model and decides how it should appear in Home Assistant.

For integration development, the important rule is:

If a fact describes the TROVIS controller itself and would still be true in a command-line application without Home Assistant, it belongs in trovis-modbus.

The detailed model is documented in the library wiki:




🗺️ Where should a change be implemented?

Use this table before adding controller logic to the Home Assistant layer.

Change Correct project/layer
New TROVIS register or coil trovis-modbus
Address conversion rule trovis-modbus
New supported controller model trovis-modbus
Hydronic system / Rk role trovis-modbus
Sensor/input resolver trovis-modbus
Numeric range, step, scale or unit trovis-modbus
Enum values trovis-modbus
TROVIS write precondition trovis-modbus
Generic Modbus field type modbus-connection
Generic read-planning behavior modbus-connection
Generic Modbus exception model modbus-connection
tmodbus protocol/backend behavior tmodbus
Serial transport behavior serialx / backend
HA config-flow field trovis-modbus-hass
HA device or entity mapping trovis-modbus-hass
Entity availability/gating from library metadata trovis-modbus-hass
Translation trovis-modbus-hass
Coordinator behavior trovis-modbus-hass
HA write-access UI gate trovis-modbus-hass

A useful rule of thumb:

If the rule would still be true in a command-line application with no Home Assistant installed, it probably belongs in trovis-modbus.




📚 Technical deep dives

The overview above is deliberately kept short. Details live on one dedicated page per topic:

For the controller-side model itself, use the trovis-modbus wiki.

Useful modbus-connection references for developers moving another integration to the same architecture:



❤️ Design goal

The project should remain easy to reason about even as the Modbus transport architecture evolves.

The stable center is:

TROVIS knowledge
        │
        ▼
trovis-modbus
        │
        ▼
ModbusUnit

Everything below ModbusUnit may evolve with the Modbus ecosystem.

Everything above it may evolve with Home Assistant.

The controller model should not need to care about either.

german Wiki - Start english


english Bauanleitungen

Schritt 1 - Kabel

Schritt 2 - Adapter

Schritt 3 - Schnittstelle

Schritt 4 - Regler

Schritt 5 - Erster Test

🔥 Update: Weitere Adapter


english Home Assistant Integration

🚀 Getting started

🔌 Using the integration

🧑‍💻 Technical reference

🔢 Related projects


english SmartHomeNG Plugin


german2 Anhang: Info-Sammlung

Clone this wiki locally