custom-components / nordpool

This component allows you to pull in the energy prices into Home-Assistant.
444 stars 105 forks source link

The calculated value under "Mean" is not correct #339

Open edwin-bergstedt opened 1 year ago

edwin-bergstedt commented 1 year ago

Version of the custom_component

0.0.14

Homeassistant version

2023.9.3

Configuration


  - platform: nordpool
    # Should the prices include vat? Default True
    VAT: True
    # What currency the api fetches the prices in
    # this is only need if you want a sensor in a non local currency
    currency: "EUR"
    # Option to show prices in cents (or the equivalent in local currency)
    price_in_cents: false
    # Helper so you can set your "low" price
    # low_price = hour_price < average * low_price_cutoff
    low_price_cutoff: 0.95
    # What power regions your are interested in
    # Possible values: "DK1", "DK2", "FI", "LT", "LV", "Oslo", "Kr.sand", "Bergen", "Molde", "Tr.heim", "Tromsø", "SE1", "SE2", "SE3","SE4", "SYS", "EE"
    region: "SE3"
    # How many decimals to use in the display of the price
    precision: 3
    # What the price should be displayed in default
    # Possible values: MWh, kWh and Wh
    # default: kWh
    price_type: kWh
    # This option allows the usage of a template to add a tariff.
    # now() always refers start of the hour of that price.
    # this way we can calculate the correct costs add that to graphs etc.
    # The price result of the additional_costs template expects this additional cost to be in kWh and not cents as a float
    # default {{0.0|float}}
    additional_costs: "{{0.0|float}}"

Describe the bug

The value calculated under "Mean" is not the mean value, mean and average are almost always the same. The value calculated is probably the Median, the center of all values.

If i run the values for today (24/8) in python:

state_class: total average: 1.2279166666666668 off_peak_1: 0.30575 off_peak_2: 2.0285 peak: 1.5758333333333332 min: 0.276 max: 3.851 mean: 0.435 unit: kWh currency: SEK country: Sweden region: SE3 low_price: true price_percent_to_average: 0.3583305055989141 today:

Output from Pandas DataFrame: count 24.000000 mean 1.227917 std 1.141570 min 0.276000 25% 0.321500 50% 0.435000 75% 2.309500 max 3.851000 median 0.435

The average is equal to the mean at 1.2279, but the mean is probably mislabelled and should be called median instead.

Debug log


This bug is not visible in logs.
Hellowlol commented 11 months ago

That’s correct. We do use median to calculate the mean. I have no idea why I ended up calling that attribute mean…

LAPDragnet commented 2 weeks ago

When both the daily average and the current spot price is negative, _price_percent_to_average is not calulated correctly. An even lower negative spot price will make _price_percent_to_average larger.

Erwiiinst commented 20 hours ago

I bumped into using mean incorrect due to its naming.

To avoid confusion for users, I kindly request that the attribute name be updated from “mean” to “median” to accurately reflect its function. Additionally, I recommend providing a clear notification about this change in the update notes to inform users who rely on the “mean” attribute, ensuring a smooth transition.

Thank you for your attention to this matter.

Kind regards, Erwin