Skip to content

Modules

Top-level package for hoymiles_modbus.

client

Hoymiles Modbus client.

CommunicationParams dataclass

Low level pymodbus communication parameters.

close_comm_on_error: bool = False class-attribute

Close connection on error

reconnect_delay: int = 60000 * 5 class-attribute

Delay in milliseconds before reconnecting.

retries: int = 3 class-attribute

Max number of retries per request.

retry_on_empty: bool = False class-attribute

Retry if received an empty response.

strict: bool = True class-attribute

Strict timing, 1.5 character between requests.

timeout: int = 3 class-attribute

Request timeout.

HoymilesModbusTCP(host, port=502, microinverter_type=MicroinverterType.MI, unit_id=1)

Hoymiles Modbus TCP client.

Gather data from photovoltaic installation based on Hoymiles microinverters 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
microinverter_type MicroinverterType

Microinverter type, applies to all microinverters

MicroinverterType.MI
unit_id int

Modbus unit ID

1
Source code in hoymiles_modbus/client.py
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
def __init__(
    self, host: str, port: int = 502, microinverter_type: MicroinverterType = MicroinverterType.MI, unit_id: int = 1
) -> None:
    """Initialize the object.

    Arguments:
        host: DTU address
        port: target DTU modbus TCP port
        microinverter_type: Microinverter type, applies to all microinverters
        unit_id: Modbus unit ID

    """
    self._host: str = host
    self._port: int = port
    self._dtu_serial_number: str = ''
    self._microinverter_data_struct: Type[Union[MISeriesMicroinverterData, HMSeriesMicroinverterData]]
    if microinverter_type == MicroinverterType.MI:
        self._microinverter_data_struct = MISeriesMicroinverterData
    elif microinverter_type == MicroinverterType.HM:
        self._microinverter_data_struct = HMSeriesMicroinverterData
    else:
        raise ValueError('Unsupported microinverter type:', microinverter_type)
    self._unit_id = unit_id
    self._comm_params: CommunicationParams = CommunicationParams()

comm_params: CommunicationParams property

Low level communication parameters.

dtu: str property

DTU serial number.

microinverter_data: List[Union[MISeriesMicroinverterData, HMSeriesMicroinverterData]] property

Status data from all microinverters.

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.

HMSeriesMicroinverterData

Bases: MISeriesMicroinverterData

HM series microinverter status data structure.

MISeriesMicroinverterData

Bases: Structure

MI series microinverter status data structure.

MicroinverterType

Bases: Enum

Microinverter type.

HM = auto() class-attribute

HM series.

MI = auto() class-attribute

MI series.

PlantData dataclass

Data structure for the whole plant.

alarm_flag: bool = False class-attribute

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

dtu: str class-attribute

DTU serial number.

microinverter_data: List[Union[MISeriesMicroinverterData, HMSeriesMicroinverterData]] = field(default_factory=list) class-attribute

Data for each microinverter.

pv_power: Decimal = Decimal(0) class-attribute

Current production [W].

today_production: int = 0 class-attribute

Today production [Wh].

total_production: int = 0 class-attribute

Total production [Wh].