Skip to content
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

Add IQ Storage power (charge/discharge) and correct consumption #55

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

isottipietro
Copy link

@isottipietro isottipietro commented Mar 21, 2023

Added the endpoint exposing ensemble power, sensors of battery charge/discharge and correct consumption (based on battery power). Hope it's useful

@DigitalBites
Copy link

DigitalBites commented Apr 5, 2023

I attempted to use this pull request however it doesn't seem to be providing the battery data correctly. I am getting "Unknown" for the Battery Power Charge and Battery Power Discharge.

The rest of the metrics come back ok. it appears there is a call that is not authorized.

2023-04-04 16:59:44.328 DEBUG (MainThread) [custom_components.enphase_envoy_custom.envoy_reader] Fetched from https://xxxx/ivp/ensemble/power: <Response [401 Unauthorized]>: <html>
<head><title>401 Authorization Required</title></head>
<body>
<center><h1>401 Authorization Required</h1></center>
<hr><center>Redirecting to <a id='link' href=''></a></center>
<script>
const redirect_url = window.location.protocol + '//' + window.location.host + '/home';
function redirect() { window.location.href = redirect_url; }
window.onload = function() {
    const link = document.getElementById('link');
    link.href = redirect_url;
    link.text = redirect_url;
    setTimeout(redirect, 500);
}
</script>
</body>
</html>

@catsmanac
Copy link
Collaborator

catsmanac commented Apr 14, 2023

I tested this one by installing from @isottipietro but got an error. Am I doing something wrong?

2023-04-14 22:13:59.844 ERROR (MainThread) [custom_components.enphase_envoy] Unexpected error fetching envoy Envoy 122302045041 data: local variable 'grid' referenced before assignment
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 250, in _async_refresh
    self.data = await self._async_update_data()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 206, in _async_update_data
    return await self.update_method()
  File "/config/custom_components/enphase_envoy/__init__.py", line 71, in async_update_data
    data[description.key] = await getattr(
  File "/config/custom_components/enphase_envoy/envoy_reader.py", line 571, in grid_import
    self.grid_power = int(grid)
UnboundLocalError: local variable 'grid' referenced before assignment

Using ENVOY_S EU version, not metered

@Hoffmann77
Copy link

Hey @catsmanac,
it looks like an error in the added code. Probably missing indentations on lines 552 to 562 and lines 571 to 575.

Even with that error fixed the original code doesn't seem to correctly detect your Envoy-Model-S non metered. It detects an Envoy-Model-C which probably doesn't support this endpoint.

Just to confirm for further development you are running an ENVOY_S EU version, not metered with Encharge Batteries?

@catsmanac
Copy link
Collaborator

catsmanac commented Jun 20, 2023

Hey @catsmanac, it looks like an error in the added code. Probably missing indentations on lines 552 to 562 and lines 571 to 575.

Even with that error fixed the original code doesn't seem to correctly detect your Envoy-Model-S non metered. It detects an Envoy-Model-C which probably doesn't support this endpoint.

Just to confirm for further development you are running an ENVOY_S EU version, not metered with Encharge Batteries?

I'm using ENVOY_S EU Version, no meters, no batteries, just solar panels. It determines that as model P (ENVOY_MODEL_C) because it does not have production and consumption (has_production_and_consumption) and will report 200 to endpoint_production_v1_results.

        if (
            self.endpoint_production_json_results
            and self.endpoint_production_json_results.status_code == 200
            and has_production_and_consumption(
                self.endpoint_production_json_results.json()
            )
        ):
            self.isMeteringEnabled = has_metering_setup(
                self.endpoint_production_json_results.json()
            )
            if not self.isMeteringEnabled:
                await self._update_from_p_endpoint()
            self.endpoint_type = ENVOY_MODEL_S
            return

        try:
            await self._update_from_p_endpoint()
        except httpx.HTTPError:
            pass
        if (
            self.endpoint_production_v1_results
            and self.endpoint_production_v1_results.status_code == 200
        ):
            self.endpoint_type = ENVOY_MODEL_C  # Envoy-C, production only <---------
            return

Fetched from https://192.168.3.112/api/v1/production: <Response [200 OK]>: {
  "wattHoursToday": 46523,
  "wattHoursSevenDays": 204481,
  "wattHoursLifetime": 2330695,
  "wattsNow": 0
}

I see what you mean by the indentation issue, thanks! I'll give it a try later to confirm compatibility with my plain vanilla envoy-s.

@bassrock
Copy link

Just got IQ Enphase Batteries installed and was looking just for this, would be happy to test if needed.

@catsmanac
Copy link
Collaborator

The current version V0.0.17 has battery support as well as import/export values. It obtains the data from different pages as this one, but it may provide what you are looking for?

@catsmanac
Copy link
Collaborator

Looking at this PR it seems to replace battery energy charge/discharge by battery power charge and discharge. Adding the latter is probably useful, but removing the energy charge/discharge probably not as I guess these are drivers for the battery storage of the energy dashboard.

@Underlyingglitch
Copy link

@catsmanac I know it has been a while, but you make a good point. Currently there are entities for charge/discharge that provide the data for the energy dashboard (Wh), but no entities for the power usage (W) which could be useful in realtime overviews.

Any updates on this? I'd be more than happy to contribute/test

I have the EU version of the gateway metered (version 8), IQ8+ inverters and 2 batteries (5P)

@catsmanac
Copy link
Collaborator

That's a while back indeed. Adding battery power is probably a small thing. If I recall correctly this PR had more impacting changes for which I didn't felt qualified to decide on then.

@isottipietro
Copy link
Author

Looking at this PR it seems to replace battery energy charge/discharge by battery power charge and discharge. Adding the latter is probably useful, but removing the energy charge/discharge probably not as I guess these are drivers for the battery storage of the energy dashboard.

I use the power from the batteries because is useful to know how much power is draining or chargeing, then i calculate the energy with the integration template to have both. I'm going to write a new PR to only add power from battery without removing the energy

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.

6 participants