PG&E Energy Monitoring Integration

For any utility other than PG&E you are on your own.

PG&E redirects to: https://itiamping.cloud.pge.com/idp/startSSO.ping?PartnerSpId=sso.opower.com&TargetResource=https%3A%2F%2Fpge.opower.com%2Fei%2Fapp%2Fr%2Fenergy-usage-details, which if you are logged in has a single form that points to https://sso2.opower.com/sp/ACS.saml2 with 2 hidden inputs: RelayState and SAMLResponse. Then opower replies back with another form with hidden input opentoken.

The Oracle Utilities Opower Single Sign-On Configuration Guide has some technical information that might be helpful in figuring out how SMUD does it.

Your endpoint is different than the PG&E one so it seems it won’t be that easy for the library to support additional utilities.

1 Like

Yea, I am working it out. :slight_smile: not expecting a miracle. See if I can use your code base as a starting base to work around their walls. :smiley:
Right now I see its checking for a browser.

Improve your browsing experience

   You are using an older browser that may limit your access to certain features of our site. An update is recommended, but not required.

   Click any of the browser icons below for a free download of the latest version.
     __

   You can still access our site with your current browser, but some things may not work properly, and some pages may not display correctly.

   Got it. I want to continue

   Let me review your browser support policy
     __

Supported Browsers

     * [chrome.png] Chrome 61+
     * [firefox.png] Firefox 56+
     * [safari.png] Safari 9+
     * [edge.png] Edge 12+
     * [internetexplorer.png] Internet Explorer 10+

You’re able to bypass that with https://myaccount.smud.org/?ack=true , slowly picking at it. I see you also reach a saml URL.

https://smud.okta.com/app/sacramentomunicipalutilitydistrict_opower_1/<something_important>/sso/saml?RelayState=https://smud.opower.com/ei/app/myEnergyUse

Get there little by little. aiohttp is not something I am used to. So far it makes perfect sense.

@tronikos do you have an article or something you can point me at that explains this pyproject.toml and setup.cfg. I have not seen this before. Will “demo.py” = [“T201”] prevent other py scripts from printing to stdout ?

As I said you are on your own on adding support for anything other than PG&E. It looks right you are on the right path. Regarding the browser I’m sure you can fix this by setting a better User-Agent in the request headers than the one I’m setting (Mozilla/5.0). Regarding the pyproject.toml and setup.cfg you can ignore them. They are for building the package and for specifying rules for the formatter and linters.

Thanks! Yea I understood, just writing down my process.

Integration is being added in:

Documentation in:

6 Likes

awesome - so this should hopefully trickle down to a HA release sometime soon?

It depends on the core maintainers when they will review, approve and merge the PR. It might take a few months…

1 Like

Any chance of getting this in a HACS repo for the time being?

1 Like

nvm, was able to do it. Turns out my base64 need to remove the line break. For people’s reference:

# the -n is important
echo -n "$CLIENT_ID:$CLIENT_SECRET" | base64 -w 0

How did you complete the API connectivity testing? I was able to upload my wildcard domain certificate from letsencrypt (*.example.com) and get their approval, but during the test (via https://api.pge.com/datacustodian/test/oauth/v2/token), it complains “Cert not present or invalid Cert” when sending the client certificate over (cert.pem and privatekey.pem).

You can manually install in HACS using this repository:

FYI, I plan to delete this repository once my PRs make it in core.

3 Likes

I have installed OPower on the latest HASIO from the repo and get this error.


This error originated from a custom integration.

Logger: custom_components.opower.coordinator
Source: custom_components/opower/coordinator.py:67
Integration: Opower (documentation, issues)
First occurred: May 10, 2023 at 10:50:08 PM (335 occurrences)
Last logged: 11:28:13 AM

Unexpected error fetching Opower data: 'typicalUsage'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 258, in _async_refresh
    self.data = await self._async_update_data()
  File "/config/custom_components/opower/coordinator.py", line 67, in _async_update_data
    forecasts = await self.api.async_get_forecast()
  File "/usr/local/lib/python3.10/site-packages/opower/opower.py", line 226, in async_get_forecast
    typical_usage=float(forecast["typicalUsage"]),
KeyError: 'typicalUsage'


I made an account on “open energy view” and linked it with my PGE account but I’m not sure if that is still necessary. When I installed the integration in HA it asked me for my PGE login and it accepted it with a successful message. I have also tested my login directly on the PGE site.
I do have 3 accounts under my PGE login so I’m not sure if that is causing the issue.

Thanks
Matt

I get the same error fwiw.

On your browser can you:

  • enable developer tools
  • go to the network tab
  • login to pge.com
  • navigate to energy dashboard
  • navigate to projected bill
  • in the network requests you should see a request for combined-forecast
  • can you copy paste the response? Feel free to redact the values of the keys

How old is your PGE account? It’s likely for new accounts the typicalUsage is missing from the response in which case I need to handle it and not add a sensor for it.

I released an updated version. Let me know if that fixes your issue.

That fixed it!

This is cool, it works for me. No Idea what Ill do with the info, but its neat.

We have 2 service addresses, and one account. Only the first registered service address shows up in the integration. FYI.

Sure did! Thank You!

Will someone please post here when this integration is built into HA Core non-beta?

The library now supports multiple accounts. Can you try the latest version of the integration and report whether you see data for both of your 2 service addresses?