Energy costs sensor resets after restart

Hi!
I have 2 entities that I use in an apexcharts-card to track the exported electricity and bought electricity.
Entities are:
sensor.grid_import_solar_daily_energy_cost
sensor.grid_export_solar_daily_energy_compensation

But every time I restart the raspberry, it resets the numbers.
What can I do about this? I need to have it 24 hours, then it can reset itself

1 Like

How are the sensors defined?

Which integration?

I have them in swipe-card and in that a apex card

type: custom:swipe-card
title: null
card_width: 90%
start_card: 1
parameters:
  effect: coverflow
  grabCursor: true
  centeredSlides: true
  slidesPerView: auto
  coverflowEffect:
    rotate: 110
    stretch: 90
    depth: 633
    modifier: 1
    slideShadows: true
  pagination:
    type: bullets
cards:
  - type: custom:apexcharts-card
    chart_type: pie
    header:
      show: true
      show_states: true
      colorize_states: true
      title: SÄld, Köpt & Producerad El
    apex_config:
      chart:
        height: 300px
      legend:
        show: true
      dataLabels:
        enabled: true
        formatter: |
          EVAL:function(value) {
            return value.toFixed(0) + "%";
          } 
    series:
      - entity: sensor.grid_export_solar_daily_energy
        name: SĂ„ld El
        color: lawngreen
        float_precision: 2
      - entity: sensor.grid_import_solar_daily_energy
        name: Köpt El
        color: red
        float_precision: 2
      - entity: sensor.daily_yield
        name: Totalt Producerad El
        color: deepskyblue
        float_precision: 2
  - type: custom:apexcharts-card
    chart_type: pie
    header:
      show: true
      show_states: true
      colorize_states: true
      title: Priser
    apex_config:
      chart:
        height: 300px
      legend:
        show: true
      dataLabels:
        enabled: true
        formatter: |
          EVAL:function(value) {
            return value.toFixed(0) + "%";
          } 
    series:
      - entity: sensor.grid_import_solar_daily_energy_cost
        name: Köpt Energi
        color: red
        float_precision: 2
      - entity: sensor.grid_export_solar_daily_energy_compensation
        name: SĂ„ld Energi
        color: lawngreen
        float_precision: 2

Not the card.

Can you explain what mean? Sorry I’m new with home assistant.

These sensors:

How were they made?

These come from the huawei inverter, they were hidden, but are connected to energy-sources-table
I also have nordpool added, and everything in the energy dashboard is correct, used electricity and sold electricity with floating nordpool price.
I just want to have those 2 in a card so i don’t need to go into the energy dashboard to see what I have sold and bought.

**


**

But it does not reset in the energy dashboard, just the card.
Or do you have any better suggestion how to get those 2 entities to a card with history so it doesnt reset.

Which integration?

Share your config for them if they are not discovered.

Integration is SUN2000-10KTL-M1SUN2000-12

Where do I find the config for them, talk to me like you are talking to a little child, with 0 knowledge about this :slight_smile:

That appears to be the inverter model number.

How did you make the sensors?

How did you connect the inverter to Home Assistant?

Here in the forum there is a tutorial, but i went into hacks and searched for huawei solar github link

The sensors are there, just hidden, i didn’t make them.

Only thing i did was to name them “sĂ„ld” “köpt”

I also noticed the same (and maybe to add some information to this post). With the new energy dashboard from some releases ago, in the latest release when setting up an energy sensors with a pricing entity linked to calculate costs, HomeAssistant also auto-creates new sensors named ‘Sensor cost’ with a price which seems to be like a meter entity that:

  • Resets once per day
  • Resets when HA restarts.

I guess second option can’t be changed as it might be some tracked cost in the portal, but my question is, any way to change when in the day does the sensor cost resets? It would be more useful to have it reset at midnight, to have the cost sensor direclty show the accumulated costs throughout the day.

I tired searching a bit about these automatically created sensors costs but couldn’t find much. Any link to docs or something would be very appreciated to understand them better!

Thanks

1 Like

Hi,
These sensors will be created, when you add tarifs to your energy dashboard.

In my Energy Dashboard, I have configured a price for Imported Energy and a price for exported energy.
HomeAssistant does generate these “monetary” sensors automatically:


But it seems, that they reset on reboot of the system.
As you can see, both sensors do have the same “last_reset” timestamp (except for some miliseconds)

Both have been resetted on October 27th (Thursday)

In this case, it seems that the sensors don’t use a fixed “reset” option like daily, weekly, monthly or something else
 which makes it a bit difficult to use them somewhere in a custom dashboard


Here’s the “history” for the “exported compensation”

as well as for the “imported costs”

Here’s a “zoom in” into the range from Oct. 27th 21:00 to Oct. 28th 02:00

I would really like to use these Sensors - but I would prefer to have them in the same form like other utility meters
 with “fixed” reset periods, like daily / weekly / monthly / quarterly / yearly

Atm, the only way I do see is to create custom sensors / templates / utility meters, where I need to set the price again - and then - calculate the prices / revenues by multiplikating the price with the exported / imported energy.
But when HA does already provide this kind of information in some way - I would prefer to use this one, instead of creating these entities manually.

I think I have solved it, at least for my self.
I created a helper (utility meter) Input sensor =one of the generated sensors.
Reset daily and that was it.
Now it has history so I can restart, and the history is still there.
Only problem I had was that I got 17-18 decimals
The way I fixed that was I made a sensor:

  totalt_spotpris_idag:
      friendly_name: Spotpris skulle ha kostat
      value_template: '{{ states("sensor.spot_test_reset_daily") | float | round(2)}}'       
      unit_of_measurement: "€"

This is with the helper i created, 17-18 decimals
image

And this is the results with the created sensor:
image

If someone have some improvements, feel free to share.

1 Like

yes, writing the data of the existing meter-sensor into a new one can be used as a workaround.
But the downside of this is:

You have two components doing exactly the same
 (the one without having a “bug”) - but I prefer if the team could fix the underlying issue :smiley: rather than working around it

I wonder if this has been addressed yet or if this is reported as an issue?
At least for my v2022.10.5 it still seems to be resetted


let me check, but I don’t think that it’ll be fixed

Edit:
The sensors still reset on reboot:

based on what I know, the state_class: total should be able to reset.
I think, the sensor is doing what it is supposed to do
 it does measure and it does save the “last reset”.

Therefore, I don’t think that raising an issue will change anything

Probably, the only way of getting this is really to create a template / helper “utility meter” that is inherited from the cost sensors.

Hhm, not sure if I understand correct:
If I look at my sensors, I see the cost sensor is reset but the corresponding production sensor not.

Is this really what it is supposed to do? I have no idea, what the idea or the use case for this behavior could be.
What is the idea to display an energy cost since last boot?

the production sensor has state class: total_increasing.
therefore, it does “never” reset.

The cost sensor - is another measurement sensor with state class: total.
The “total” state class is a sensor that requires a reset timestamp.
Therefore, - the sensor does behave as it has been designed (corresponding to the state_class)


The Discussion would be more about, if the desired state_class is the correct one, or if it should also be “total_increasing”


I don’t know, why the state_class “total” was choosen. Maybe, there’s a good reason for it


1 Like