tronikos / opower-hacs

HACS integration for PG&E via Opower
10 stars 2 forks source link

Unexpected error fetching Opower data: unsupported operand type(s) for +=: 'float' and 'NoneType' #4

Closed mrpedaling closed 1 year ago

mrpedaling commented 1 year ago

Hi, login successful, but warnings and errors on fetch:

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 69, in _async_update_data
    await self._insert_statistics([forecast.account for forecast in forecasts])
  File "/config/custom_components/opower/coordinator.py", line 124, in _insert_statistics
    cost_sum += cost_read.provided_cost
TypeError: unsupported operand type(s) for +=: 'float' and 'NoneType'

Hope this is helpful. Let me know if I can provide more info, and what kind.

tronikos commented 1 year ago

Can you log the cost_read?

Change /config/custom_components/opower/coordinator.py line 124 from:

                cost_sum += cost_read.provided_cost

to

                if cost_read.provided_cost is None:
                    _LOGGER.error("cost_read: %s", cost_read)
                cost_sum += cost_read.provided_cost
mrpedaling commented 1 year ago

Thanks for the snippet. Here's that new log output:

Logger: custom_components.opower.coordinator Source: custom_components/opower/coordinator.py:69 Integration: Opower (documentation, issues) First occurred: 8:56:36 AM (5 occurrences) Last logged: 8:58:41 AM cost_read: CostRead(start_time=datetime.datetime(2016, 5, 23, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=61200))), end_time=datetime.datetime(2016, 5, 31, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=61200))), consumption=-99.387, provided_cost=None)

mrpedaling commented 1 year ago

Seeing the negative consumption, it just occurred to me to mention we have a grid-tied solar setup w/ net metering.

tronikos commented 1 year ago

If you login on pge.com and navigate to energy usage details -> energy costs, what do you see? Do you see zero dollars? Or negative dollars?

mrpedaling commented 1 year ago

I'm seeing negative dollars

tronikos commented 1 year ago

Can you copy one of the cost reads with negative value? e.g. mine (with positive value) is:

{
  "startTime": "2023-05-03T00:00:00.000-07:00",
  "endTime": "2023-05-04T00:00:00.000-07:00",
  "value": 13.7592,
  "readType": "ACTUAL",
  "providedCost": 4.258622698,
  "readComponents": [
    {
      "tierType": "ORDINAL",
      "tierNumber": 2,
      "season": "WINTER",
      "dayPart": "OFF_PEAK",
      "cost": 0,
      "value": 0
    },
    {
      "tierType": "ORDINAL",
      "tierNumber": 1,
      "season": "WINTER",
      "dayPart": "OFF_PEAK",
      "cost": 3.31926771,
      "value": 10.8526
    },
    {
      "tierType": "ORDINAL",
      "tierNumber": 1,
      "season": "WINTER",
      "dayPart": "ON_PEAK",
      "cost": 0.939354988,
      "value": 2.9066
    },
    {
      "tierType": "ORDINAL",
      "tierNumber": 2,
      "season": "WINTER",
      "dayPart": "ON_PEAK",
      "cost": 0,
      "value": 0
    }
  ],
  "isPeakPeriod": false,
  "rebateAmount": 0,
  "milesDriven": 23
}

Let me know which value matches the negative dollars you see in the dashboard.

FrancoisHuet commented 1 year ago

FWIW, I tried to reproduce this issue after submitting #6 (which doesn't seem related, thought it's PG&E and I'm also on NEM), but couldn't.

tronikos commented 1 year ago

Can you still reproduce this? I got PTO for solar a couple of weeks ago and I cannot reproduce. I'm closing this but please reopen if you still experience this.

rianadon commented 1 year ago

Thank you for the integration @tronikos! I'm really looking forward to getting PG&E data into Home Assistant.

After the setup today of version 0.0.12 I have this same error message, except while we do have solar the consumption for this reading is positive:

CostRead(start_time=datetime.datetime(2011, 11, 5, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=61200))), end_time=datetime.datetime(2011, 12, 1, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))), consumption=412.0, provided_cost=None)

Any ideas why there is no cost data? Maybe it's just too far back in time?

tronikos commented 1 year ago

Before I treat missing provided_cost as 0, could you follow my previous messages?

If you login on pge.com and navigate to energy usage details -> energy costs, what do you see for the same time period?

Could you copy the response of one of the relevant https://pge.opower.com/ei/edge/apis/DataBrowser-v1/cws/cost/utilityAccount/XXX request?

rianadon commented 1 year ago

I took a look at the PG&E energy costs dashboard for that time period and it looks like they are for some reason missing the data. There are no cost readings between November of 2011 and August of 2012, but there are cost readings before and after that period. Nevertheless, despite the missing no cost data, there are still net energy readings for that period.

Here's part of the response of the https://pge.opower.com/ei/edge/apis/DataBrowser-v1/cws/utilities/pge/utilityAccounts/XXX/reads?aggregateType=bill&includeEnhancedBilling=false&includeMultiRegisterData=false request (which has all the readings):

{"startTime":"2011-10-29T00:00:00.000-07:00","endTime":"2011-11-05T00:00:00.000-07:00","consumption":{"value":0.000,"type":"ACTUAL"},"demand":null,"exported":null,"grossConsumption":null,"grossGeneration":null,"imported":null,"reactivePower":null,"providedCost":1.05,"milesDriven":0},
{"startTime":"2011-11-05T00:00:00.000-07:00","endTime":"2011-12-01T00:00:00.000-08:00","consumption":{"value":412.000,"type":"ACTUAL"},"demand":null,"exported":null,"grossConsumption":null,"grossGeneration":null,"imported":null,"reactivePower":null,"providedCost":null,"milesDriven":692},
{"startTime":"2011-12-01T00:00:00.000-08:00","endTime":"2011-12-30T00:00:00.000-08:00","consumption":{"value":680.000,"type":"ACTUAL"},"demand":null,"exported":null,"grossConsumption":null,"grossGeneration":null,"imported":null,"reactivePower":null,"providedCost":null,"milesDriven":1142},

It's definitely odd the data is missing. It would be a great coincidence if the cost for each of those 12 months was zero.

tronikos commented 1 year ago

Fixed in the latest release by treating missing cost values as 0.