Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persistent values after reboot for sensor_total_energy and sensor_total_daily_energy #527

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

ojwc
Copy link

@ojwc ojwc commented Jul 6, 2024

Changes to pulse_meter, sensor_total_energy, and sensor_total_daily_energy to restore their previous values after a reboot

Also adds on_boot flag to esphome which calls pulse_meter.set_total_pulses to manually restore the value as pulse_meter total doesn't have a restore flag.

Finally, added preferences to restrict flash writes to once every 5 minutes, to reduce wear on flash memory.

Tested on ESP32 nodemcu-32s only.

Summary by CodeRabbit

  • New Features

    • Added configuration for resetting pulse meter total pulses on boot.
    • Introduced settings for flash write interval to optimize web server performance.
    • Added a global variable to persist total energy readings across reboots.
  • Improvements

    • Enhanced sensor reading filters for more accurate pulse rate calculations.
    • Implemented a restore property for the sensor to maintain state across reboots.

ojwc added 5 commits July 6, 2024 19:33
create global variable persist_sensor_total_energy, supports making sensor_total_energy persistent after reboot
restricts flash write intervals to 5 minutes, ensures no unnecessary wear on flash memory
change pulse_meter_on_raw_value filter so it writes sensor_total_energy to global persist_sensor_total_energy
adding on_boot flag to restore sensor_total_energy from flash after a reboot.
adding restore: True to sensor_total_daily_energy so previous value is restored from flash after boot
Copy link

vercel bot commented Jul 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
home-assistant-glow ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 12, 2024 11:46pm
home-assistant-glow-wupl ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 12, 2024 11:46pm

Copy link
Contributor

coderabbitai bot commented Jul 6, 2024

Walkthrough

Walkthrough

The recent updates enhance the configuration of the pulse_meter component and the Home Assistant Glow ESP32 settings. Key changes include the introduction of a restore property for persistent sensor states, the setup of pulse_meter.set_total_pulses to initialize on boot, and adjustments to flash_write_interval preferences. Additionally, a global variable for tracking total energy has been added, improving data retention and operational reliability.

Changes

File Path Change Summary
components/pulse_meter.yaml Updated sensor filters with a new lambda function and added the restore property to sensors.
home-assistant-glow/esp32.yaml Introduced pulse_meter.set_total_pulses on boot, updated flash_write_interval preferences, and added a persistent global variable for total energy.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ojwc
Copy link
Author

ojwc commented Jul 6, 2024

PS: apologies for the excessive number of commits, I haven't done this before.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 359f22f and 3b9104a.

Files selected for processing (2)
  • components/pulse_meter.yaml (2 hunks)
  • home-assistant-glow/esp32.yaml (2 hunks)
Additional context used
yamllint
home-assistant-glow/esp32.yaml

[error] 28-28: trailing spaces

(trailing-spaces)


[error] 30-30: trailing spaces

(trailing-spaces)

Additional comments not posted (4)
home-assistant-glow/esp32.yaml (2)

68-72: LGTM!

Setting flash_write_interval to 5 minutes to reduce flash wear is a good practice.


73-76: LGTM!

Adding a global variable persist_sensor_total_energy with restore_value set to true is appropriate for persisting the sensor value across reboots.

components/pulse_meter.yaml (2)

64-68: LGTM!

The lambda function appropriately updates the value of persist_sensor_total_energy and computes the pulse rate.


94-97: LGTM!

Setting the restore property to true for the sensor_total_daily_energy is appropriate for enabling state restoration across reboots.

home-assistant-glow/esp32.yaml Outdated Show resolved Hide resolved
good bot

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3b9104a and 3103eb3.

Files selected for processing (1)
  • home-assistant-glow/esp32.yaml (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • home-assistant-glow/esp32.yaml

@klaasnicolaas klaasnicolaas added new-feature New features or request. enhancement Enhancement of the code, not introducing new features. labels Jul 23, 2024
Copy link
Owner

@klaasnicolaas klaasnicolaas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we adjust things in pulse_meter, adjustments are also needed in the ESP8266 code, otherwise it will break.

components/pulse_meter.yaml Outdated Show resolved Hide resolved
components/pulse_meter.yaml Outdated Show resolved Hide resolved
fixed formatting + added explanatory comment
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3103eb3 and 0ea7e5d.

Files selected for processing (1)
  • components/pulse_meter.yaml (2 hunks)
Additional context used
yamllint
components/pulse_meter.yaml

[error] 68-68: syntax error: expected , but found ''

(syntax)

Additional comments not posted (1)
components/pulse_meter.yaml (1)

93-93: The addition of the restore property is approved.

Adding restore: True ensures the sensor's state is retained across reboots, enhancing reliability.

components/pulse_meter.yaml Outdated Show resolved Hide resolved
@ojwc
Copy link
Author

ojwc commented Aug 12, 2024

I don't have any ESP8266 devices available for testing - are you able to make the necessary adjustments?

formatting :(

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0ea7e5d and eddfec9.

Files selected for processing (1)
  • components/pulse_meter.yaml (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • components/pulse_meter.yaml

Copy link

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. Thank you for your contributions.

@github-actions github-actions bot added the stale There has not been activity on this issue or PR for quite some time. label Sep 12, 2024
@klaasnicolaas klaasnicolaas added no-stale This issue or PR is exempted from the stable bot. and removed stale There has not been activity on this issue or PR for quite some time. labels Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement of the code, not introducing new features. new-feature New features or request. no-stale This issue or PR is exempted from the stable bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants