energomera_hass_mqtt.iec_hass_sensor

Package provide single HASS sensor over MQTT from energy meter read using IEC protocol.

Classes

IecToHassSensor(mqtt_config, mqtt_client, ...)

Processes entity received from the meter IEC 62056-21 protocol in accordance with given configuration from the parameters section and sends them over to HomeAssistant using MQTT.

class energomera_hass_mqtt.iec_hass_sensor.IecToHassSensor(mqtt_config, mqtt_client, config_param, iec_item, model, sw_version, serial_number)

Bases: object

Processes entity received from the meter IEC 62056-21 protocol in accordance with given configuration from the parameters section and sends them over to HomeAssistant using MQTT.

Parameters:
  • mqtt_config (ConfigMqttSchema) – mqtt fragment of the configuration

  • mqtt_client (MqttClient) – Instance of MQTT client

  • config_param (ConfigParameterSchema) – particular entry from parameters configuration section

  • iec_item (List[DataSet]) – Entry received from the meter for the specified config_param

property state_last_will_payload: str | None

Stores value of last will payload to be set for MQTT client.

Should be implemented by subclasses.

property iec_item: List[DataSet]

Provides IEC entity associated with the instance.

Returns:

IEC entity

iec_try_value_by_index()

Attempts to pick an item from multi-valued meter’s response (if response_idx is configured in the entry of parameters section being processed).

Return type:

None

hass_gen_hass_sensor_props(idx)

Generates various properties for the HASS sensor (device and unique IDs, MQTT topic names etc.).

Return type:

None

hass_config_payload()

Returns HASS config payload for the item.

Return type:

Dict[str, str | Collection[str] | Dict[str, str]]

Returns:

HASS config payload

hass_state_payload(value)

Returns HASS state payload for the item.

Return type:

Dict[str, str]

Returns:

HASS state payload

async process(setup_only=False)

Processes the entry received from the meter and sends it to HASS over MQTT.

Parameters:

setup_only (bool) – Perform only setup steps for the entiry, such as determining MQTT topics etc., with no payloads sent to MQTT. Used to configure MQTT last will, since it has to be done prior to connecting to MQTT broker, thus no payloads could be sent yet

Return type:

None