Skip to content

Conversation

@IacopoSb
Copy link

I'm opening this PR to address issue #15 and enable the retrieval of real-time data from Tigo inverters. Since these are instantaneous values, I've also added new global sensors specifically for this data, allowing seamless integration within the Home Assistant energy dashboard. This enhancement is particularly useful for users who rely solely on the data provided by the inverter.

At the moment, I am personally testing these changes on my own home system and verifying the results by comparing them with the data obtained from the official app. For this reason, is marked as draft.

@IacopoSb IacopoSb marked this pull request as ready for review August 19, 2025 08:30
Copy link
Owner

@MartinStoffel MartinStoffel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution. I made some suggestions. Since I do not have the hardware to test, I can only do some code review.

It would be nice, if you could share some images on how this looks like. E.g. in the read me.

"""Get the data from the web api."""
authHeader = await self._cookieCahe.getAuthHeader()
cookieJar = self._cookieCahe.getCookieJar()
now = datetime.now()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to move this closer to where it is first used. You never know when those async calls get to run or finish. So line 191 or so would be good.

Comment on lines +104 to +119
def _init_energy_accumulators(self):
self._energy_accumulators = {
"solar_energy": 0.0,
"home_energy": 0.0,
"grid_import": 0.0,
"grid_export": 0.0,
"battery_charge": 0.0,
"battery_discharge": 0.0,
}
self._last_update = None

def _integrate_energy(self, key, power, now):
if self._last_update is not None:
elapsed = (now - self._last_update).total_seconds() / 3600.0
self._energy_accumulators[key] += (power * elapsed)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this behave? I mean integrating with a sampling frequence of 1 minnute might not be very accurate.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is true, but it is conditioned by the API behavior of Tigo: on the free plan, data is updated every 15 minutes; with the pro plan, you have fresher data every minute. When using the "real-time" data sent by the inverter to the cloud, that is the maximum achievable. Even when using minute-by-minute graph data, these can only be retrieved after 5 minutes.

Comment on lines +93 to +134
"grid_import": {
"name": "Grid Import",
"native_unit_of_measurement": UnitOfEnergy.WATT_HOUR,
"device_class": SensorDeviceClass.ENERGY,
"state_class": SensorStateClass.TOTAL_INCREASING,
"attr_icon": "mdi:transmission-tower-import",
},
"grid_export": {
"name": "Grid Export",
"native_unit_of_measurement": UnitOfEnergy.WATT_HOUR,
"device_class": SensorDeviceClass.ENERGY,
"state_class": SensorStateClass.TOTAL_INCREASING,
"attr_icon": "mdi:transmission-tower-export",
},
"battery_charge": {
"name": "Battery Charge",
"native_unit_of_measurement": UnitOfEnergy.WATT_HOUR,
"device_class": SensorDeviceClass.ENERGY,
"state_class": SensorStateClass.TOTAL_INCREASING,
"attr_icon": "mdi:battery-arrow-up",
},
"battery_discharge": {
"name": "Battery Discharge",
"native_unit_of_measurement": UnitOfEnergy.WATT_HOUR,
"device_class": SensorDeviceClass.ENERGY,
"state_class": SensorStateClass.TOTAL_INCREASING,
"attr_icon": "mdi:battery-arrow-down",
},
"solar_energy": {
"name": "Solar Energy",
"native_unit_of_measurement": UnitOfEnergy.WATT_HOUR,
"device_class": SensorDeviceClass.ENERGY,
"state_class": SensorStateClass.TOTAL_INCREASING,
"attr_icon": "mdi:solar-power-variant-outline",
},
"home_energy": {
"name": "Home Energy",
"native_unit_of_measurement": UnitOfEnergy.WATT_HOUR,
"device_class": SensorDeviceClass.ENERGY,
"state_class": SensorStateClass.TOTAL_INCREASING,
"attr_icon": "mdi:home-lightning-bolt-outline",
},
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would handle vlues which do not come directly from the sensor differently. Here you integrate them home assistant has features to do this. I suggest using them. See: https://www.home-assistant.io/docs/energy/individual-devices/#devices-with-power-w-sensors

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know about hierarchies in HA, i'll update the code according to the post linked

Comment on lines 298 to +300
def get_data(self) -> any:
"""Get the whole reaging data."""
return self.htigo_data.get_data()
return self.tigo_data.get_data()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function can be removed, due to the ?typo? it never worked anyways... my bad

Comment on lines +261 to +263
def get_data(self) -> dict:
return self._data

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed, if lines 298ff are also removed.

Nothing is currenty using this

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants