Yesterday energy consumption in Esphome

Hello,

I have pzem-004t v1 connected to wemos D1 mini with esphome on board and it works really good. I wrote with help of utility meter integration daily and monthly energy consumption and they work flawlessly :slight_smile: I wonder if I can also make sensors which will show previous month or at least yesterday energy consumption (I can’t see that in utility meter options and I don’t want make any graphs with that). If I remember good in Tasmota firmware with pzem it could show yesterday power consumption (so is it possible also with ESPhome?).

Thank you in advance for any tips :slight_smile:

Ok, I made it :slight_smile:
If anyone would like to do it the same with yesterday energy consumption that’s how I solved it:

I made an input number which I switched to a sensor:

energia_wczoraj:
  name: Energia Wczoraj
  mode: box
  min: 0
  max: 99999999999
  step: 0.001
  unit_of_measurement: "kWh"
  icon: mdi:counter
  - platform: template
    sensors:
      energia_wczoraj:
        friendly_name: 'Energia Wczoraj' 
        entity_id:
          - input_number.energia_wczoraj
        value_template: "{{ states('input_number.energia_wczoraj')|float|round(3) }}"
        unit_of_measurement: "kWh"   

Next, I wrote a code in my automations.yaml. “sensor.l1_energia_dzienna” is a utility meter which shows energy consumption from today.

- id: yesterday_energy_use
  alias: 'Energia Wczoraj - przepisanie danych'
  trigger:
    platform: time
    at: '23:59:59'
  action:
  - service: input_number.set_value
    data_template:
      entity_id: input_number.energia_wczoraj
      value: "{{ states('sensor.l1_energia_dzienna')|float }}"

So overall, at 23:59:59 each day data from today’s energy consumption are re-written to sensor.energia_wczoraj .

1 Like

Where do I put first two code blocks? Could you also share code for sensor.l1_energia_dzienna?

1 Like