Closed si458 closed 2 years ago
Thanks - I thought I had fixed that.
@ColinRobbins this is a different line š you fixed the elec tariff standing, this is for elec tariff rate
@ColinRobbins if you dont change GBP/kWh
to GBP
the web ui in home assistant complains in the console saying
RangeError: invalid currency code in NumberFormat(): GBP/kWh
so this needs to be set as GBP
I donāt think this is right. The Energy integration needs the unit rate to by GBP/kWh, otherwise it wonāt accept it. The standing rate is GBP.
Which page / card are you looking at when you see the console error? Iām not seeing anything in my console!
BEFORE:
AFTER:
CONSOLE ERRORS BEFORE PATCH:
EDIT: uploading right picture does help haha
this is just a standard entities added to my home dashboard
type: entities
entities:
- sensor.electric_consumption_today
- sensor.electric_consumption_year
- sensor.electric_cost_today
- sensor.electric_tariff_rate
- sensor.electric_tariff_standing
EDIT AGAIN: i dont believe the kWh is needed as thats being used/calculated in the energy tab and not on the standard dashboards
Ah, OK.
I think that probably needs a different fix then.
I think GBP/kWh is correct.
The issue is the device class being DEVICE_CLASS_MONETARY
.
Sorry, device class, not state class - corrected post above. No sure what the ācorrectā value should be - lookingā¦
Not sure I can see anything better than āDEVICE_CLASS_ENERGYā
@ColinRobbins im keeping my pi running for now with this patch set as GBP and ill see if any issues happen over the next few days none so fair, but case of wait n see š¤
With it set to GBP, you will not be able to add it as an entity with current price
in the energy dashboard. It will probably work if set up, but would not work if you remove it and try to add it back. The energy dashboard needs GBP/kWh.
With it set to GBP, you will not be able to add it as an
entity with current price
in the energy dashboard. It will probably work if set up, but would not work if you remove it and try to add it back. The energy dashboard needs GBP/kWh.
surely the entity with current price
option would be sensor.electric_cost_today
and not sensor.electric_tariff_rate
?
i currently have mine set to use an entity tracking the total costs
and use sensor.electric_cost_today
and no issues here
If you look at the code in https://github.com/home-assistant/core/blob/dev/homeassistant/components/energy/sensor.py
About line 300, the integration is expecting the price to end in /wh
, /mwh
or by default /kWh
.
My proposed alternative fix, resolves the issue you reported, and meets the expectation of the energy dashboard.
The energy dashboard documentation gives an example in āUSD/kWhā, not āUSDā.
@ColinRobbins if you look at the developer docs too for the sensor entites it says the values need to be either kWh
or a GBP
(currency) for either energy
or monetary
so i think this fix is good enough :)
https://developers.home-assistant.io/docs/core/entity/sensor#available-device-classes
Weāll have to agree to differ, and let HandyHat decide which approach to take.
Revisiting this, I think if you use ārateā in the energy dashboard with GBP as the unit, this PR will lead to the errorā¦
Unexpected unit of measurement
Translation Error: The intl string context variable "currency" was not provided to the string "The following entities do not have the expected units of measurement ''{currency}/kWh'' or ''{currency}/Wh'':"
Hence why I believe the current units are correct at GBP/kWh.
Revisiting this, I think if you use ārateā in the energy dashboard with GBP as the unit, this PR will lead to the errorā¦
Unexpected unit of measurement Translation Error: The intl string context variable "currency" was not provided to the string "The following entities do not have the expected units of measurement ''{currency}/kWh'' or ''{currency}/Wh'':"
Hence why I believe the current units are correct at GBP/kWh.
Where are you seeing this error? I've had no issues/no errors with this pr on my pi for awhile now?
This error is in the HA Logs. It occurs if you use the ārateā sensor, with this PR, in the Energy integration to supply the current cost of energy.
How does ur elec look as no issues here at all?
The error occurs if you use the current tariff rate sensor for āuse an entity with the current priceā. ( I know using the cost sensor is better, but the using the tariff sensor should not result in an error).
Don't mean to intervene but I am with @ColinRobbins on this one.
Here is my reasoning:
use an entity with the current price
and tried it with Electric Cost (Today)
which is basically GBP (unit of measurement) and that indeed throws an error.Revisiting this, I think if you use ārateā in the energy dashboard with GBP as the unit, this PR will lead to the errorā¦
Unexpected unit of measurement Translation Error: The intl string context variable "currency" was not provided to the string "The following entities do not have the expected units of measurement ''{currency}/kWh'' or ''{currency}/Wh'':"
Hence why I believe the current units are correct at GBP/kWh.
So i can confirm changing tariff rate (the entity refered in this PR) to GBP and using it for Energy will error later.
I agree that the tariff rate unit of measurement should be GBP/kWh, and not GBP. This is NOT a sum of money (currency) but rather a unit of measurement, like fuel consumption. Fuel consumption 5L makes no sense if you do not match it against a distance e.g. 100km. (same logic applies to miles per galon obviously). Same things is when you go shop for anything, the price for meat is Ā£/kg, otherwise how do you know how much you are getting for your Ā£?
So that being said, the approach should be to change the device class rather than change the unit of measurement, as already suggested by Colin
Rather than changing line 336, I suggest trying adding the following at line 332:
@property def device_class(self) -> str: """Return None as the device class.""" return None
I've tried it on my test systems, and it seems to solve the issue. I think anything other that None will case issues somewhere.
PS: I have landed here by basically discovering the same error in the console, see here https://github.com/HandyHat/ha-hildebrandglow-dcc/issues/88#issuecomment-976615782
Thank you for the insightful discussion here everyone! I'm going to close this in favour of @ColinRobbins' solution of unsetting the device class (#138), as I think that makes more sense
Description
fix home assistant complaining GBP/kWH is an invalid currency
Motivation and Context
How Has This Been Tested?
Types of changes