BottlecapDave / HomeAssistant-OctopusEnergy

Unofficial Home Assistant integration for interacting with Octopus Energy
https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/
MIT License
612 stars 61 forks source link

Current Electricity rate is £0.00/kWh for some (all?) versions >1.0.0 #34

Closed AlexCPU closed 2 years ago

AlexCPU commented 2 years ago

Describe the bug I've tried versions: 1.0.0 which correctly exposes the Electricity Current Rate (I'm on an old Go tariff), and this has been changing as expected at 00:30 and 04:30. However in all of the other released versions that I've tried, this sensor is just returning 0.00 GBP/kWh. I've tried versions:

To Reproduce I have no idea, I've just updated to newer versions, and had to manually roll them back

Expected behavior The Electricity Current Rate sensor continues working in later versions, or is replaced with a similar sensor (I can't see one though)

Home Assistant Logs Can't spot anything particularly relevant. Let me know if you want something specific and I'll get it,l be that specific logs, dumps of raw API from Octopus, etc.

image

BottlecapDave commented 2 years ago

Hi there. Sorry you have been having issues with the component. Are you seeing any errors in the logs that are tied to the integration?

BottlecapDave commented 2 years ago

Also on the latest version of the sensor, in the attributes it gives you the tariff it's trying to retrieve the data for. Could you update this issue with that information too?

AlexCPU commented 2 years ago

Hi @BottlecapDave,

Logs are below (using 3.0.2).

I'm not sure where to find the attributes that you mention, but here is a screenshot of States tab of developer tools looking at all of the electric elements that the integration is creating (there's a handful of gas ones as well that all read 0). image

2021-12-29 11:00:11 WARNING (MainThread) [homeassistant.components.sensor] Setup of sensor platform octopus_energy is taking over 10 seconds.
2021-12-29 11:01:20 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.octopus_energy_electricity_17p7316843_previous_accumulative_cost fails
Traceback (most recent call last):
File "/config/custom_components/octopus_energy/sensor.py", line 422, in async_update
rate = next(r for r in rates if r["valid_from"] == consumption_from and r["valid_to"] == consumption_to)
StopIteration
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 487, in async_update_ha_state
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 691, in async_device_update
raise exc
File "/config/custom_components/octopus_energy/sensor.py", line 424, in async_update
raise Exception(f"Failed to find rate for consumption between {consumption_from} and {consumption_to} for tariff {self._tariff_code}")
Exception: Failed to find rate for consumption between 2021-12-28 04:00:00+00:00 and 2021-12-28 04:30:00+00:00 for tariff E-1R-GO-18-06-12-E
2021-12-29 11:02:20 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.octopus_energy_electricity_17p7316843_previous_accumulative_cost fails
Traceback (most recent call last):
File "/config/custom_components/octopus_energy/sensor.py", line 422, in async_update
rate = next(r for r in rates if r["valid_from"] == consumption_from and r["valid_to"] == consumption_to)
StopIteration
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 487, in async_update_ha_state
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 691, in async_device_update
raise exc
File "/config/custom_components/octopus_energy/sensor.py", line 424, in async_update
raise Exception(f"Failed to find rate for consumption between {consumption_from} and {consumption_to} for tariff {self._tariff_code}")
Exception: Failed to find rate for consumption between 2021-12-28 04:00:00+00:00 and 2021-12-28 04:30:00+00:00 for tariff E-1R-GO-18-06-12-E
BottlecapDave commented 2 years ago

I've released a patch in v3.0.3 which should fix retrieving GO tariffs, which in turn should fix the consumption calculations. Let me know if you have any further issues

AlexCPU commented 2 years ago

Thanks, this looks to be working, I'll come back tomorrow and close the issue once I've seen it make it through the Go period.

AlexCPU commented 2 years ago

Seems to be working now, thanks!