BottlecapDave / HomeAssistant-OctopusEnergy

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

Gas meter not discovered/no sensors generated for gas. #45

Closed itsfja closed 2 years ago

itsfja commented 2 years ago

Describe the bug Missing gas meter sensors

To Reproduce Added integration, current and previous electricity meter added, no gas meter

A gas meter may be seen to be present when running an API curl command https://api.octopus.energy/v1/accounts/A-xxxxxxx/ (the same key and acount added to the integrations. The meter is SMETS1 but is adopted )I tried ticked and unticked).

Expected behavior Gas meter sensors to be added. Home Assistant Logs I can't find anything useful.

BottlecapDave commented 2 years ago

Sorry to hear you're having issues. I've just released a new version with some additional debugging information around adding sensors. To get this information, the first thing to do is increase the log levels for the component. This can be done by setting the following values in your configuration.yaml file.

logger:
  logs:
    custom_components.octopus_energy: info

If you don't have access to this file, then you should be able to set the log levels using the available services.

Once done, you'll need to reload the integration and then check the "full home assistant log". You should then see entries associated with this component stating either sensors were added, skipped or no sensors were available at all.

The identifiers of the sensors should then be checked against your Octopus Energy dashboard to verify the correct sensors are being picked up.

itsfja commented 2 years ago

Thanks for the prompt response.

I deleted the integration, downloaded the latest version, installed and there are now no sensors.

The major error in the log is now;

Logger: homeassistant.components.sensor Source: custom_components/octopus_energy/sensor.py:132 Integration: Sensor (documentation, issues) First occurred: 20:15:42 (3 occurrences) Last logged: 20:16:17

Error while setting up octopus_energy platform for sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform await asyncio.shield(task) File "/config/custom_components/octopus_energy/sensor.py", line 97, in async_setup_entry await async_setup_default_sensors(hass, entry, async_add_entities) File "/config/custom_components/octopus_energy/sensor.py", line 132, in async_setup_default_sensors _LOGGER.info(f'Skipping electricity meter due to no active agreement; mpan: {point["mpan"]}; serial number: {meter["serial_number"]}') UnboundLocalError: local variable 'meter' referenced before assignment

itsfja commented 2 years ago

I'll try again using branch main (it defaulted to develop. Oops.

BottlecapDave commented 2 years ago

Nope, that looks like my dodgy logic. There is a new version available at https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/releases/tag/v4.1.1.

Based on where it's erroring, it looks like you have some meters without active agreements. Have you had sensors replaced? Do you know what kind of tariff you're on?

itsfja commented 2 years ago

On 4.1.0 - I can see 8 sensors, all related to the electricity meters, I am unable to find the word "gas" in the log.

I am on the TEP, that might entertain you for a bit, they just added a second tariff to the one meter.

From Octopus; Gas: Octopus 12M Fixed Electricity: Sorry, we weren't able to get the details for your tariff. (I'm betting it will be "Tesla Energy Plan Export" tomorrow) Electricity: Tesla Energy Plan Import.

BottlecapDave commented 2 years ago

The newly added information doesn't seem to appear in the HA log panel. You'll need to click "Load Full Home Assistant Log" to get the debug logs. As mentioned, 4.1.1 should fix your previous error.

itsfja commented 2 years ago

On 4.1.1 - Logger: homeassistant.components.sensor Source: custom_components/octopus_energy/sensor.py:151 Integration: Sensor (documentation, issues) First occurred: 21:15:43 (1 occurrences) Last logged: 21:15:43

Error while setting up octopus_energy platform for sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform await asyncio.shield(task) File "/config/custom_components/octopus_energy/sensor.py", line 97, in async_setup_entry await async_setup_default_sensors(hass, entry, async_add_entities) File "/config/custom_components/octopus_energy/sensor.py", line 151, in async_setup_default_sensors _LOGGER.info(f'Skipping gas meter due to no active agreement; mpan: {point["mpan"]}; serial number: {meter["serial_number"]}') KeyError: 'mpan'

itsfja commented 2 years ago

From the full log;

2022-03-22 21:15:43 INFO (MainThread) [custom_components.octopus_energy.sensor] Skipping electricity meter due to no active agreement; mpan and serial number: 2022-03-22 21:15:43 INFO (MainThread) [custom_components.octopus_energy.sensor] agreements: [] 2022-03-22 21:15:43 INFO (MainThread) [custom_components.octopus_energy.sensor] Adding electricity meter; mpan: and; serial number: 2022-03-22 21:15:43 INFO (MainThread) [custom_components.octopus_energy.sensor] Adding electricity meter; mpan: and; serial number:

Still no Gas. Much like half the world at the moment.

BottlecapDave commented 2 years ago

🙄 Another fix inbound. At some point I should deploy some code that works in this area. Once deployed, it should indicate the gas sensor that is being skipped and the agreements associated with the sensor which should indicate why it's being skipped.

itsfja commented 2 years ago

Fast coder!

itsfja commented 2 years ago

4.1.2

2022-03-22 21:42:23 INFO (MainThread) [custom_components.octopus_energy.sensor] Skipping electricity meter due to no active agreement; mpan: 002; serial number: 207 2022-03-22 21:42:23 INFO (MainThread) [custom_components.octopus_energy.sensor] agreements: [] 2022-03-22 21:42:23 INFO (MainThread) [custom_components.octopus_energy.sensor] Adding electricity meter; mpan: 768; serial number: 639 2022-03-22 21:42:23 INFO (MainThread) [custom_components.octopus_energy.sensor] Adding electricity meter; mpan: 768; serial number: 207 2022-03-22 21:42:23 INFO (MainThread) [custom_components.octopus_energy.sensor] Skipping gas meter due to no active agreement; mprn: 101; serial number: 171 2022-03-22 21:42:23 INFO (MainThread) [custom_components.octopus_energy.sensor] Skipping gas meter due to no active agreement; mprn: 101; serial number: 800 2022-03-22 21:42:23 INFO (MainThread) [custom_components.octopus_energy.sensor] agreements: [{'tariff_code': 'G-1R-FIX-12M-18-02-14-G', 'valid_from': '2018-04-02T00:00:00+01:00', 'valid_to': '2019-04-02T00:00:00+01:00'}, {'tariff_code': 'G-1R-FIX-12M-18-12-21-G', 'valid_from': '2019-04-02T00:00:00+01:00', 'valid_to': '2020-04-02T00:00:00+01:00'}, {'tariff_code': 'G-1R-SUPER-GREEN-12M-20-02-12-G', 'valid_from': '2020-04-02T00:00:00+01:00', 'valid_to': '2021-04-02T00:00:00+01:00'}, {'tariff_code': 'G-1R-VAR-20-10-01-G', 'valid_from': '2021-04-02T00:00:00+01:00', 'valid_to': '2021-04-02T00:00:00+01:00'}, {'tariff_code': 'G-1R-FIX-12M-21-02-16-G', 'valid_from': '2021-04-02T00:00:00+01:00', 'valid_to': '2022-04-02T00:00:00+01:00'}] 2022-03-22 21:42:23 INFO (MainThread) [custom_components.octopus_energy.sensor] Updating OctopusEnergyElectricityPreviousRate for '768/639' 2022-03-22 21:42:23 INFO (MainThread) [custom_components.octopus_energy.sensor] Updating OctopusEnergyElectricityCurrentRate for '768/207' 2022-03-22 21:42:23 INFO (MainThread) [custom_components.octopus_energy.sensor] Updating OctopusEnergyElectricityPreviousRate for '768/207' 2022-03-22 21:42:23 INFO (MainThread) [custom_components.octopus_energy.sensor] Updating OctopusEnergyElectricityCurrentRate for '768/639' 2022-03-22 21:42:23 INFO (MainThread) [custom_components.octopus_energy.sensor] Calculated previous electricity consumption for '768/207'...

Is there a better way of giving you logs? I've removed all but the last three characters of serials etc, where I found them. By the way - the agreements [] is verbatim, not redacted.

002 is electricity on 207. Sorry, we weren't able to get the details for your tariff 768 is electricity on 207. Tesla Energy Plan Import 101 is gas on 800. Octopus 12M Fixed. Expires in two weeks, goodbye heating.

BottlecapDave commented 2 years ago

It looks like it's not picking up the final agreement for your gas despite it still being active, so that's where I'll take a look.

In regards to logs, what you have provided is sufficient. However, I think I'm going to expose an overarching device so that the relevant information can be extracted more easily using https://www.home-assistant.io/integrations/diagnostics/

BottlecapDave commented 2 years ago

I've just released https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/releases/tag/v4.1.3, which should fix your issue. Let me know if it works or if you have any further issues.

itsfja commented 2 years ago

4.1.3

Unable to get past Setup your basic account information screen.

"Account information was not found"

Transient error - 5th attempt scucceded

itsfja commented 2 years ago

4.1.3

2022-03-23 19:28:57 INFO (MainThread) [custom_components.octopus_energy.sensor] Skipping electricity meter due to no active agreement; mpan: 002; serial number: 207 2022-03-23 19:28:57 INFO (MainThread) [custom_components.octopus_energy.sensor] agreements: [] 2022-03-23 19:28:57 INFO (MainThread) [custom_components.octopus_energy.sensor] Adding electricity meter; mpan: 1620000868768; serial number: 639 2022-03-23 19:28:57 INFO (MainThread) [custom_components.octopus_energy.sensor] Adding electricity meter; mpan: 768; serial number: 207 2022-03-23 19:28:57 INFO (MainThread) [custom_components.octopus_energy.sensor] Adding gas meter; mprn: 101; serial number: 171 2022-03-23 19:28:57 INFO (MainThread) [custom_components.octopus_energy.sensor] Adding gas meter; mprn: 101; serial number: 800 2022-03-23 19:28:57 INFO (MainThread) [custom_components.octopus_energy.sensor] Updating OctopusEnergyGasCurrentRate 2022-03-23 19:28:57 INFO (MainThread) [custom_components.octopus_energy.sensor] Updating OctopusEnergyGasCurrentRate 2022-03-23 19:28:57 INFO (MainThread) [custom_components.octopus_energy.sensor] Updating OctopusEnergyElectricityPreviousRate for '768/639' 2022-03-23 19:28:57 INFO (MainThread) [custom_components.octopus_energy.sensor] Updating OctopusEnergyElectricityCurrentRate for '768/207' 2022-03-23 19:28:57 INFO (MainThread) [custom_components.octopus_energy.sensor] Updating OctopusEnergyElectricityPreviousRate for '768/207' 2022-03-23 19:28:57 INFO (MainThread) [custom_components.octopus_energy.sensor] Updating OctopusEnergyElectricityCurrentRate for '768/639' 2022-03-23 19:28:58 INFO (MainThread) [custom_components.octopus_energy.sensor] Calculated previous gas consumption for '101/800'... 2022-03-23 19:28:58 INFO (MainThread) [custom_components.octopus_energy.sensor] Calculated previous electricity consumption for '768/207'... 2022-03-23 19:29:59 INFO (MainThread) [custom_components.octopus_energy.sensor] Calculated previous gas consumption cost for '101/800'... 2022-03-23 19:30:57 INFO (MainThread) [custom_components.octopus_energy.sensor] Updating OctopusEnergyElectricityPreviousRate for '768/639' 2022-03-23 19:30:57 INFO (MainThread) [custom_components.octopus_energy.sensor] Updating OctopusEnergyElectricityCurrentRate for '768/207' 2022-03-23 19:30:57 INFO (MainThread) [custom_components.octopus_energy.sensor] Updating OctopusEnergyElectricityPreviousRate for '768/207' 2022-03-23 19:30:57 INFO (MainThread) [custom_components.octopus_energy.sensor] Updating OctopusEnergyElectricityCurrentRate for '768/639'

So ... Lots of meters to look at, the gas is present. Some ghosts (I'll just hide them). Sorted, Thanks for a very prompt fix.

BottlecapDave commented 2 years ago

Glad it worked :)