home-assistant / frontend

:lollipop: Frontend for Home Assistant
https://demo.home-assistant.io
Other
4.08k stars 2.8k forks source link

Energy Usage Cost is completely wrong. #14249

Closed issmirnov closed 1 year ago

issmirnov commented 2 years ago

Checklist

Describe the issue you are experiencing

I enabled the Energy dashboard, and added 4 smart plugs (same make and model). The "Sources" chart is showing completely incorrect cost numbers.

image

All 4 entities have the cost set to $0.12/kwh. The first value of 5.76kwh should show $0.69, not $1.01. The other values are similarly incorrect.

There also appears to be a rounding error, as the total costs are off by $0.01

Describe the behavior you expected

Math should work correctly.

Steps to reproduce the issue

  1. Link 4 smart plugs
  2. Set price per kwh
  3. View http://homeassistant:8123/energy and verify math

What version of Home Assistant Core has the issue?

2022.10.5

What was the last working version of Home Assistant Core?

No response

In which browser are you experiencing the issue with?

Google Chrome 107.0.5304.87

Which operating system are you using to run this browser?

Arch Linux

State of relevant entities

`sensor.elude_cluster_total_daily_energy`: 2.208

state_class: total_increasing
unit_of_measurement: kWh
device_class: energy
friendly_name: Elude Cluster Total Daily Energy

sensor.elude_cluster_total_daily_energy_cost: 0.265079999999995

state_class: total
last_reset: 2022-10-31T06:00:00.026737+00:00
unit_of_measurement: USD
device_class: monetary
friendly_name: sensor Cost

### Problem-relevant frontend configuration

```yaml
# Custom sensor for xcel energy
# https://co.my.xcelenergy.com/s/billing-payment/residential-rates/residential-opt-out-pricing
template:
  - sensor:
    - platform: time_date
      display_options:
        - 'time'
        - 'date'
        - 'date_time'
        - 'date_time_utc'
        - 'date_time_iso'
        - 'time_date'
        - 'time_utc'
        - 'beat'
  - sensor:
      - name: "Current Electricity Rate"
        unit_of_measurement: "USD/kWh"
        device_class: monetary
        state: >
            {% set month = now().month %}
            {% if month in [10, 11, 12, 1, 2, 3, 4, 5] %}
             0.12
            {% elif month in [6, 7, 8, 9] %}
             0.14
            {% endif %}

### Javascript errors shown in your browser console/inspector

```txt
390f9167.js:1 RangeError: Invalid currency code : USD/kWh
    at new NumberFormat (<anonymous>)
    at n (390f9167.js:1:35205)
    at h (973fa28d.js:1:4242)
    at m (973fa28d.js:1:3920)
    at F.value (hui-sensor-entity-row.ts:72:1)
    at F.update (styles.ts:370:1)
    at F.performUpdate (styles.ts:370:1)
    at F.scheduleUpdate (styles.ts:370:1)
    at F._$EC (styles.ts:370:1)

styles.ts:370 Error: <path> attribute d: Expected number, "…   0 1,\n        NaN NaN\n    ".
k @ styles.ts:370
styles.ts:370 Error: <path> attribute d: Expected number, "…   0 1,\n        NaN NaN\n    ".

Additional information

Given the error message and my custom config, I'm wondering if perhaps the "USD/kWh" is throwing things off?

github-actions[bot] commented 1 year ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.