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
53 stars 49 forks source link

ConEd multiple accounts - no forecast data #35

Closed rct closed 10 months ago

rct commented 10 months ago

I'm up to date with what's merged into homeassistant:dev so far (between 2023.8.2 and the yet to be released 2023.8.3). I'm not getting opower sensorss, but with request debugging enabled it looks like I'm getting back forecast data:

2023-08-13 14:51:37.621 DEBUG (MainThread) [/config/opower/opower.py] Fetching: https://cned.opower.com/ei/edge/apis/bill-forecast-cws-v1/cws/cned/customers/XXX-customer-385-duplex-uuid-XXX/combined-forecast
2023-08-13 14:51:37.962 DEBUG (MainThread) [/config/opower/opower.py] Fetched: {
  "isValidUser": true,
  "totalForecast": {
    "meterType": "COMBINED",
    "startDate": "2023-08-10",
    "endDate": "2023-09-08",
    "currentDate": "2023-08-13",
    "daysInPeriod": 30,
    "currentDay": 4,
    "daysLeftInBill": 26,
    "forecastedUsage": 1008,
    "forecastedCost": 0,
    "typicalUsage": 1027,
    "typicalCost": 0,
    "budgetBilling": false,
    "costToDate": 0,
    "usageToDate": 61,
    "currencySymbol": "$"
  },
  "totalMetadata": [
    "NO_FORECASTED_COST"
  ],
  "accountForecasts": [
    {
      "unitOfMeasure": "KWH",
      "meterType": "ELEC",
      "startDate": "2023-08-10",
      "endDate": "2023-09-08",
      "currentDate": "2023-08-13",
      "daysInPeriod": 30,
      "currentDay": 4,
      "daysLeftInBill": 26,
      "forecastedUsage": 1008,
      "typicalUsage": 1027,
      "budgetBilling": false,
      "usageToDate": 61,
      "currencySymbol": "$",
      "preferredUtilityAccountId": "5085809",
      "accountUuids": [
        "XXX-utilacct-duplex-elec-XXX"
      ],
      "isSolar": false
    }
  ]
}
2023-08-13 14:51:37.962 DEBUG (MainThread) [/config/opower/opower.py] Fetching: https://cned.opower.com/ei/edge/apis/bill-forecast-cws-v1/cws/cned/customers/XXX-customer-384-halls-uuid-XXX/combined-forecast
2023-08-13 14:51:38.090 DEBUG (MainThread) [custom_components.opower.coordinator] Updating sensor data with: []

What else can I do to debug this?

tronikos commented 10 months ago

Your URL looks slightly different. The code is using: https://github.com/tronikos/opower/blob/main/src/opower/opower.py#L239-L247

What's the XXX-customer-384-halls-uuid-XXX and XXX-customer-385-duplex-uuid-XXX in your URLs?

As I said in the other issue, the only thing I can do is to accept PRs since I don't have ConEd or multiple accounts.

rct commented 10 months ago

The log output posted above is from Home Assistant.

What's the XXX-customer-384-halls-uuid-XXX and XXX-customer-385-duplex-uuid-XXX in your URLs?

Sorry for the confusion over the URLs, I’ve run the log output through a regular expression that obscures the UUIDs and account numbers for privacy but also to make it easy for me to see which account UUID is being used.

I’ve had to use a local copy of the opower module (loaded by home assistant by placing it in the config directory) to change the hardcoded debug log response variable.

Please correct me where I am wrong, but doesn’t it look like the opower module, as called by the integration, is fetching forecast data for the main electric account and getting a seemingly valid response back?

rct commented 10 months ago

Ok, I think I see the problem, the early/empty return. Apparently it's possible to get a 404 for some accounts but not others.

There's data in forecasts when it does return []. Testing a fix now.

tronikos commented 10 months ago

Good catch. Try replacing return [] with continue

rct commented 10 months ago

That's exactly what I did, works for both demo and Home Assistant.

I now finally have an accessible service and 6 entities.

image

tronikos commented 10 months ago

Thanks. Fixed with v0.0.28 release