Skip to content

Implement Powermeter TQ EM#150

Merged
tomquist merged 3 commits into
mainfrom
implement-powermeter-using-api
Jun 26, 2025
Merged

Implement Powermeter TQ EM#150
tomquist merged 3 commits into
mainfrom
implement-powermeter-using-api

Conversation

@tomquist
Copy link
Copy Markdown
Owner

@tomquist tomquist commented Jun 26, 2025

Summary

  • Implemented a new TQEMPowermeter to interact with the TQ Energy Manager JSON API, supporting optional authentication and power calculation
  • Documented the TQ Energy Manager configuration in the README, including setup instructions
  • Added configuration example for TQ_EM in the sample config file
  • Updated the configuration loader to create TQ_EM powermeter instances based on the new section

Testing

  • pytest -q

Fixes #133

@tomquist tomquist changed the title Add test and fix TQ_EM docs Implement Powermeter TQ EM Jun 26, 2025
@tomquist tomquist merged commit fe578a0 into main Jun 26, 2025
15 checks passed
@tomquist tomquist deleted the implement-powermeter-using-api branch June 26, 2025 22:23
@TheItschi
Copy link
Copy Markdown

TheItschi commented Jun 27, 2025

Code is much nicer but returns wrong value(s) ;-)

The power is always reported in two different values (e.g. one for the power coming from the grid and one for the power that is fed to the grid). To get a signed total you need to calculate the value by subtracting the power that is fed to the grid from the power that is drawn from the grid. At least one of those values will always be zero. Note sure why you extract the phase power as well, but you would need to calculate the total phase power accordingly.

"tq_tm.py" needs to be changed as follows:

    # OBIS codes
    _TOTAL_TO_GRID = 0
    _TOTAL_FROM_GRID = 1

    _TOTAL_KEYS = (
        "1-0:1.4.0*255",   # Σ active power (from grid) 
        "1-0:2.4.0*255",   # Σ active power (to grid)
    )

    _TOTAL_TO_GRID_L1 = 0
    _TOTAL_FROM_GRID_L1 = 1
    _TOTAL_TO_GRID_L2 = 2
    _TOTAL_FROM_GRID_L2 = 3
    _TOTAL_TO_GRID_L3 = 4
    _TOTAL_FROM_GRID_L3 = 5

    _PHASE_KEYS = (
        "1-0:21.4.0*255",  # L1 active power (from grid)
        "1-0:22.4.0*255",  # L1 active power (to grid)
        "1-0:41.4.0*255",  # L2..
        "1-0:42.4.0*255",
        "1-0:61.4.0*255",  # L3..
        "1-0:62.4.0*255"
    )

...

    def get_powermeter_watts(self) -> List[float]:
        self._ensure_session()

        try:
            data = self._read_live_json()
        except _SessionExpired:
            self._login()
            data = self._read_live_json()

        if len([element for element in self._TOTAL_KEYS if element in data]) == len(self._TOTAL_KEYS):
            return [float(data[self._TOTAL_KEYS[self._TOTAL_TO_GRID]])-float(data[self._TOTAL_KEYS[self._TOTAL_FROM_GRID]])]
        else:
            raise RuntimeError("Required OBIS values missing in payload")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fail to read B-Control Modbus Power Meter EM300

2 participants