Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cost-only sensor gets reset to 0 after Home Assistant reboot #90

Open
catshapednoodles opened this issue May 22, 2024 · 3 comments
Open
Labels
help wanted Extra attention is needed

Comments

@catshapednoodles
Copy link

catshapednoodles commented May 22, 2024

Version of the custom_component

v1.1.0

Configuration

energy_meter:
  boiler_energy_meter:
    source: sensor.boiler_energy
    name: Boiler Energy
    price_entity: sensor.day_ahead_price
    create_utility_meter: true
  test_1:
    source: sensor.boiler_energy
    name: Energy Meter Test 1
    price_entity: sensor.day_ahead_price
    create_utility_meter: false

Describe the bug

In my configuration listed above I've created two sensors based on the same energy sensor ('sensor.boiler_energy'). The first also creates a utility meter sensor, and the second doesn't. The first costs sensor works correctly, with costs that keep getting higher and never resetting to 0. The second sensor keeps getting reset to 0 after a Home Assistant reboot:
image

I've looked at the behavior of the energy sensor that I use ('sensor.boiler_energy'), and after a reboot it goes through these stages:

  • Non-existent (it only gets loaded when the MQTT integration is loaded)
  • Existing with state 'unavailable'
  • Existing with state 'unknown'
  • (At some point Home Assistant is done with the startup)
  • After the sensor reports back for the first time it gets an actual numerical value

The costs-only sensor ('sensor.boiler_energy_day_ahead_price_cost') has these stages:

  • Non-existent (the Energy Meter integration gets loaded after MQTT for me, though)
  • Existing with state 'unknown' (at this point the energy sensor also has state 'unknown')
  • (At some point Home Assistant is done with the startup)
  • After the sensor reports back for the first time it gets an actual numerical value, which is always 0

This is after Home Assistant says it's done with the start up (see the first and the last sensor in the screenshot):
image

Then after the first sensor gets a numerical value, the second (energy meter cost) sensor also gets a value. Unfortunately it's gone back to 0:
image
In the screenshot it's actually higher than 0, but that's because I was late taking a screenshot and the energy sensor got a new value. The 'last_reset' attribute is actually when my last restart happened, so the sensor also gets reset for some reason.

I think the energy meter sensor gets tripped over the 'unknown' state, but I'm not really sure.

The energy sensor that I use is a TuYa TS0121 plug, connected via Zigbee2MQTT.

NB: As you can see, the name of the cost-only sensor is also wrong. It's just 'sensor Cost' instead of the name I gave it in the configuration. That doesn't bother me as much, since you can just easily change it in the UI.

Debug log


2024-05-22 19:04:45.640 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter.boiler_energy_meter
2024-05-22 19:04:45.640 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter.boiler_energy_meter: skip utility_meter select entity
2024-05-22 19:04:45.640 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter.boiler_energy_meter: create a single utility_meter sensor
2024-05-22 19:04:45.641 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter: setup energy cost sensor of type from_grid
2024-05-22 19:04:45.641 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter: create energy cost sensor for entity sensor.boiler_energy
2024-05-22 19:04:45.641 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter.boiler_energy_meter_cost: create a single utility_meter sensor
2024-05-22 19:04:45.642 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter.test_1
2024-05-22 19:04:45.642 DEBUG (MainThread) [custom_components.energy_meter] Setup energy_meter: setup energy cost sensor of type from_grid

@yuntian123456
Copy link

the same thing happend to me, it always show "unknown", never updated.

@zeronounours
Copy link
Owner

Hello, the resetting behavior on the cost is normal. It is the behavior of HA on energy costs. The last_reset is managed by the recorder correctly when doing long term stats.

I advise you to use https://github.com/zeronounours/lovelace-energy-entity-row to display costs, or similar components. It relies on long term stats to show costs over the selected period

@zeronounours
Copy link
Owner

@yuntian123456, if the state stay "unknown", you should check the state of:

  • your energy sensor
  • your price sensor

Do they both have valid values?

@zeronounours zeronounours added the help wanted Extra attention is needed label Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants