-
Notifications
You must be signed in to change notification settings - Fork 6
feat: added inverter data #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
MartinStoffel
left a comment
There was a problem hiding this 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() |
There was a problem hiding this comment.
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.
| 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) | ||
|
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| "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", | ||
| }, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
| def get_data(self) -> any: | ||
| """Get the whole reaging data.""" | ||
| return self.htigo_data.get_data() | ||
| return self.tigo_data.get_data() |
There was a problem hiding this comment.
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
| def get_data(self) -> dict: | ||
| return self._data | ||
|
|
There was a problem hiding this comment.
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
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.