Don't get the count right for historical data of sensor.power_production

Hello,

I’m trying to count the data of one day, starting from 00:00 till 23:59 of the sensor “sensor.power_production”. This sensor is giving the exact data of producing power to the grid. Can someone help me with the config to get the data of one day?

I tried the following configs but it didn’t work out well.

  - platform: history_stats
    name: real_sunpanel_grid
    entity_id: sensor.power_production
    state: 'on'
    type: 'count'
    end: "{{ now().replace(hour=0, minute=0, second=0) }}"
    duration:
      hours: 24

  - platform: statistics
    name: real_sunpanel_grid
    entity_id: sensor.power_production
    sampling_size: 86.400

  - platform: template
     daily_sunpanel_short:
      value_template: "{{ '%.3f'%(states('sensor.daily_sunpanel_deliver') | float) | float }}"
      unit_of_measurement: 'kWh'

Thanks a lot for an answer, cheers!

image

That is a power sensor (kW) not energy (kWh). You cant sum it. Also the history stats sensor does not work like that.

If your device has an energy sensor (unit of Wh or kWh) then feed that to a utility meter with a daily cycle.

Job done.

If your device does not have an energy sensor then convert the power sensor to an energy sensor using the Riemann Sum integration (integrating power with respect to time gives energy):

Then feed this sensor to the utility meter on a daily cycle.

Thanks a lot for this usefull information!! @tom_l i created the Riemann Sum integral, but i don’t get data in it. What i am doing wrong?

image

sensor:
  - platform: integration
    source: sensor.power_production
    name: energysun_togrid
    unit_prefix: k
    round: 2

Thanks a lot again!!!

Try this:

sensor:
  - platform: integration
    source: sensor.power_production
    name: energysun_togrid
    round: 2
    method: left

Also it won’t update until sensor.power_production updates a couple of times.

I think this is the solution. tommorow i know exactly. We now have the wasingmachine on and the dryer so all the sunpower is going to that machines. Thanks a lot @tom_l

1 Like

Just remember that sensor will keep counting up. The Utility Meter linked above can give you quarter hourly, hourly, daily, monthly, bi-monthly, quarterly or yearly totals.

Hi @tom_l

Today i’m looking into the graphs and it looks like it is not working after the daily cycle, see screenshots and code:

  - platform: integration
    source: sensor.power_production
    name: energysun_togrid
    unit_prefix: k
    round: 2
    method: left
utility_meter:
  daily_sunpanel_deliver_grid:
    source: sensor.energysun_togrid
    cycle: daily

image

image

image
And as you see this one gives also kkWh

Thanks a lot again

Look at my config. Then look at yours. Mine does not have:

    unit_prefix: k

It seems like it is working now!! The only thing is still kkWh but that doesn’t matter. I can trick that away! Thanks a lot for all @tom_l