zeronounours / HA-custom-component-energy-meter

Provides extended features on top of utility-meter to track costs for each tariff as well as total costs
MIT License
19 stars 2 forks source link

Cost reading record large increase each time Home assistant is restarted #69

Open alfwro13 opened 8 months ago

alfwro13 commented 8 months ago

Version of the custom_component

v.1.1.0

Configuration

energy_meter:
  daily_energy:
    source: sensor.octopus_energy_electricity_current_accumulative_consumption
    unique_id: agile_daily_energy_um
    name: Agile Daily Electricity Energy
    cycle: daily
    price_entity: sensor.octopus_energy_electricity_current_rate
  weekly_energy:
    source: sensor.octopus_energy_electricity_current_accumulative_consumption
    unique_id: agile_weekly_energy_um
    name: Agile Weekly Electricity Energy
    cycle: weekly
    price_entity: sensor.octopus_energy_electricity_current_rate
  monthly_energy:
    source: sensor.octopus_energy_electricity_current_accumulative_consumption
    name: Agile Monthly Electricity Energy
    unique_id: agile_monthly_energy_um
    cycle: monthly
    price_entity: sensor.octopus_energy_electricity_current_rate

Describe the bug

Every time Home assistant is restarted cost energy meter entities record large increase (by around £2.4) . For example today my "Agile Daily Electricity Energy Cost is £0.42. I have restarted HA and it jumped to £2.83. I use the Utility meter calibrate service to manually change it to the correct value. Here is a screenshot: image

This started happening at around the beginning of December 2023 prior to that this was working fine. As for my setup I run Home Assistant OS. HAOS, Supervisor and HA are always updated to the latest version usually within days of it being released. Currently running version HA Core v2024.1.6 This is only affecting the cost entities, energy consumption entities are fine.

Debug log

2024-02-06 13:33:51.978 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter.daily_energy
2024-02-06 13:33:51.978 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter.daily_energy: skip utility_meter select entity
2024-02-06 13:33:51.978 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter.daily_energy: create a single utility_meter sensor
2024-02-06 13:33:51.978 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter: setup energy cost sensor of type from_grid
2024-02-06 13:33:51.978 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter: create energy cost sensor for entity sensor.octopus_energy_electricity_current_accumulative_consumption
2024-02-06 13:33:51.978 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter.daily_energy_cost: create a single utility_meter sensor
2024-02-06 13:33:51.978 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter.weekly_energy
2024-02-06 13:33:51.978 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter.weekly_energy: skip utility_meter select entity
2024-02-06 13:33:51.978 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter.weekly_energy: create a single utility_meter sensor
2024-02-06 13:33:51.978 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter: setup energy cost sensor of type from_grid
2024-02-06 13:33:51.978 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter.weekly_energy_cost: create a single utility_meter sensor
2024-02-06 13:33:51.978 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter.monthly_energy
2024-02-06 13:33:51.978 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter.monthly_energy: skip utility_meter select entity
2024-02-06 13:33:51.978 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter.monthly_energy: create a single utility_meter sensor
2024-02-06 13:33:51.978 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter: setup energy cost sensor of type from_grid
2024-02-06 13:33:51.978 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter.monthly_energy_cost: create a single utility_meter sensor
2024-02-06 13:33:51.978 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter.agile_daily_export
2024-02-06 13:33:51.978 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter.agile_daily_export: skip utility_meter select entity
2024-02-06 13:33:51.978 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter.agile_daily_export: create a single utility_meter sensor
2024-02-06 13:33:51.978 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter: setup energy cost sensor of type from_grid
2024-02-06 13:33:51.978 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter: create energy cost sensor for entity sensor.shellyem_channel_1_energy_returned
zeronounours commented 7 months ago

Hello, @alfwro13, so far, I only have suppositions on the cause of your issue. My best idea is that your source energy sensor is not providing accurately the availability status which cause issues upon restart.

Can you:


The change you've noticed is probably due to https://github.com/home-assistant/core/commit/46d626280e884632b63fdce1b8601be91eb31842. Prior to this, the energy cost sensor started monitoring with both energy and price sensor were ready. Now it starts only when energy sensor is ready.

I suppose the following sequence happens for you on startup :

  1. Your energy sensor become ready, but with value 0
  2. The energy_meter is loaded, creating the energy cost sensor: because the energy sensor is ready, it starts accumulating costs
  3. Your energy sensor restore its previous, good value, lets says 1000 kWh
  4. The energy cost sensor seeing this increase will consider it's a new consumption causing the jump of £2.83
  5. Only then the utility meters are loaded

If such, you might also find out a pike to 0 in the graph of the energy sensor