evcc-io / evcc

Sonne tanken ☀️🚘
https://evcc.io
MIT License
3.53k stars 653 forks source link

Grid type octpusenergy key is called "tariff" but only accepts "product" #13474

Closed teun95 closed 6 months ago

teun95 commented 6 months ago

Describe the bug

The grid type octopusenergy has the key tariff, but when the tariff code is used an error is displayed in the log. When the product code is used, the configuration works without issues.

Octopus Energy has tariff codes and product codes, which conflicts with how the terminology is used in EVCC. If Octopus Energy would not have had tariff codes, users would not have been confused and would use product codes as value for tariff. However, given that looking up a Octopus Energy product code will also expose the user to the tariff code, the error is the result of expected configuration changes.

For clarification, this is from the API reference of Octopus Energy.

product_code

    The code of the product to be retrieved, for example VAR-17-01-11.
tariff_code

    The code of the tariff to be retrieved, for example E-1R-VAR-17-01-11-A.

As you can see, the tariff code is made up of the product code with some additional stuff. I believe that EVCC actually obtains the tariff code using the product code.

Steps to reproduce

  1. Configure octopusenergy as grid type
  2. Use the tariff code E-1R-COSY-22-12-08-A as value for tariff

Configuration details

tariffs:
  currency: GBP
  grid:
    type: octopusenergy
    tariff: E-1R-COSY-22-12-08-A # Tariff code
    region: A # optional

Log details

**Log output when using `E-1R-COSY-22-12-08-A` as value for `tariff`:**

[octopus] ERROR 2024/04/17 16:01:59 unexpected status: 404 (Not Found)
[main  ] ERROR 2024/04/17 16:01:59 failed configuring grid tariff: cannot create tariff type 'octopusenergy': unexpected status: 404 (Not Found)


### What type of operating system are you running?

HomeAssistant Add-on

### Version

0.125.0
teun95 commented 6 months ago

I think there are two options for a fix:

  1. Clarify in the documentation that tariff in the case of Octopus Energy refers to the product code. I think this is undesirable as it is more of a workaround.
  2. Add an additional more specific key called tariffcode or productcodeand update /tariff/octopus/api.go to reflect this. Tariff can then be deprecated in time. I do not have enough knowledge of the octopus energy api to know whether it makes most sense to ask for the tariffcode or productcode.
  3. Add a key for the Octopus Energy api token and obtain the active tariff code in the background. This is more work, but provides a better user experience as the API key can relatively easily be found in the Octopus Energy account details whereas finding the product or tariff details is more involved.
andig commented 6 months ago

Is this similar to https://github.com/evcc-io/evcc/pull/11555?

/cc @duckfullstop

duckfullstop commented 6 months ago

It is - #11555 provides option 3

Tariff and product codes are mightily confusing to pick apart because they're referred to by similar phrases in different places - sorry for any confusion!

I'd suggest we could catch this during parsing of the code (and act appropriately), but option 2 is probably a better move for long term codebase tidiness (alongside option 3)

andig commented 6 months ago

@duckfullstop would you want to follow up with the PR? Otherwise I'd close here as wontfix.

duckfullstop commented 6 months ago

I'm happy to provide a fix (life permitting), but I'm not sure whether it makes more sense to add it as part of #11555, or as a separate thing?

andig commented 6 months ago

As you prefer, no strong opinion here.

duckfullstop commented 6 months ago

I have pushed a non-breaking change from tariff to productcode to the branch, ready for review once it's unstaled (unless I broke #11555?)

(my IDE of choice has self-combusted and I'm away from home so the PR may be horribly broken as I'm only able to test with a really old version (which isn't Go 1.22 compliant), I might be able to spend some time on it next week but I'm 99.9% confident that branch works)