Skip to content

Modules

Top-level package for hoymiles_modbus.

client

Hoymiles Modbus client.

HoymilesModbusTCP(host, port=502, unit_id=1)

Hoymiles Modbus TCP client.

Gather data from photovoltaic installation based on Hoymiles inverters managed by Hoymiles DTU (like DTU-pro). The client communicates with DTU via Modbus TCP protocol.

Initialize the object.

Parameters:

Name Type Description Default
host str

DTU address

required
port int

target DTU modbus TCP port

502
unit_id int

Modbus unit ID

1
Source code in hoymiles_modbus/client.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def __init__(self, host: str, port: int = 502, unit_id: int = 1) -> None:
    """Initialize the object.

    Arguments:
        host: DTU address
        port: target DTU modbus TCP port
        unit_id: Modbus unit ID

    """
    self._host: str = host
    self._port: int = port
    self._dtu_serial_number: str = ''
    self._unit_id = unit_id
    self._comm_params: 'CommunicationParams' = CommunicationParams()

comm_params: CommunicationParams property

Low level communication parameters.

dtu: str property

DTU serial number.

inverters: list[InverterData] property

Status data from all inverters.

Each get is a new request and data from the installation.

plant_data: PlantData property

Plant status data.

Each get is a new request and data from the installation.

datatypes

Data structures.

CommunicationParams(timeout=3, retries=3, reconnect_delay=0, reconnect_delay_max=300) dataclass

Low level pymodbus communication parameters.

reconnect_delay: float = 0 class-attribute instance-attribute

Minimum delay in seconds.milliseconds before reconnecting. Doubles automatically with each unsuccessful connect, from reconnect_delay to reconnect_delay_max.

Default is 0 which means that reconnecting is disabled.

reconnect_delay_max: float = 300 class-attribute instance-attribute

Maximum delay in seconds.milliseconds before reconnecting.

retries: int = 3 class-attribute instance-attribute

Max number of retries per request.

timeout: float = 3 class-attribute instance-attribute

Timeout for a connection request, in seconds.

InverterData

Bases: Structure

Inverter data structure.

alarm_code: int = member(fmt=uint16) class-attribute instance-attribute

Alarm code.

alarm_count: int = member(fmt=uint16) class-attribute instance-attribute

Alarm count.

grid_frequency: Decimal = member(fmt=_udec16p2) class-attribute instance-attribute

Grid frequency [Hz].

grid_voltage: Decimal = member(fmt=_udec16p1) class-attribute instance-attribute

Grid voltage [V].

Link status.

operating_status: int = member(fmt=uint16) class-attribute instance-attribute

Operating status.

port_number: int = member(fmt=uint8) class-attribute instance-attribute

Port number.

pv_current: Decimal = member(fmt=_pv_current_type, fmt_arg=serial_number) class-attribute instance-attribute

PV current [A].

pv_power: Decimal = member(fmt=_udec16p1) class-attribute instance-attribute

PV power [W].

pv_voltage: Decimal = member(fmt=_udec16p1) class-attribute instance-attribute

PV voltage [V].

serial_number: str = member(fmt=_serial_number_t) class-attribute instance-attribute

Inverter serial number.

temperature: Decimal = member(fmt=_sdec16p1) class-attribute instance-attribute

Inverter temperature [°C].

today_production: int = member(fmt=uint16) class-attribute instance-attribute

Today production [Wh].

total_production: int = member(fmt=uint32) class-attribute instance-attribute

Total production [Wh].

PlantData(dtu, pv_power=Decimal(0), today_production=0, total_production=0, alarm_flag=False, inverters=list()) dataclass

Data structure for the whole plant.

alarm_flag: bool = False class-attribute instance-attribute

Alarm indicator. True means that at least one inverter reported an alarm.

dtu: str instance-attribute

DTU serial number.

inverters: list[InverterData] = field(default_factory=list) class-attribute instance-attribute

Data for each inverter.

pv_power: Decimal = Decimal(0) class-attribute instance-attribute

Current production [W].

today_production: int = 0 class-attribute instance-attribute

Today production [Wh].

total_production: int = 0 class-attribute instance-attribute

Total production [Wh].