-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
added pulse width accumulate #4622
base: current
Are you sure you want to change the base?
Conversation
WalkthroughThe pull request introduces new documentation for the Changes
Suggested labels
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
🧹 Nitpick comments (4)
components/sensor/pulse_width_accumulate.rst (4)
4-6
: Enhance SEO description specificity.The current SEO description is too generic. Consider making it more specific to the
pulse_width_accumulate
sensor's unique features.- :description: Instructions for setting up pulse width sensors in ESPHome + :description: Instructions for setting up pulse width accumulation sensors in ESPHome to measure total on-time of GPIO inputs for MOSFETs and TRIACs
16-20
: Improve technical specifications clarity.Consider using consistent unit formatting and add maximum polling window value in seconds for clarity.
- Threshold stability values were experimentally determined for an esp32 devkit_v4. - Pulse width >= 22 microseconds, pulse width delay >= 70 microseconds - (ie. implied maximum frequency ~10.87 KHz) - There are no overflow problems ie. the pulse width can be infinitely long. - However, the polling window (default 1 minute) must not be set > 71.58 minutes. + Threshold stability values were experimentally determined for an ESP32 DevKit-v4: + - Minimum pulse width: ≥ 22 µs + - Minimum pulse width delay: ≥ 70 µs + - Maximum implied frequency: ~10.87 kHz + - Maximum polling window: 71.58 minutes (4295 seconds)
35-45
: Improve clarity of polling behavior explanation.The explanation of polling behavior and its limitations could be structured better for clarity.
- The polling function also resets the microsecond counter preventing overflow - at 71.58 min. A peculiarity of the current Interrupt synchronization is the - occasional sensor skip of one or more polling periods. The sensor - remains accurate because the accumulated time is pushed forward to the next - polling period. The graph below shows the sensor output under stressed - conditions (22 microsecond pulses with a pulse width delay of 70 microseconds - and an update period of 1 second). - Although the majority of readings are as expected 22/92=0.239 seconds, a number - of zero, and consecutive zero readings are pushed forward. Polling - misses are less common with polling intervals >=1 min (~0.4% chance). However, - be warned that excessive polling periods >15 min may risk overflow. + Important implementation details: + + 1. The polling function resets the microsecond counter to prevent overflow at 71.58 minutes + 2. Due to interrupt synchronization, the sensor may occasionally skip polling periods + - The accumulated time is accurately carried forward to the next polling period + - Under stress testing (22 µs pulses, 70 µs delay, 1s update): + * Expected readings: 0.239s (22/92) + * Some readings show as 0 and are pushed to next period + 3. Polling reliability: + - Intervals ≥1 minute have ~0.4% miss rate + - Warning: Intervals >15 minutes risk counter overflow
47-49
: Add alt text for accessibility.The figure lacks alt text, which is important for accessibility.
.. figure:: images/22_70_kernel_density.png :align: center :width: 80.0% + :alt: Kernel density plot showing sensor output distribution under stress conditions
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
images/22_70_kernel_density.png
is excluded by!**/*.png
📒 Files selected for processing (1)
components/sensor/pulse_width_accumulate.rst
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
components/sensor/pulse_width_accumulate.rst (1)
Pattern **
: - Do not generate or add any sequence diagrams
🔇 Additional comments (1)
components/sensor/pulse_width_accumulate.rst (1)
51-69
: Configuration and references section looks good!The configuration variables are well documented and all relevant references are included.
✅ Deploy Preview for esphome ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this 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
🧹 Nitpick comments (2)
components/sensor/pulse_width_accumulate.rst (2)
15-22
: Consider adding brief explanation for maximum polling window.The note mentions a maximum polling window of 71.58 minutes with "see text below", but it would be more user-friendly to briefly explain why here, even though it's detailed later in the implementation notes.
- Maximum implied frequency: ~10 kHz - - Maximum polling window: 71.58 minutes (see text below) + - Maximum polling window: 71.58 minutes (limited by microsecond counter overflow)
23-32
: Consider enhancing the example with output value explanations.The example configuration is clear but would benefit from comments explaining what values to expect from both sensors.
# Example configuration entry sensor: - platform: pulse_width_accumulate pin: GPIO32 name: Cumulative on-time sensor + # Reports total seconds the input was HIGH during the update interval frequency: name: Average frequency sensor + # Reports average switching frequency in Hz during the update interval
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
components/sensor/pulse_width_accumulate.rst
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
components/sensor/pulse_width_accumulate.rst (1)
Pattern **
: - Do not generate or add any sequence diagrams
🪛 GitHub Check: build
components/sensor/pulse_width_accumulate.rst
[failure] 36-36:
Directive 'note' must be indented with 4 spaces, not 2. See components/sensor/pulse_width_accumulate.rst:36
🪛 GitHub Actions: Lint
components/sensor/pulse_width_accumulate.rst
[error] 36-36: Directive 'note' must be indented with 4 spaces, not 2
🔇 Additional comments (3)
components/sensor/pulse_width_accumulate.rst (3)
1-14
: LGTM! Clear and informative introduction.The SEO description and introduction effectively explain the sensor's purpose, functionality, and units of measurement.
48-58
: LGTM! Well-documented configuration variables.The configuration variables section is complete and includes all necessary information, including default values and references to relevant schemas.
59-67
: LGTM! Comprehensive references.The See Also section provides helpful links to related documentation and source files.
.. note:: | ||
|
||
Important implementation details: | ||
|
||
1. The polling function resets the microsecond counter to prevent overflow at 71.58 minutes | ||
2. Sensor accuracy is a function of the input signal frequency: | ||
- Test Condition #1 (25 µs pulses, 75 µs delay, 1 sec polling, 27380 samples): | ||
* Frequency. Expected 10 kHz. Observed mean 9980.5 Hz. Standard deviation=5.5 Hz | ||
* On-time. Expected based on time stamps 6846.75 s. Observed 6844.33 s | ||
- Test Condition #2 (300 µs pulses, 300 µs delay, 1 min polling, 289 samples): | ||
* Frequency, expected 1666.67 Hz, Observed mean 1666.57 Hz, standard deviation=0.08 Hz | ||
* On-time. Expected based on time stamps 8640 s. Observed 8639.98 s | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix note directive indentation.
The note directive must be indented with 4 spaces, not 2, to comply with RST formatting requirements.
-.. note::
-
- Important implementation details:
-
- 1. The polling function resets the microsecond counter to prevent overflow at 71.58 minutes
- 2. Sensor accuracy is a function of the input signal frequency:
- - Test Condition #1 (25 µs pulses, 75 µs delay, 1 sec polling, 27380 samples):
- * Frequency. Expected 10 kHz. Observed mean 9980.5 Hz. Standard deviation=5.5 Hz
- * On-time. Expected based on time stamps 6846.75 s. Observed 6844.33 s
- - Test Condition #2 (300 µs pulses, 300 µs delay, 1 min polling, 289 samples):
- * Frequency, expected 1666.67 Hz, Observed mean 1666.57 Hz, standard deviation=0.08 Hz
- * On-time. Expected based on time stamps 8640 s. Observed 8639.98 s
+.. note::
+
+ Important implementation details:
+
+ 1. The polling function resets the microsecond counter to prevent overflow at 71.58 minutes
+ 2. Sensor accuracy is a function of the input signal frequency:
+ - Test Condition #1 (25 µs pulses, 75 µs delay, 1 sec polling, 27380 samples):
+ * Frequency. Expected 10 kHz. Observed mean 9980.5 Hz. Standard deviation=5.5 Hz
+ * On-time. Expected based on time stamps 6846.75 s. Observed 6844.33 s
+ - Test Condition #2 (300 µs pulses, 300 µs delay, 1 min polling, 289 samples):
+ * Frequency, expected 1666.67 Hz, Observed mean 1666.57 Hz, standard deviation=0.08 Hz
+ * On-time. Expected based on time stamps 8640 s. Observed 8639.98 s
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
.. note:: | |
Important implementation details: | |
1. The polling function resets the microsecond counter to prevent overflow at 71.58 minutes | |
2. Sensor accuracy is a function of the input signal frequency: | |
- Test Condition #1 (25 µs pulses, 75 µs delay, 1 sec polling, 27380 samples): | |
* Frequency. Expected 10 kHz. Observed mean 9980.5 Hz. Standard deviation=5.5 Hz | |
* On-time. Expected based on time stamps 6846.75 s. Observed 6844.33 s | |
- Test Condition #2 (300 µs pulses, 300 µs delay, 1 min polling, 289 samples): | |
* Frequency, expected 1666.67 Hz, Observed mean 1666.57 Hz, standard deviation=0.08 Hz | |
* On-time. Expected based on time stamps 8640 s. Observed 8639.98 s | |
.. note:: | |
Important implementation details: | |
1. The polling function resets the microsecond counter to prevent overflow at 71.58 minutes | |
2. Sensor accuracy is a function of the input signal frequency: | |
- Test Condition #1 (25 µs pulses, 75 µs delay, 1 sec polling, 27380 samples): | |
* Frequency. Expected 10 kHz. Observed mean 9980.5 Hz. Standard deviation=5.5 Hz | |
* On-time. Expected based on time stamps 6846.75 s. Observed 6844.33 s | |
- Test Condition #2 (300 µs pulses, 300 µs delay, 1 min polling, 289 samples): | |
* Frequency, expected 1666.67 Hz, Observed mean 1666.57 Hz, standard deviation=0.08 Hz | |
* On-time. Expected based on time stamps 8640 s. Observed 8639.98 s |
🧰 Tools
🪛 GitHub Check: build
[failure] 36-36:
Directive 'note' must be indented with 4 spaces, not 2. See components/sensor/pulse_width_accumulate.rst:36
🪛 GitHub Actions: Lint
[error] 36-36: Directive 'note' must be indented with 4 spaces, not 2
There was a problem hiding this 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
♻️ Duplicate comments (1)
components/sensor/pulse_width_accumulate.rst (1)
36-42
:⚠️ Potential issueFix note directive indentation.
The content under the
.. note::
directive is not indented with the required 4 spaces. This improper indentation is causing the build/lint failure.Apply the following diff to fix the indentation:
-.. note:: - - Important implementation details: - - 1. Edge interrupts, and the polling function both reset the microsecond - counter preventing overflow at 71.58 minutes. - 2. Sensor accuracy is determined by the input signal frequency, for example: - - Test Condition #1 (25 µs pulses, 75 µs delay, 1 sec polling, 20379 samples): - * Frequency. Expected 10 kHz. Observed mean 9998.2 Hz. Standard deviation=0.9 Hz - * On-time. Expected based on time stamps 5094.25 s. Observed 5094.87 s (see figure below) - - Test Condition #2 (300 µs pulses, 300 µs delay, 1 sec polling, 15333 samples): - * Frequency, expected 1666.67 Hz, Observed mean 1666.57 Hz, standard deviation=0.50 Hz - * On-time. Expected based on time stamps 7666 s. Observed 7665.97 s - - Test Condition #3 (random 1s to 10 min pulses, random 1 s to 1 min delay, 1 min polling, XX samples): - * On-time. Expected based on generation algorithm output 18404.0 s. Observed 18405.0 s (gen algo used inaccurate millis() function) +.. note:: + + Important implementation details: + + 1. Edge interrupts, and the polling function both reset the microsecond counter preventing overflow at 71.58 minutes. + 2. Sensor accuracy is determined by the input signal frequency, for example: + - Test Condition #1 (25 µs pulses, 75 µs delay, 1 sec polling, 20379 samples): + * Frequency. Expected 10 kHz. Observed mean 9998.2 Hz. Standard deviation=0.9 Hz + * On-time. Expected based on time stamps 5094.25 s. Observed 5094.87 s (see figure below) + - Test Condition #2 (300 µs pulses, 300 µs delay, 1 sec polling, 15333 samples): + * Frequency, expected 1666.67 Hz, Observed mean 1666.57 Hz, standard deviation=0.50 Hz + * On-time. Expected based on time stamps 7666 s. Observed 7665.97 s + - Test Condition #3 (random 1s to 10 min pulses, random 1 s to 1 min delay, 1 min polling, XX samples): + * On-time. Expected based on generation algorithm output 18404.0 s. Observed 18405.0 s (gen algo used inaccurate millis() function)🧰 Tools
🪛 GitHub Check: build
[failure] 39-39:
Directive 'note' must be indented with 4 spaces, not 2. See components/sensor/pulse_width_accumulate.rst:39
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
components/sensor/images/kernel_25.png
is excluded by!**/*.png
📒 Files selected for processing (1)
components/sensor/pulse_width_accumulate.rst
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
components/sensor/pulse_width_accumulate.rst (1)
Pattern **
: - Do not generate or add any sequence diagrams
🪛 GitHub Check: build
components/sensor/pulse_width_accumulate.rst
[failure] 39-39:
Directive 'note' must be indented with 4 spaces, not 2. See components/sensor/pulse_width_accumulate.rst:39
[failure] 55-55:
Directive 'figure' is not followed by an empty line. Please insert an empty line after components/sensor/pulse_width_accumulate.rst:55
|
||
.. figure:: images/kernel_25.png | ||
:align: center | ||
:width: 80.0% | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Insert an additional empty line after the figure directive options.
The .. figure::
directive is not immediately followed by a blank line, which is required by reStructuredText for proper rendering. Please insert an extra empty line immediately after the options block to satisfy the formatting rules.
Apply the following diff:
.. figure:: images/kernel_25.png
:align: center
:width: 80.0%
-
+
+
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
.. figure:: images/kernel_25.png | |
:align: center | |
:width: 80.0% | |
.. figure:: images/kernel_25.png | |
:align: center | |
:width: 80.0% | |
🧰 Tools
🪛 GitHub Check: build
[failure] 55-55:
Directive 'figure' is not followed by an empty line. Please insert an empty line after components/sensor/pulse_width_accumulate.rst:55
Description:
added docs for new sensor pulse_width_accumulate
Related issue (if applicable): fixes
Pull request in esphome with YAML changes (if applicable): esphome/esphome#
Checklist:
I am merging into
next
because this is new documentation that has a matching pull-request in esphome as linked above.or
I am merging into
current
because this is a fix, change and/or adjustment in the current documentation and is not for a new component or feature.Link added in
/index.rst
when creating new documents for new components or cookbook.