core: Opower: error at stats[cost_statistic_id][0]

The problem

Integration fails to initialize and will continuously retry the entire time the integration is enabled.

What version of Home Assistant Core has the issue?

core-2024.2.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

opower

Link to integration documentation on our website

https://www.home-assistant.io/integrations/opower

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.components.opower.coordinator
Source: helpers/update_coordinator.py:313
Integration: Opower (documentation, issues)
First occurred: February 12, 2024 at 11:07:13 PM (890 occurrences)
Last logged: 9:00:46 PM

Unexpected error fetching Opower data: 'opower:ace_elec_<REDACTED>_energy_cost'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 313, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/opower/coordinator.py", line 87, in _async_update_data
    await self._insert_statistics()
  File "/usr/src/homeassistant/homeassistant/components/opower/coordinator.py", line 136, in _insert_statistics
    cost_sum = cast(float, stats[cost_statistic_id][0]["sum"])
                           ~~~~~^^^^^^^^^^^^^^^^^^^
KeyError: 'opower:ace_elec_<REDACTED>_energy_cost'

Additional information

I have redacted account information from the logs.

It has functioned in the past with the exception that the account hasn’t had enough data to create sensors yet so it only logs into the account but no data is provided. I believe the issue started when my account has finally gotten information and its probably not in the format the integration expected.

About this issue

  • Original URL
  • State: closed
  • Created 5 months ago
  • Reactions: 1
  • Comments: 24 (8 by maintainers)

Most upvoted comments

For those that encounter error at stats[cost_statistic_id][0] could you please post the following:

  1. From the SQLite Web addon execute the following query: SELECT statistic_id, MAX(start_ts), MAX(created_ts) FROM statistics AS s JOIN statistics_meta AS sm WHERE s.metadata_id = sm.id AND sm.source="opower" GROUP BY statistic_id; The MAX(start_ts) should match for both the consumption and cost statistics.
  2. At what granularity do you get usage data on your utility’s official website? For me (PG&E) this is under “energy use” where I can switch to day view and view usage by hour.
  3. At what granularity do you get cost data on your utility’s official website? For me (PG&E) this is under “energy costs” where I can switch to day view and view cost by hour.
  4. On your browser open tools > developer tools > network and visit your utility’s official website to view cost data, see 2 above. Post the response of the request that looks like: https://pge.opower.com/ei/edge/apis/DataBrowser-v1/cws/utilities/pge/utilityAccounts/XXX/reads?startDate=2024-03-03&endDate=2024-03-03&aggregateType=hour&includeEnhancedBilling=false&includeMultiRegisterData=false. For you pge, XXX, and dates will be different.
  5. If you can, post the output running demo.py in https://github.com/tronikos/opower with --aggregate_type hour or day if hour doesn’t work.
  6. If you can, try out the previous PRs and report back.

@home-assistant rename Opower: error at stats[cost_statistic_id][0]

Can you post what worked for you? It might be good to add it in the documentation as a workaround until we can properly fix it.