How do I reset an Energy sensor value created by ESPHome?

Ok, Google was no help here,

I have an ESPHome defined Pzemac current/energy sensor that I need to reset all previous historic measurement values to zero. How can I do this?

sensor:
  - platform: pzemac
    current:
      name: "RV1 Energy Monitor Current"
    voltage:
      name: "RV1 Energy Monitor Voltage"
    energy:
      name: "RV1 Energy". <---- I WANT TO RESET THIS VALUE
    power:
      name: "RV1 Energy Monitor Power"
    frequency:
      name: "RV1 Energy Monitor Frequency"
    power_factor:
      name: "RV1 Energy Monitor Power Factor"
    update_interval: 10s

pzemac.reset_energy Action

This action resets the total energy value of the pzemac device with the given ID when executed.

on_...:
  then:
    - pzemac.reset_energy: pzemac_1

As written in the docs:

Ok, I was being too literal in reading the doc. I think what it says is there needs to be some action that triggers the reset. In light of this revelation, I added this to the top of my config file:

esphome:
  name: energy-monitor-house
  on_boot:
    then:
      - pzemac.reset_energy: energy_monitor_house

sensor:
  - platform: pzemac
    current:
      name: "RV1 Energy Monitor Current"
    voltage:
      name: "RV1 Energy Monitor Voltage"
    energy:
      name: "RV1 Energy". <---- I WANT TO RESET THIS VALUE
    power:
      name: "RV1 Energy Monitor Power"
    frequency:
      name: "RV1 Energy Monitor Frequency"
    power_factor:
      name: "RV1 Energy Monitor Power Factor"
    update_interval: 10s

But one again I cannot figure out how to get the ID right. Does it need to be defined somewhere? I tried all permutations above with no luck.

I’ve also tried:
pzemac.reset_energy: pzemac
pzemac.reset_energy: pzemac_1
pzemac.reset_energy: pzemac_RV1_Energy
pzemac.reset_energy: pzemac.RV1_Energy
And
pzemac.reset_energy: RV1_Energy

Once I crack the ID mystery, I think it will reset on boot. Then I can remove those lines and upload again.

I see lots of folks struggling with this and no success…

You need to set it on your own, like:

    energy:
      name: "RV1 Energy". <---- I WANT TO RESET THIS VALUE
      id: energy_monitor_house

You can read more how ID’s work in the docs:

I’m really struggling with this.
I added an ID to the sensor and it compiled ok, but the sensor is not resetting…

esphome:
  name: energy-monitor-house
  on_boot:
    then:
      - pzemac.reset_energy: RV1
#----------------------------------------
sensor:
  - platform: pzemac
    id: RV1
    current:
      name: "RV1 Energy Monitor Current"
    voltage:
      name: "RV1 Energy Monitor Voltage"
    energy:
      name: "RV1_Energy"
    power:
      name: "RV1 Energy Monitor Power"
    frequency:
      name: "RV1 Energy Monitor Frequency"
    power_factor:
      name: "RV1 Energy Monitor Power Factor"
    update_interval: 10s
    ```

You shouldn’t! :wink:

Not helpful…

Didn’t saw the new logs and new yaml (your edited post) but just the old one that didn’t compile… :point_up:

Guess what happens (now) is that the command to reset the energy counter is issued before the pzem is actually ready for communication.

Two things you could do about that, one is adding a delay in the on_boot action the other is just to have the action in a template button so you can hit it yourself.

And I think that energy needs it’s own id (but I can also be mistaken), like I suggested :point_up:

Sorry… you’re too quick on the draw! I sincerely appreciate the help.

This fails. If I keep it here it compiles:

sensor:
  - platform: pzemac
    id: RV1
    energy:
      name: "RV1 Energy"
#      id: RV1

I’ll see if I can figure out a delay and try that. Christ this stuff is convoluted. I just want to reset a frigging value. It shouldn’t be this complicated.

2 Likes

Finally… success. You were right about the delay. I NEVER would have gone there. I marked your idea as “the solution”.

This worked:

esphome:
  name: energy-monitor-house
  on_boot:
    then:
      - delay: 5s
      - pzemac.reset_energy: RV1

3 Likes

Another “solution” (more of a work’a’round) actually would just to use a software counter in esphome, like total_daily_energy

But the good thing with the counter in the pzem004t (which is stored in eeprom) is that even if the esp is not working/powered it will continue counting the energy - like a fail safe solution. :muscle:

I actually also make heavy use of the utility_meter in ha to sum up my consumption :slot_machine:

Hi,
it is actually quite simple. Code below.

It will create a button in WebUI and at the same time a button entity in HASS.
Just click it to reset.

Tested and working

sensor:
  # We will use pzemac or pzem004t depending on whether we are using a PZEM-004T V3 or V1
  - platform: pzemac
    id: pzemac_1
    current:
      name: "AC_proud"
    voltage:
      name: "AC_napeti"
    energy:
      name: "AC_spotreba"
    power:
      name: "AC_Prikon"
    frequency:
      name: "AC_frekvence"
    power_factor:
      name: "AC_ucinik"
    update_interval: 10s

button:
  - platform: template
    name: "kWh reset"
    on_press:
      - pzemac.reset_energy: pzemac_1
1 Like

ok, Im not getting this at all - Im having a brain bloc on buttons. I “think” I’ve defined 2 buttons in button.yaml.

#button:
  - platform: template
    name: "RV1 kWh reset"
    on_press:
      - pzemac.reset_energy: RV1
  - platform: template
    name: "RV3 kWh reset"
    on_press:
      - pzemac.reset_energy: RV3

Now what? I dont see these as new entities. the only place I see anything about buttons is in Dev Tools using service Button_press, but calling the service does nothing… and the entity name is wrong.

Did you also let esphome do it’s magic (validate the yaml, compile a new binary and upload it ota)?

If so you should see your new buttons popping up in ha (easiest is to just enter device & services under settings and open the regarding esphome device to see all it’s entites).

Also the logs of your esphome node should show which buttons it has set up.

Ok, foolish me. I had assumed I could define these buttons in configuration.yaml, or by extension button.yaml, like all the other dozens of buttons I’ve created…

But no… these are defined in the esphome config files for the device. That’s so obvious, that it’s painfully not obvious.

This shit is So confusing. Honestly, this is not documented well at all. I’ve scoured all the docs and didn’t catch this until an aha moment just now.

Most Buttons are defined in configuration.yaml unless they are part of other entities like esphome. Then sometimes they are defined in those config files. Clear as stinky, murky, filthy mud.

So yeah it’s working now but sheesh… good thing I studied rocket science in college. Seriously…

2 Likes

All HA related stuff will be in your configuration.yaml and your other ha yamls…

Well, not really sometimes. If it is part of your esphome node it will be configured in the yaml for that esphome node (and needs to be verified, compiled and uploaded to actually be “active”).

I guess the similarities are that they use yaml for configuration - but that’s kind of all. Otherwise they are two completely independent things to setup which outcome (esphome nodes) can work great together (with ha) by utilizing the native api.

But indeed studying helps with new challenges :rocket:

1 Like

This is a nice, succinct and clear explanation of how this all fits together. I’ve never seen it explained this way, but it makes complete sense.

Jeff

1 Like

jazzmonger, thanks for sticking with this one! I need this too!

I’ve struggled a LOT trying to find the solutions in the documentation, too! It’s like the BASIC prog lanuage’s "GOTO’s. They all reference back to one another in an infinite loop without the real solution in them…

Please help understand what I do wrong. I try this code:

button:

  • platform: template

    name: “RV1 kWh reset”

    on_press:

    then:

    - delay: 5s
    
    - pzemac.reset_energy: RV1
    

And see in logs this mistake:

10:15:57 [W] [pzemac:015]
Invalid size for PZEM AC!

Post your complete ESPHome config file so we can see all of it.