How to calculate daily power consumption from DSMR sensors?

If you want to combine the scripts make sure you use the same sensor names. Looks like iMartien uses the sensor name for todays normal power consumption

power_consumption_today_normal

, while gdschut uses the sensor name

todays_power_consumption_normal

1 Like

tried again to use totals, now it works :face_with_raised_eyebrow:

Hi Guys, don’t know if you’ve seen this, but sinds 0.87 you can just use the Utility Meter component: https://www.home-assistant.io/components/utility_meter/ (see end of page for an example in combination with DSRM)

4 Likes

This is a great function and saving me lot’s of time.
In properties I see there is also the value from yesterday (last period) stored.

Is there a way to access this value and display it prpoerly?

daily

template sensor

sensor:
- platform: template
  sensors:
    yesterday_consumption:
      friendly_name: Yesterday Consumption
      value_template: "{{ state_attr('sensor.daily_consumption','last_period') }}"
      unit_of_measurement: kWh

Assuming that last period is the attribute last_period.

Great - Thanks a lot. Very nice:
daily

I need to spend some time on friendly names obviously…

Hello, great project.

What are the best sensors to track solar energy production + energy consumption?

Thank you

Sorry for the late answer.
I believe everybody is using different sensors. I have the SMA Energy Meter 2.0 which is an (expensive) option with SMA PV converters.
Cheers, Jens

You can tell me how to use with Sonoff Pow (tasmota firmware). It has yesterday consume by default.
What i need to track, current energy or yesterday?

Dear all, I also have the mqtt power consumption meter. How often you read the consumption?
What time interval is the best solution, between accuracy and less reading.

I use the code below to calculate yesterday’s low and normal tarif. It doesn’t work I get a state unknown. What am I doing wrong?

    yesterday_power:
      friendly_name: Yesterday Power
      unit_of_measurement: kWh
      value_template: "{{ state_attr('sensor.daily_power_offpeak','last_period')|float + states('sensor.daily_power_peak','last_period')|float }}"

Wrong method, should be state_attr, like the first method.

1 Like

Hm forgot that one, Thanks @petro it works now.

Hi @petro, is it correct to say that by putting max age for an hour, I will have the live power consumption in kWh ?

Only if your device is outputting momentary KW

My device is outputting W, it is a Meross MSS310 plug.

then your result would be Wh

1 Like

I am rethinking the calculation I did and it seems wrong.
Here are my thoughts:
By creating this variable, as it sums up the past hour W, and keeps going the next minute and the next minute again, it seems that it will include W consumption more than one time in the calculation. To me, the Wh evaluation will be over estimated, using this method. Am I right?
However, calculating it per day, and resetting at midnight, it seems it will be correct.

Hi @iMartien, this is a great link! Do you know if the sensor should provide W or Wh?

No, its a summation of the past hour only. So when the new minute 1 is added the old minute 61 is removed.