How to calculate monthly energy consumption (adding day by day sensor value)?

I do have an efergy sensor which is not working, every time it restarts the sensor switches the daily with monthly value making it unusable.

Beside fixing the efergy component, I wish to unsderstand how to calculate a weekly/monthly energy consuption having a daily value sensor.

The sensor each day at 2am starts again from zero and starts accumulatew the energy consumption value for the day, then again at 2am goes back to zero.

Wish to know how to “accumulate” the daily value to have a sensor, or something showing a weekly, biweekly, (weekdays, weekends) monthly value

Hi @anon35356645

You can have a look an EmonPI (send W data from the individual sensors to EmonPI, then get back accumulated kwh data as other sensors).

As an alternative, here is my WIP project Basically I’ve set sensors for daily, weekly, monthly and yearly which are adding the current values to previous balances which are actualized at 30 seconds. I’ve then setup an automation that renews the monthly figures. There is still a lot of work to be done (not difficult but I got lazy after setting the new month automation) such as to create automation for starting a new day, new week, new year, etc. create an easy to use mechanism to link current existing sensors to the mqtt ones; split the sensors between real time reporting sensors (measured through wall power switches) and nominal consumption sensors (such as the ones from the light bulbs for which it doesn’t make sense to have an actual counter), etc.

#Sensors

- platform: mqtt  
  state_topic: "powerconsumption/tv/today"
  name: 'today tv kwh'  
  unit_of_measurement: 'kwh'
- platform: mqtt  
  state_topic: "powerconsumption/tv/wtd"
  name: 'week tv kwh'  
  unit_of_measurement: 'kwh'
- platform: mqtt  
  state_topic: "powerconsumption/tv/mtd"
  name: 'month tv kwh'  
  unit_of_measurement: 'kwh'
- platform: mqtt  
  state_topic: "powerconsumption/tv/ytd"
  name: 'year tv kwh'  
  unit_of_measurement: 'kwh'

#Automations

- alias: power tv
  initial_state: 'on'
  trigger:
    - platform: time
      seconds: '/30'
  action:
    - service: mqtt.publish
      data_template:
        topic: "powerconsumption/tv/today"
        payload: '{{(states.sensor.today_tv_kwh.state | float + (states.sensor.tv_watts.state | float /120000))|round(5)}}'
        retain: true
    - service: mqtt.publish
      data_template:
        topic: "powerconsumption/tv/wtd"
        payload: '{{(states.sensor.week_tv_kwh.state | float + (states.sensor.tv_watts.state | float /120000))|round(5)}}'
        retain: true
    - service: mqtt.publish
      data_template:
        topic: "powerconsumption/tv/mtd"
        payload: '{{(states.sensor.month_tv_kwh.state | float + (states.sensor.tv_watts.state | float /120000))|round(5)}}'
        retain: true
    - service: mqtt.publish
      data_template:
        topic: "powerconsumption/tv/ytd"
        payload: '{{(states.sensor.year_tv_kwh.state | float + (states.sensor.tv_watts.state | float /120000))|round(5)}}'
        retain: true

- alias: tv kwh new month
  initial_state: 'on'
  trigger:
    - platform: time
      at: '00:00:24'
  condition:
    condition: and
    conditions:
      - condition: template
        value_template: '{{ now().day == 1 }}'
  action:
    - service: mqtt.publish
      data_template:
        topic: "powerconsumption/tv/m{{now().month}}y2018"
        payload: '{{(states.sensor.month_tv_kwh.state | float)}}'
        retain: true

undesrtand you perfectly :stuck_out_tongue:

that’s cool, will check if possible to use only the software

You could build an automation that triggers when the sensor value is set to 0 (zero). And store the previous value (which will be the day total) in a template sensor. If you record long enough history, you could use some statistical sensor to compute totals.

basically every 30 seconds you add to the actual KWh, the W /120000, correct? Then at the end of the day you should put the KWh to zero

I have my reading every 10 seconds, so I have to divide by 360?

Formula is “power (W) × t (h) / 1000” so if using a 10 s interval ( thus t(h)=10/3600 ) you need to divide W by 360.000.

1 Like