BottlecapDave / HomeAssistant-OctopusEnergy

Unofficial Home Assistant integration for interacting with Octopus Energy
https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/
MIT License
535 stars 50 forks source link

Issue with Cost Tracker and increasing sensor resetting daily #759

Closed asuweb closed 4 months ago

asuweb commented 4 months ago

Describe the bug

Following discussion #747, believe there to a bug / unforeseen issue in logic of cost tracker.

Cost tracker set to track import meter, using entity sensor.solax_today_s_import_energy and another to track export meter.

image

As you'll see from the below screenshot and csv data, at 00:00 local, the entity being tracked sensor.solax_today_s_import_energy resets to zero as designed, and the cost tracker then goes to a negative value.

image

CSV of related data history.csv

state_class: total
last_reset: "2024-02-14T00:00:00+00:00"
name: agile_import_costs
mpan: "2700001188890"
target_entity_id: sensor.solax_today_s_import_energy
entity_accumulative_value: true
kind: cost_tracker
account_id: A-5D061854
is_tracking: true
tracked_charges:
  - start: "2024-02-15T00:00:00+00:00"
    end: "2024-02-15T00:30:00+00:00"
    rate: 0.116235
    consumption: -14.110000000000001
    cost: -1.6400758500000001
  - start: "2024-02-15T00:30:00+00:00"
    end: "2024-02-15T01:00:00+00:00"
    rate: 0.121065
    consumption: 0.03
    cost: 0.00363195
  - start: "2024-02-15T01:00:00+00:00"
    end: "2024-02-15T01:30:00+00:00"
    rate: 0.117285
    consumption: 0.32
    cost: 0.0375312
  - start: "2024-02-15T01:30:00+00:00"
    end: "2024-02-15T02:00:00+00:00"
    rate: 0.10584
    consumption: 0.91
    cost: 0.0963144
  - start: "2024-02-15T02:00:00+00:00"
    end: "2024-02-15T02:30:00+00:00"
    rate: 0.11025
    consumption: 0.3999999999999999
    cost: 0.04409999999999999
  - start: "2024-02-15T05:00:00+00:00"
    end: "2024-02-15T05:30:00+00:00"
    rate: 0.12306
    consumption: 0.020000000000000018
    cost: 0.002461200000000002
  - start: "2024-02-15T05:30:00+00:00"
    end: "2024-02-15T06:00:00+00:00"
    rate: 0.12411
    consumption: 0.26
    cost: 0.0322686
  - start: "2024-02-15T06:00:00+00:00"
    end: "2024-02-15T06:30:00+00:00"
    rate: 0.139335
    consumption: 0.30999999999999983
    cost: 0.04319384999999998
  - start: "2024-02-15T06:30:00+00:00"
    end: "2024-02-15T07:00:00+00:00"
    rate: 0.13671
    consumption: 0.22999999999999998
    cost: 0.031443299999999993
  - start: "2024-02-15T07:00:00+00:00"
    end: "2024-02-15T07:30:00+00:00"
    rate: 0.1323
    consumption: 0.010000000000000231
    cost: 0.0013230000000000305
  - start: "2024-02-15T07:30:00+00:00"
    end: "2024-02-15T08:00:00+00:00"
    rate: 0.15435
    consumption: 0.20000000000000018
    cost: 0.03087000000000003
  - start: "2024-02-15T08:00:00+00:00"
    end: "2024-02-15T08:30:00+00:00"
    rate: 0.12873
    consumption: 0.10999999999999988
    cost: 0.014160299999999983
  - start: "2024-02-15T08:30:00+00:00"
    end: "2024-02-15T09:00:00+00:00"
    rate: 0.14595
    consumption: 0.10000000000000009
    cost: 0.014595000000000014
  - start: "2024-02-15T09:00:00+00:00"
    end: "2024-02-15T09:30:00+00:00"
    rate: 0.138915
    consumption: 0.3999999999999999
    cost: 0.05556599999999998
  - start: "2024-02-15T09:30:00+00:00"
    end: "2024-02-15T10:00:00+00:00"
    rate: 0.139755
    consumption: 0.3999999999999999
    cost: 0.055901999999999986
  - start: "2024-02-15T10:00:00+00:00"
    end: "2024-02-15T10:30:00+00:00"
    rate: 0.1323
    consumption: 0.30000000000000027
    cost: 0.03969000000000004
  - start: "2024-02-15T10:30:00+00:00"
    end: "2024-02-15T11:00:00+00:00"
    rate: 0.125055
    consumption: 0.40000000000000036
    cost: 0.050022000000000046
  - start: "2024-02-15T11:00:00+00:00"
    end: "2024-02-15T11:30:00+00:00"
    rate: 0.12348
    consumption: 0.7999999999999998
    cost: 0.098784
  - start: "2024-02-15T11:30:00+00:00"
    end: "2024-02-15T12:00:00+00:00"
    rate: 0.12432
    consumption: 0.5999999999999996
    cost: 0.07459199999999995
  - start: "2024-02-15T12:00:00+00:00"
    end: "2024-02-15T12:30:00+00:00"
    rate: 0.12432
    consumption: 2.5
    cost: 0.3108
  - start: "2024-02-15T12:30:00+00:00"
    end: "2024-02-15T13:00:00+00:00"
    rate: 0.12705
    consumption: 3.200000000000001
    cost: 0.40656000000000014
  - start: "2024-02-15T13:00:00+00:00"
    end: "2024-02-15T13:30:00+00:00"
    rate: 0.12726
    consumption: 2.6999999999999993
    cost: 0.3436019999999999
  - start: "2024-02-15T13:30:00+00:00"
    end: "2024-02-15T14:00:00+00:00"
    rate: 0.13314
    consumption: 0.09999999999999964
    cost: 0.013313999999999953
  - start: "2024-02-15T15:00:00+00:00"
    end: "2024-02-15T15:30:00+00:00"
    rate: 0.143535
    consumption: 1.6000000000000014
    cost: 0.2296560000000002
untracked_charges: []
total_consumption: 1.790000000000001
unit_of_measurement: GBP
device_class: monetary
icon: mdi:currency-gbp
friendly_name: Octopus Energy Cost Tracker agile_import_costs

Reproduction steps

Create a cost tracker that tracks an accumulating sensor that resets daily

Expected behaviour

Expect that the cost tracker resets to zero daily

Tariff Code

E-1R-AGILE-23-12-06-F

Integration Version

10.1.0

Home Assistant Version

2024.2.1

Fresh Install?

Not specified

Home Assistant Logs

I've enabled and will update this issue tomorrow once the midnight reset has occurred.

Confirmation

BottlecapDave commented 4 months ago

Thanks for the issue, and sorry you're encountering it. I'll try and take a look when I can.

BottlecapDave commented 4 months ago

Hello. This should hopefully be fixed in v10.1.1. Please confirm when you can :)

billmichell commented 4 months ago

Downloaded and new cost tracker created. We shall see when it resets at midnight!

billmichell commented 4 months ago

Looking good

asuweb commented 4 months ago

Many thanks for the quick fix. I can confirm this has now been resolved and is working as expected

BottlecapDave commented 4 months ago

Closing as this looks like it's fixed now.