tronikos / opower

A Python library for getting historical and forecasted usage/cost from utilities that use opower.com such as PG&E
Apache License 2.0
54 stars 49 forks source link

New provider: Enmax (Canada) #17

Closed pironic closed 10 months ago

pironic commented 11 months ago

Good afternoon, I'm super eager to use this library (as part of home-assistant) but my python abilities are lacking. If I can provide all of the information from a browser session to login is there someone that can help add/validate the new provider? I'd be happy to assist in any-way that I can.

the subdomain that I see the requests going through are at enmx.opower.com (the missing a is intentional) and the authenticate urls are also mentioning the sso at sso.enmax.com.

When I log into my provider's website at enmax.com I am never presented with a url in my browser visible at opower.com but i see many hits to the enmx.opower.com api in the network tab of chrome's dev tools.

tronikos commented 11 months ago

My recommendation is to try to find someone in your region that has Enmax and has some basic python skills. The login seems easy. It just sends a post request to https://www.enmax.com/SignInSite/_vti_bin/Enmax.Internet.Auth/AuthService.svc/AuthenticateUser with payload: {email: "test@test.com", password: "test", queryString: "", autoUnlockIntervalMinutes: 15} Once you login there should be some other request that returns the opower access token. The code in the other utilities should be very helpful to use as example.

Since this will be the first non US utility, there are some additional changes needed since https://github.com/home-assistant/core/blob/dev/homeassistant/components/opower/sensor.py uses USD as the unit for the cost entities.

aman207 commented 10 months ago

Hi. I've created a PR for this.

HA automatically set the correct currency in the Energy dashboard at least. Not sure if this is because my localization settings are set to Canada?

Screenshot 2023-09-12 180627

tronikos commented 10 months ago

I don't remember setting a unit for the statistics so I guess it makes sense the energy dashboard to work. How about the forecast and usage sensors?

aman207 commented 10 months ago

Hmm, actually there doesn't appear to be any sensors at all...

I see this in the logs

2023-09-13 01:16:05.388 DEBUG (MainThread) [homeassistant.components.opower.coordinator] Updating sensor data with: []
2023-09-13 01:16:05.388 DEBUG (MainThread) [homeassistant.components.opower.coordinator] Updating Statistics for opower:enmx_elec_0020002707151_energy_cost and opower:enmx_elec_..._energy_consumption
2023-09-13 01:16:05.573 DEBUG (MainThread) [homeassistant.components.opower.coordinator] Finished fetching Opower data in 4.792 seconds (success: True)
2023-09-13 01:16:05.576 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.opower
tronikos commented 10 months ago

Not all utilities support the forecast API. I guess we can delay fixing the sensors unit then.