Troubleshooting and Fixing the Sonoff Pow R2 Energy Data Issue

Hey everyone, I wanted to share my experience with the Sonoff Pow R2 and a little hiccup I encountered during a firmware update. I hope this helps someone else who might run into the same issue!

So, I’ve been using my Sonoff Pow R2 for a while now, and I absolutely love how it tracks energy consumption. It’s been a great tool for monitoring my daily energy usage and making adjustments to save on my electricity bill. The ability to store today’s, yesterday’s, and total energy values in flash memory has been super handy, especially after power outages. But here’s the catch: when I updated the firmware wirelessly, I noticed that the ‘today’ and ‘total’ energy values were getting erased. The ‘yesterday’ value was preserved, which was good, but the others were reset, which was a bit frustrating.

I decided to dig into the issue and figure out what was going wrong. After some research and tinkering, I realized that the problem was related to how the firmware update interacts with the flash memory. The ‘yesterday’ value was being copied over correctly, but the ‘today’ and ‘total’ values weren’t being preserved during the update process. This led me to look into the configuration settings and see if there was a way to ensure all values were retained.

Here’s what I did to fix it:

  1. Checked the Restore Settings: I made sure that the ‘restore_from_flash’ option was set to ‘True’ in the ESP8266 configuration. This ensures that any saved values are restored after a reboot or firmware update.
  2. Adjusted the Global Variables: I reviewed the global variables in my configuration and made sure that all relevant energy tracking variables were set to ‘restore_value: yes’. This tells the system to keep these values even after a restart or update.
  3. Modified the Time Automation: I tweaked the time automation that copies the daily energy values to the ‘yesterday’ variable. I added some extra logging to ensure that the values were being captured and stored correctly before the firmware update.
  4. Tested the Update: After making these changes, I performed a firmware update again. This time, all the energy values were preserved, and I didn’t lose any data. It was a relief to see everything working as intended!

This experience taught me the importance of thoroughly checking configuration settings, especially when dealing with firmware updates and data persistence. It also highlighted how the community-driven nature of projects like ESPHome can be a lifesaver when troubleshooting issues. By sharing my solution, I hope to help others avoid the same frustration and ensure their energy tracking remains uninterrupted.

If anyone else has encountered similar issues or has additional tips, I’d love to hear about them in the comments below! Happy tinkering, everyone! :rocket: