PG&E Energy Monitoring Integration

Ok so it looks like what I am missing is the extendedKeyUsage = clientAuth extension and that is why its giving me this message.

I used LetsEncrypt with a personal subdomain, and just pasted in the in the contents of cert.pem with no issue

Yeah that all sounds familiar based on what you’ve written up before; didn’t realize that was all still related to self-access though.

I’m curious and I’ll check in the docs, but my off-the-cuff idea was that setting up a webhook in Home Assistant would fulfill the purpose of receiving a POST (obviously, assuming that the webhook URL was publicly accessible and using SSL properly).

I assume that setting up a webhook within the context of a HASS integration may not be super straightforward, but am I completely off-base?

Either way, I definitely agree that integrating with OEV seems to be a more straightforward approach

My original post:

Technically, I believe the charge and conviction was for manslaughter.

This was a factual correction to the preceding post, which incorrectly stated what crime(s) PG&E has plead guilty to.

I can’t imagine there’s many people in this thread who aren’t stuck with PG&E, and given the utility’s long history of corporate negligence, some reading this thread are going to have some justifiably deep-seated and very negative opinions of the company based on the life-ending and -altering hazards it has imposed on people in their service area, and it’s not like someone can switch who delivers their electricity and natural gas.

I’m not trying to start a fight or de-rail, but per post #61, GreenButton only exists as the result of regulatory action. @JPHutchins has built something very cool, and being that it’s based on federal regulation, OEV will be useful well outside the PG&E service area. (Thanks!)

PG&E’s status as an awful corporate citizen, however is relevant, as creates an opportunity for the imposition of more regulation on PG&E (and other utilities covered by the same agencies.) If H-A users served by PG&E remember that this is a company that is not in good standing with regulators and legislators, there’s a chance to reach out to state officials to demand and get a way to ingest data that doesn’t require setting up a whole web service to get timely usage info, rate information, etc… and instead get something more usable like a polling or push service.

2 Likes

I believe that each HA instance would need to register its own SSL cert with PGE (manually?) and the user would need to forward port 443 from their router to HA. Maybe web hooks solve for some of this, IDK anything about them.

I personally like alternatives, Open Energy view is just one way.

Couple ways this can be done where different services act as a “client” or recipient of the webhook, but a intermediate service has to be used one way or another if you are not exposing your HA instance to the internet.

A webhook can be created under Automation and can receive either json or data.
( IE. trigger.json, trigger.data )

  1. Use of a Nabu Cloud webhook that is automatically created if a the user is subscribed.

  2. Use a cloud service like AWS Lamba or Google Cloud functions as a client for the web hook, and pub/sub to subscribe the HA custom integration to the notifications.

Now poking around at the internals I see webhooks on Home Assistant are not designed to use an type of authentication or security at all, see : Automation Trigger - Home Assistant

Now personally I would lean on option number 2, but that still leaves the certificate that PG&E wants from you.

@JPHutchins these probably will answer your previous question:
“What certificates are you wondering about? Please point me to the PGE docs.”

image
Image is a link to the page

Probably an important tidbit - all other requests between you and PG&E are over mutual SSL and require that you attach your client SSL certificate to your request. (This needs to be the same certificate you sent to PG&E prior to being accepted.)

On the bonus side this says " Standard APIs -
Nationally recognized standard Energy Service Provider Interface API format for interoperability with other energy providers." I know that here in California this format is used by at least 5 other utilities to get gas, electric, and water usage data depending on the circumstance.

I don’t see how I can get my data from OEV. Is there something I’m missing? I’ve been through the OEV dash a few times. It’s nifty and all, but I don’t see any documentation on getting that imported to my instance of HA – this is a Home Assistant forum, on a topic about integrating PG&E data into Home Assistant.

The good news is PG&E “Share My Data” is live and appears to be up and running. I just registered, myself, pointing to a random Webhook I just created via automation. However, I still don’t see how to get that data imported into HA’s Energy view.

2 Likes

following post

any timeline for the gas integration? would love to be able to analyze my usage!

I was able to get usage/cost for both electricity and gas without the need of going through the complicated “Share My Data” steps that I don’t expect any average user could follow. I’ve been using the opower.com JSON API, the same one the website is using so you only need username and password to login. From start I coded the library to be extensible so that others can very easily add support for other utlity websites that also use opower.com since it seems a lot of utilities are using them.

I’ve been coding a Home Assistant integration in the past couple of days. I’m exposing 12 sensors, 6 for electricity, 6 for gas with the following data:

  • Current bill usage to date
  • Current bill cost to date
  • Current bill forecasted usage
  • Current bill forecasted cost
  • Typical monthly usage
  • Typical monthly cost

I’ve also been able to get consumption and cost data in the energy dashboard but with the past 1-2 days missing. At initial setup I’m performing a backfill using:

  • month resolution for all years (since account activation)
  • day resolution for past 3 years (max possible since opower only keeps monthly data for older than 3y)
  • hour resolution for past 2 months (only for electricity, for gas the minimum resolution is day)

The hour resolution could also go up to 3 years back but I don’t see how it could be useful especially since Home Assistant’s energy dashboard doesn’t allow you to easily see data for a single date (you have to manually click on previous day when viewing today so you would have to tap it a lot of times…).

I need to fix a couple of remaining bugs before I prepare a PR. In the meantime, let me know if you have any suggestions.

In the future I’d like to add support for production data in addition to consumption. I had solar installed yesterday but it will take a while for the permission to operation so that I can see how the data is represented in the API.

6 Likes

I uploaded my library at:

If anyone has production via solar I’d appreciate it you could send me the output of:

python src/demo.py --verbose 2> out.txt
python src/demo.py --verbose --usage_only 2> out_usage_only.txt

but after you remove any sensitive information such as address of account.

If you are familiar with Python, it’s even better if you can send me a pull request that adds production data in Forecast, CostRead, and UsageRead classes.

Edit: No need to send me anything. I saw for the short time my system was active the reported values are negative so what I have should work fine.

Awesome. I was going to start trying to figure out how to feed the XML data into a sensor, but you are ahead of me.

SMUD does something weird. They log you in here, https://myaccount.smud.org/signin/index?ReturnUrl=%2fmanage%2fopowerresidential%2fenergyusage and then redirect your browser.

Also has a hidden form with a __RequestVerificationToken

After that you get something out of the opower website but it doesn’t look like the PG&E location (endpoint). Really don’t want me to automate getting my data. :triumph:

https://smud.opower.com/ei/x/energy-use-details?ou-data-browser=%2Fcost%2Felectricity%2Fbill%2F2023-03-18%3FaccountUuid%3D##REDACTED##

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