How to create daily energy sensor

How did you solve this challenge, getting the daily production and consumption information?

In my case the 4 sensors doesn’t give the daily generation but the total, since the measuring started, consumed and produced.

Use the utility meter helper with a daily cycle:

Thanks, that was the tip I needed to create the daily grid measurement counters. Thanks.

1 Like

As suggested I’ve created a Utility Meter for daily consumption and production measurement. I’ve noticed something strange. The default energy dashboard in HA has a different value for P1-Electricity Energy consumption (tarif 2) compared to the sensor I’ve created. Why is there a difference? I’ve been searching but not found anything so far. Suggestions? See also screenshort.

The value from the HA Energy dashboard

The value from the utility meter I’ve created.:

What did you set the utility meter cycle to?

Daily, but I cannot find that configuration setting anymore. Strangly enough.

I can see the results from the Daily config as in the graphic (see screenshot) it dropped to zero at midnight.

Could it be the source sensor sometimes resets to 0 for a short while (for instance when an integration is unavailable)?

Well then you would expect a lower value. But the value of my Utility sensor has a higher value compared to the one in the HA Energy dashboard.

Is it possible to use the sensors from the HA standard Energry dashboard in other dashboards and automations?

Now the differences is not that big anymore, strange,


No, you’d not get a lower value. Due to the periodically resetting setting, when the source goes from 0 to its real value again, all of that (so the entire total) is counted as new production, becaue it is assuming you got yourself a brand new meter. That is a very useful feature, but can bite you too.

This shortly 0 behaviour would happen if you for instance use a template sensor that has float(0) in there somewhere, without using an availability template to make sure it goes unavailable instead of to 0.

The reason I think that is it is because the weird value is very high compared to the graph.

The dashboard uses statistics, there’s no dayly counter in there.

The DSMR meter is not new, running for many years already but only now start playing with my own dashboard config.

I’ve created another Template which uses the tarif 1 and tarif 2 Utility sensors to calculate the total daily energy consumption from grid. I’m using float(3) in this, this could be wrong. To be honest I don’t exactly knows what float(0) or float(3) does. I assume it is calculation with digits behing the comma.

{{ ((states(‘sensor.daily_grid_consumption_tarif_1’)|float(3) + states(‘sensor.daily_grid_consumption_tarif_2’)|float(3)) ) | round (3) }}

Well, it is not digits behind the comma for sure. float(3) says: convert a string to a float ( a numerical value with decimals), when you cannot (for instance because the string is “unavailable”) then use the default value 3 instead.

So what could happen is: the total is 1000. then it goes unavailable, so the template says: lets assume it is 3. Then Utility meter thinks, oh, you got a new meter from the energy company, so it the real total is 1000 + 3 (the old meter plus the new meter), and the utility meter adds the 3 as new use. Then the sensor is available again, so the template jumps to 1000 again. Then utility meter sees it jump from 3 to 1000 and the utility meter adds yet another 997.

Unfortunately, the only solution for this is to use an availability sensor. You cannot do that in the template sensor from the gui, it can only be done in a yaml sensor.

But if you are not using the template as a base, this might not be it, or the dsmr integration is implemented badly, but lets not assume that just yet.

I also assume the utility meter was not created today? because as the docs state, the first day will be rubbish (utility meter does not know what the value whas before it was created), it will only work right from the next day, after the first dayly reset.

Will change it to float(0), thanks for the explanation.
Indeed the DSMR is not installed today, already many years ago. The HA Enegry dashboard is displaying the correct values.

The availability sensor is not yet clear for me what you mean with that and how to set it up.

But the float(3) doesn’t explain/clarify what the Tarif 2 sensor has a different value. In that Utility sensor there is no float(3). It simply takes the value from the DSMR device in an Utility format with a daily reset.

The availability template is a setting for a template sensor to explain when it is available or not available. You can use it to make sure the sensor is unavailable when you lack the information you need to calculate the result.

Aha, I’ve read about it indeed. And seen it as well. You can use something like is_available…

This is an example where I use the availability template (to convert the unit of a sensor from kWh). It basically copies the value. I could not convert yours easily as it is a screenshot:

- sensor:
    - name: "Water totaal"
      unique_id: sensor.water_totaal
      availability: "{{ is_number(states('sensor.extra_total')) }}"
      state_class: total_increasing
      device_class: water
      unit_of_measurement: m³
      icon: "mdi:water"
      state: "{{ states('sensor.extra_total') | float(0) }}"

As the Sun starts shining (a bit) the Solar start generating energy, I’ve similar differences for this sensor/utility as well.

My created sensor indicates 0.274 kWh:

The Home Assistant Energy Dashboard indicates 0.04 kWh.

I’m using the GUI to create/update the template, where can I find the sensors in the yaml code?

The by the GUI created template sensors are not in the sensors.yaml file.