Energy Cost Calculation went haywire after 2022.8

This looks different to my setup.

Here is my sensor

  - sensor:
      - name: Tariff Price
        unit_of_measurement: AUD/kWh
        state: >
            {% if is_state('utility_meter.daily_energy', 'DE_Peak') %}
                {{ 0.52872 * 0.8 }}
            {% elif is_state('utility_meter.daily_energy', 'DE_Shoulder') %}
                {{ 0.25247 * 0.8 }}
            {% elif is_state('utility_meter.daily_energy', 'DE_OffPeak') %}
                {{ 0.17704 * 0.8 }}
            {% else %}
                {{ 0.17704 * 0.8 }}
            {% endif %}

  - sensor:
      - name: Tariff Price Export
        unit_of_measurement: AUD/kWh
        state: >
                {{ 0.076 }}

and here is what mine looks like in dev tools

and here is what it looks like in dashboard

image

image

image

1 Like

Hi del13r,
Thank you for the guide to get the energy dashboard working! and helping with my question. Yes we are credited at retail rate so 1:1 for us which was a pleasant surprise after seeing what others are getting.

1 Like

I noticed your entity starts with input_number. instead of sensor.
I have no experience with input_number type of entity.

Wow, that is nice. We get 8c//kWh for feed in and 15 to 30c/kWh use (off-peak and peak).

I use an input number. It works fine.

For the record, everything you have posted so far looks functionally correct apart from the $ figure shown on the energy dashboard.

If i had to guess that $490 figure is close to your total lifetime credit given the export sensor is around 1200kwh (average price around $0.40)

Unfortunately I don’t think that was it. Here are three hours of costs compared.


Rate was $0.52 from above to below. 2.76kWh X $0.52 = $1.43 not $11.20

Rate was $0.33 from above to below. 10.56kWh X 0.33 = $3.48 not $31.40

I’ll keep an eye on it tomorrow perhaps it needs a fresh start?

That’s good too know. I’m not sure what it could be anymore at first it seemed like it a simple rounding error. See This Reply for updated costs over a 3 hour period.

While hunting around I did notice these sensors that go back to 0 whenever I reboot home assistant

I don’t remember creating these sensors, so perhaps energy dashboard creates them for use by energy dashboard

Maybe check what these are doing.

The names will probably be different for you. Try searching for _compensation and _cost

This is correct. I have the compensation one but not the cost one because I use my own sensor calculating the total cost. This means HA doesn’t need to do any further calculations for my cost, but for compensation I have a flat rate configured in the energy dashboard and therefore HA needs to calculate the total itself.

The compensation and cost sensors should be identical to the entity name used in the energy dashboard but with cost/compensation on the end.

@cjueden would be interesting to see what your two sensors look like in developer tools > states

I stumbled upon those as well once and assumed the same as you did. Mine never seem to reset except for one day at 12:00 I may have force them to 0 in the dev tools on that day.

Interesting I seem to have a second set of the sensors with a suffix of the number 2

I can see at least 5 resets on this graph.

1 reset on the 4th.
2 resets on the 7th.
2 resets on the 8th.

You’re right! I checked the chart and all resets went to 0 for the import.

Those number look correct for today right?

I’m not sure what it’s supposed to look like. But the cost on the dashboard is still wonky.

ballpark they look about right though.

If you search in developer tools>states for $474.20 (or whatever the current value is) or alternatively just for “compensation” do you find another sensor with that incorrect value?

If you can stomach starting from scratch I think the easiest fix is to edit the energy dashboard and delete the current import and export sensors from it. Restart HA then add them a back in. I think HA is hanging onto an old or incorrect sensor for an unknown reason. Did you change the energy dashboard configuration at all recently?

I’m unable to find any thing in developer tools>states with the $ or any combo of -$474

I’ve change all sorts of things back and forth for a couple weeks now trouble shooting, and have already lost a lot of data. Hoping I can figure out how to import it from my utilities export or a Enphase export at a later date. :crossed_fingers:
I was thinking of spinning up a fresh DB. Would that help HA lose a incorrect association it’s making?

Yeah sorry it won’t start with $, just the numbers, try 47

I was thinking of spinning up a fresh DB. Would that help HA lose a incorrect association it’s making?

Yes that is one solution, deleting the DB.

The energy dashboard stores data in a column called sum in table called statistics.
It records the difference in the value of the sensor every hour (as state column) and and then adds that difference to the sum column.
Statistics update hourly.

I have SQLite web add on installed

Here is the query I used to display the table below.

You will need to find the correct id’s for your own sensors by first displaying the content of the statistics_meta table.

SELECT *
FROM "statistics"
Where metadata_id IN (37,41)
Order by id desc

The sum of 247 is the total amount of compensation from the first day that energy dashboard started recording.

The sum of 717 is the total amount of cost from the first day that energy dashboard started recording.

1 Like

Nothing for 47. But a phone that needs to be charged soon

I guess I might have to try that.