Skip to content

[bl0940] document new configuration options#5340

Merged
jesserockz merged 10 commits intoesphome:nextfrom
dan-s-github:bl0940md
Sep 10, 2025
Merged

[bl0940] document new configuration options#5340
jesserockz merged 10 commits intoesphome:nextfrom
dan-s-github:bl0940md

Conversation

@dan-s-github
Copy link
Copy Markdown
Contributor

Description:

Related issue (if applicable): fixes

Pull request in esphome with YAML changes (if applicable):

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 /components/index.rst when creating new documents for new components or cookbook.

New Component Images

If you are adding a new component to ESPHome, you can automatically generate a standardized black and white component name image for the documentation.

To generate a component image:

  1. Comment on this pull request with the following command, replacing COMPONENT_NAME with your component name in UPPER_CASE format with underscores (e.g., BME280, SHT3X, DALLAS_TEMP):

    @esphomebot generate image COMPONENT_NAME
    
  2. The ESPHome bot will respond with a downloadable ZIP file containing the SVG image.

  3. Extract the SVG file and place it in the images/ folder of this repository.

  4. Use the image in your component's index table entry in /components/index.rst.

Example: For a component called "DHT22 Temperature Sensor", use:

@esphomebot generate image DHT22

esphome[bot]
esphome bot previously requested changes Sep 8, 2025
Copy link
Copy Markdown

@esphome esphome bot left a comment

Choose a reason for hiding this comment

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

As this is a feature matched with a PR in https://github.com/esphome/esphome, please target your PR to the next branch and rebase.

@esphome esphome bot marked this pull request as draft September 8, 2025 09:10
@esphome
Copy link
Copy Markdown

esphome bot commented Sep 8, 2025

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@netlify
Copy link
Copy Markdown

netlify bot commented Sep 8, 2025

Deploy Preview for esphome ready!

Name Link
🔨 Latest commit ad7b9b0
🔍 Latest deploy log https://app.netlify.com/projects/esphome/deploys/68c0da2075f3a90008813e7d
😎 Deploy Preview https://deploy-preview-5340--esphome.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Sep 8, 2025

Walkthrough

Documentation updates only. The components index updates the BL0940 description to include Energy. The BL0940 sensor page is rewritten from a brief note to a full UART-based documentation with example configuration, configuration variables, calibration concepts and formulas, online calibration numbers, reset button, and references.

Changes

Cohort / File(s) Summary of edits
Docs: Components index tweak
content/components/_index.md
Updated BL0940 description from "Voltage & Current & Power" to "Voltage & Current & Power & Energy".
Docs: BL0940 page overhaul
content/components/sensor/bl0940.md
Replaced placeholder with comprehensive BL0940 docs: UART usage, example YAML, expanded configuration (uart_id, legacy_mode, read/write commands), sensor options (voltage/current/power/energy/temps, update_interval), detailed calibration model and formulas, online calibration numbers, reset button, and references.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

has-parent, next

Suggested reviewers

  • jesserockz
  • DjordjeMandic
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
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

🧹 Nitpick comments (2)
content/components/sensor/bl0940.md (2)

77-85: Remove trailing punctuation in heading; minor unit clarity

Fix MD026 and improve R2 note.

-#### Available calibration options:
+#### Available calibration options
@@
-resistor_two: 1950        # R2 = 5 x 390 kΩ -> 1950 kΩ
+resistor_two: 1950        # R2 = 5 × 390 kΩ = 1950 kΩ

159-166: Remove trailing punctuation in heading (MD026)

-### Calibration details:
+### Calibration details
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c4512fb and 1c48f65.

⛔ Files ignored due to path filters (1)
  • content/components/sensor/images/bl0940-cal.png is excluded by !**/*.png
📒 Files selected for processing (2)
  • content/components/_index.md (1 hunks)
  • content/components/sensor/bl0940.md (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

  • Do not generate or add any sequence diagrams

Files:

  • content/components/_index.md
  • content/components/sensor/bl0940.md
🪛 GitHub Check: build
content/components/sensor/bl0940.md

[failure] 157-157:
Lists should be surrounded by blank lines [Context: "> - unit_of_measurement: `..."]

🪛 GitHub Actions: Lint
content/components/sensor/bl0940.md

[error] 77-77: Markdownlint MD026: Trailing punctuation in heading [Punctuation: ':'] (step: nosborn/github-action-markdown-cli@v3.5.0)

🔇 Additional comments (10)
content/components/_index.md (1)

326-326: BL0940 now lists Energy – good alignment with new docs

Matches the added energy sensor support on the BL0940 page.

content/components/sensor/bl0940.md (9)

87-101: Good: formulae and source reference are explicit

Clear mapping from schematic values to computed references.


103-111: Legacy defaults block looks consistent

Keeps backward compatibility explicit.


112-122: Nice: manual override precedence and example values

Example aligns with corrected defaults above.


171-179: Reset button docs are concise and clear

LGTM.


1-8: Process: target branch should be “next” until esphome#8158 ships

Front matter is fine, but the PR description says “merge into next”; the PR metadata targets “current”. Please confirm and retarget to next if this feature isn’t in a released ESPHome yet.


187-188: Use standard apiref shortcode for API link

Consistent with other component pages.

-- API reference: bl0940/bl0940.h
+- {{< apiref "bl0940/bl0940.h" >}}

10-13: Fix grammar and clarify UART pin names

  • “energy monitors sensors” → “energy monitor sensors” (or simply “energy monitor”).
  • “Tuya-devices” → “Tuya devices”.
  • Refer to config keys: use tx_pin and rx_pin instead of “TX and RX pins”.
  • Verify product name spellings: “power-metering BW-SHP10” and “Vaiotech Rowi2 Smart Plug”.
-The `bl0940` component allows you to use BL0940 energy monitors sensors with ESPHome. These are used in some Tuya-devices (e.g. the power metering BW-SHP10) and the Vaiotech Rowi2 Smart Plug.
+The `bl0940` component allows you to use BL0940 energy monitor sensors with ESPHome. These are used in some Tuya devices (e.g. the power-metering BW-SHP10) and the Vaiotech Rowi2 Smart Plug.
@@
-The communication with this component is done via a UART. You must therefore have a `uart:` entry in your configuration with both the TX and RX pins set to some pins on your board and the baud rate set to 4800 with 1 stop bit.
+Communication is via UART. Add a `uart:` entry with `tx_pin` and `rx_pin` set for your board, baud rate 4800, and 1 stop bit.

61-69: Swap voltage_reference and current_reference defaults; add units for resistors

-**resistor_shunt** (*Optional*, float): The calibration parameter for RL. Defaults to `1`
-**resistor_one** (*Optional*, float): The calibration parameter for R1. Defaults to `0.51`
-**resistor_two** (*Optional*, float): The calibration parameter for R2. Defaults to `1950`
+**resistor_shunt** (*Optional*, float): Shunt resistor RL in mΩ. Default: `1`.
+**resistor_one** (*Optional*, float): Divider resistor R1 in kΩ. Default: `0.51`.
+**resistor_two** (*Optional*, float): Divider resistor R2 in kΩ. Default: `1950`.
@@
-**voltage_reference** (*Optional*, float): The calibration parameter for voltage readings. Defaults to `266013.136288998` as calculated using schema defaults.
-**current_reference** (*Optional*, float): The calibration parameter for current readings. Defaults to `17158.9201389365` as calculated using schema defaults.
+**voltage_reference** (*Optional*, float): The calibration parameter for voltage readings. Defaults to `17158.9201389365` (calculated from defaults).
+**current_reference** (*Optional*, float): The calibration parameter for current readings. Defaults to `266013.136288998` (calculated from defaults).

Please verify these numbers against the implementation constants and example calculations.


47-57: Tighten option wording; fix “energy”/“external_temperature” descriptions

  • Standardize read/write command default formatting.
  • Update energy description to cumulative energy in kWh.
  • Clarify that external_temperature may be unconnected and return invalid data.
-**read_command** (*Optional*): The byte used for the read commands when communicating with the BL0940. By default, it is set to `0x58` or `0x50` in `legacy_mode`.
+**read_command** (*Optional*): Byte used for read commands. Default: `0x58` (or `0x50` in `legacy_mode`).
-**write_command** (*Optional*): byte used for the write commands when communicating with the BL0940. By default, it is set to `0xA8` or `0xA0` in `legacy_mode`.
+**write_command** (*Optional*): Byte used for write commands. Default: `0xA8` (or `0xA0` in `legacy_mode`).
-**energy** (*Optional*): Use the voltage value of the sensor in kWh. All options from Sensor.
+**energy** (*Optional*): Cumulative energy in kWh. All options from Sensor.
-**external_temperature** (*Optional*): The external value of the sensor in °C. Often not connected and gives garbage data. All options from Sensor.
+**external_temperature** (*Optional*): External temperature in °C. Often not connected on devices and may return invalid data. All options from Sensor.

Confirm read/write command defaults match esphome/esphome#8158.

Comment on lines +148 to +158
#### Calibration variables:

- **min_value** (*Optional*, float): The minimum value this number can be. Minimal allowed value is `-50` defaults to `-10`.
- **max_value** (*Optional*, float): The maximum value this number can be. Maximal allowed value is `50` defaults to `10`.
- **step** (*Optional*, float): The granularity with which the number can be set. Defaults to `0.1`.
- **restore_value** (*Optional*, boolean): Saves and loads the state to RTC/Flash. Defaults to `True`
- All other options from Number.

> **Note:** There are some fixed values defined:
> - **unit_of_measurement**: `UNIT_PERCENT`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix heading punctuation, boolean casing, and markdown list spacing; avoid internal constant name

  • Remove trailing colon (MD026).
  • Use lowercase YAML boolean for consistency.
  • Surround the list with blank lines (markdownlint).
  • Prefer “%” over internal UNIT_PERCENT.
-#### Calibration variables:
+#### Calibration variables
@@
-- **restore_value** (*Optional*, boolean): Saves and loads the state to RTC/Flash. Defaults to `True`
+- **restore_value** (*Optional*, boolean): Saves and loads the state to RTC/Flash. Defaults to `true`.
@@
-> **Note:** There are some fixed values defined:
-> - **unit_of_measurement**: `UNIT_PERCENT`
+> **Note:** There are some fixed values defined.
+>
+> - unit_of_measurement: `%`
+>
📝 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.

Suggested change
#### Calibration variables:
- **min_value** (*Optional*, float): The minimum value this number can be. Minimal allowed value is `-50` defaults to `-10`.
- **max_value** (*Optional*, float): The maximum value this number can be. Maximal allowed value is `50` defaults to `10`.
- **step** (*Optional*, float): The granularity with which the number can be set. Defaults to `0.1`.
- **restore_value** (*Optional*, boolean): Saves and loads the state to RTC/Flash. Defaults to `True`
- All other options from Number.
> **Note:** There are some fixed values defined:
> - **unit_of_measurement**: `UNIT_PERCENT`
#### Calibration variables
- **min_value** (*Optional*, float): The minimum value this number can be. Minimal allowed value is `-50` defaults to `-10`.
- **max_value** (*Optional*, float): The maximum value this number can be. Maximal allowed value is `50` defaults to `10`.
- **step** (*Optional*, float): The granularity with which the number can be set. Defaults to `0.1`.
- **restore_value** (*Optional*, boolean): Saves and loads the state to RTC/Flash. Defaults to `true`.
- All other options from Number.
> **Note:** There are some fixed values defined.
>
> - unit_of_measurement: `%`
>
🧰 Tools
🪛 GitHub Check: build

[failure] 157-157:
Lists should be surrounded by blank lines [Context: "> - unit_of_measurement: `..."]

🤖 Prompt for AI Agents
In content/components/sensor/bl0940.md around lines 148 to 158, the markdown has
a trailing colon on the "Calibration variables:" heading, inconsistent boolean
casing, missing blank lines around the list, and exposes an internal constant
name for the unit; remove the trailing colon from the heading, change
"True"/"False" to lowercase YAML booleans (true/false), add a blank line before
and after the bulleted list, and replace the internal constant `UNIT_PERCENT`
with the literal percent symbol (%) in the text.

esphome[bot]
esphome bot previously requested changes Sep 8, 2025
Copy link
Copy Markdown

@esphome esphome bot left a comment

Choose a reason for hiding this comment

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

As this is a feature matched with a PR in https://github.com/esphome/esphome, please target your PR to the next branch and rebase.

esphome[bot]
esphome bot previously requested changes Sep 8, 2025
Copy link
Copy Markdown

@esphome esphome bot left a comment

Choose a reason for hiding this comment

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

As this is a feature matched with a PR in https://github.com/esphome/esphome, please target your PR to the next branch and rebase.

@dan-s-github dan-s-github changed the base branch from current to next September 9, 2025 04:54
@esphome esphome bot added the next label Sep 9, 2025
@esphome esphome bot dismissed their stale review September 9, 2025 04:55

Base branch has been corrected - dismissing previous review.

@esphome esphome bot dismissed their stale review September 9, 2025 04:59

Base branch has been corrected - dismissing previous review.

@esphome esphome bot dismissed their stale review September 9, 2025 05:06

Base branch has been corrected - dismissing previous review.

@dan-s-github dan-s-github marked this pull request as ready for review September 9, 2025 05:47
@jesserockz jesserockz merged commit 464c1dd into esphome:next Sep 10, 2025
4 checks passed
@jesserockz jesserockz mentioned this pull request Sep 10, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Sep 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants