Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions content/components/sensor/pzemdc.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,131 @@ on_...:
- pzemdc.reset_energy: pzemdc_1
```

## Alternative configuration via Modbus

While its own component is great working for a basic setup, you may want to have more possibilities while using modbus controller.

Comment on lines +80 to +81
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Improve grammar and clarity of the introductory paragraph.

The text has grammatical issues and unclear phrasing:

  • "its own component is great working" should be "its own component works great" or "the native component is great"
  • "more possibilities while using modbus controller" should be "more flexibility when using the modbus controller"
📝 Proposed fix
-While its own component is great working for a basic setup, you may want to have more possibilities while using modbus controller.
+While the native component works great for basic setups, you may want more flexibility when using the modbus controller.
🤖 Prompt for AI Agents
In `@content/components/sensor/pzemdc.md` around lines 80 - 81, Replace the
unclear introductory sentence that starts "While its own component is great
working for a basic setup, you may want to have more possibilities while using
modbus controller." with a clearer phrasing; update it to something like: "The
native component works great for basic setups, but you may want more flexibility
when using the Modbus controller." Ensure "Modbus" is capitalized and the
sentence flow is corrected in the pzemdc.md introductory paragraph.

### Example Config

```yaml
#Where is the modbus hardware connect to?
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix grammatical error in YAML comment.

The comment "Where is the modbus hardware connect to?" has a grammatical error. It should be "connected to" instead of "connect to".

📝 Proposed fix
-#Where is the modbus hardware connect to?
+#Where is the modbus hardware connected to?
📝 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
#Where is the modbus hardware connect to?
`#Where` is the modbus hardware connected to?
🤖 Prompt for AI Agents
In `@content/components/sensor/pzemdc.md` at line 84, Update the YAML comment
string "Where is the modbus hardware connect to?" to the correct grammar "Where
is the modbus hardware connected to?" in the sensor/pzemdc.md content (locate
the comment text itself to change).

uart:
- id: modbus_uart
tx_pin: gpio<XX> #User-defined
rx_pin: gpio<XX> #User-defined
baud_rate: 9600
stop_bits: 1
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's check if the file exists and examine the relevant sections
find . -name "pzemdc.md" -type f

Repository: esphome/esphome-docs

Length of output: 101


🏁 Script executed:

# Read the file to check the actual content around lines 31 and 91
wc -l content/components/sensor/pzemdc.md

Repository: esphome/esphome-docs

Length of output: 103


🏁 Script executed:

# Read the relevant sections
sed -n '25,35p' content/components/sensor/pzemdc.md

Repository: esphome/esphome-docs

Length of output: 211


🏁 Script executed:

# Read around line 91
sed -n '85,95p' content/components/sensor/pzemdc.md

Repository: esphome/esphome-docs

Length of output: 264


🏁 Script executed:

# Search for all stop_bits references in PZEM-related files
rg 'stop_bits' -C2 --type=md -g '*pzem*'

Repository: esphome/esphome-docs

Length of output: 555


🏁 Script executed:

# Read more context around the first configuration (stop_bits: 2)
sed -n '20,45p' content/components/sensor/pzemdc.md

Repository: esphome/esphome-docs

Length of output: 665


🏁 Script executed:

# Read more context around the second configuration (stop_bits: 1)
sed -n '75,100p' content/components/sensor/pzemdc.md

Repository: esphome/esphome-docs

Length of output: 604


🏁 Script executed:

# Check if there are any section headers or explanations
grep -n "^##\|^###\|Example\|configuration" content/components/sensor/pzemdc.md | head -20

Repository: esphome/esphome-docs

Length of output: 448


Clarify stop_bits configuration difference between PZEM component and Modbus alternative.

The documentation shows two different UART configurations for PZEM devices: the native pzemdc component uses stop_bits: 2 (line 31), while the alternative "Modbus" configuration uses stop_bits: 1 (line 91). These are presented as separate methods, but the documentation does not explain why the settings differ or which is required for proper operation. Add a note clarifying whether both settings are correct for their respective methods or if one should be standardized.

🤖 Prompt for AI Agents
In `@content/components/sensor/pzemdc.md` at line 91, Update the pzemdc.md
documentation to clarify the differing UART "stop_bits" values: add a short note
next to the pzemdc component example (the native pzemdc example using stop_bits:
2) and next to the Modbus alternative example (the Modbus-over-UART example
using stop_bits: 1) stating that both settings are correct for their respective
methods — the native pzemdc driver expects 2 stop bits, while the
Modbus-over-UART configuration typically uses 1 stop bit — and include a
one-line rationale that the native driver and Modbus protocol expect different
UART framing so users should keep the stop_bits as shown for each method.

parity: NONE

#Lets define the modbus to use:
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix apostrophe in YAML comment.

"Lets" should be "Let's" (contraction of "let us").

📝 Proposed fix
-#Lets define the modbus to use:
+#Let's define the modbus to use:
📝 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
#Lets define the modbus to use:
`#Let`'s define the modbus to use:
🤖 Prompt for AI Agents
In `@content/components/sensor/pzemdc.md` at line 93, Update the YAML/Markdown
comment string "#Lets define the modbus to use:" to use the correct contraction
with an apostrophe; change the text to "#Let's define the modbus to use:" so the
comment reads correctly. Reference the existing comment line "#Lets define the
modbus to use:" in content/components/sensor/pzemdc.md to locate and update it.

modbus:
uart_id: modbus_uart
id: my_modbus

#Lets intiate the Modbus Controller:
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix spelling and apostrophe in YAML comment.

The comment has two errors: "Lets" should be "Let's", and "intiate" should be "initiate".

📝 Proposed fix
-#Lets intiate the Modbus Controller:
+#Let's initiate the Modbus Controller:
📝 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
#Lets intiate the Modbus Controller:
`#Let`'s initiate the Modbus Controller:
🤖 Prompt for AI Agents
In `@content/components/sensor/pzemdc.md` at line 98, Update the YAML comment
"#Lets intiate the Modbus Controller:" to correct spelling and punctuation by
changing it to "#Let's initiate the Modbus Controller:" so the contraction and
the verb are correct.

modbus_controller:
- id: pzem_hub
modbus_id: my_modbus
address: 0x01
setup_priority: -10
command_throttle: 100ms
update_interval: "4s"

sensor:
- platform: modbus_controller
modbus_controller_id: pzem_hub
name: "PZEM Voltage"
id: pzem_dc_voltage
icon: "mdi:flash"
register_type: read
address: 0x0000
unit_of_measurement: "V"
value_type: U_WORD
accuracy_decimals: 2
force_update: true
filters:
- multiply: 0.01

- platform: modbus_controller
modbus_controller_id: pzem_hub
name: "PZEM Current"
id: pzem_dc_current
icon: "mdi:current-dc"
register_type: read
address: 0x0001
unit_of_measurement: "A"
value_type: U_WORD
accuracy_decimals: 2
filters:
- multiply: 0.01
# Using delta to ignore false values in case the PZEM Device is OFF
- delta: 0.05
# Using heartbeat to send an "alive" message to HA
- heartbeat: 10s

- platform: modbus_controller
modbus_controller_id: pzem_hub
name: "PZEM Power"
id: pzem_dc_power
register_type: read
icon: "mdi:lightning-bolt"
address: 0x0002
unit_of_measurement: "W"
value_type: U_DWORD
accuracy_decimals: 2
filters:
- multiply: 0.1
# DELTA-Filter: Does only send a new value if the new one is different by 3 Watt
- delta: 3.0
# Using heartbeat to send an "alive" message to HA
- heartbeat: 10s

- platform: total_daily_energy
name: "PZEM Daily Energy"
id: pzem_dc_energy_daily
icon: "mdi:counter"
power_id: pzem_dc_power
unit_of_measurement: "kWh"
state_class: total_increasing
device_class: energy
accuracy_decimals: 3
filters:
# Multiply to change from Watt hours to Kilo Watt hours (kwh)
- multiply: 0.001

```

### `on_offline` and `on_online` Action

Scenario: A binary sensor (id: bs_pzem_online) shall indicate if the device is off- or online.
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix hyphenation in sentence.

"off- or online" should be "offline or online" without the awkward hyphen.

📝 Proposed fix
-Scenario: A binary sensor (id: bs_pzem_online) shall indicate if the device is off- or online.
+Scenario: A binary sensor (id: bs_pzem_online) shall indicate if the device is offline or online.
📝 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
Scenario: A binary sensor (id: bs_pzem_online) shall indicate if the device is off- or online.
Scenario: A binary sensor (id: bs_pzem_online) shall indicate if the device is offline or online.
🤖 Prompt for AI Agents
In `@content/components/sensor/pzemdc.md` at line 173, Replace the hyphenated
phrase "off- or online" with "offline or online" in the Scenario sentence that
references the binary sensor id bs_pzem_online so it reads: "A binary sensor
(id: bs_pzem_online) shall indicate if the device is offline or online."


```yaml
on_online:
then:
- binary_sensor.template.publish:
id: bs_pzem_online
state: ON

#Also possible writing it in lambdas:
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix grammar in YAML comment.

The comment "Also possible writing it in lambdas:" is grammatically incorrect.

📝 Proposed fix
-#Also possible writing it in lambdas:
+#It's also possible to write it in lambdas:
📝 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
#Also possible writing it in lambdas:
`#It`'s also possible to write it in lambdas:
🤖 Prompt for AI Agents
In `@content/components/sensor/pzemdc.md` at line 181, Replace the grammatically
incorrect YAML comment "Also possible writing it in lambdas:" with a corrected
phrasing such as "Also possible to write it using lambdas:" (or "Also possible
to write it with lambdas:") so the comment is clear; locate the exact comment
string "Also possible writing it in lambdas:" in the sensor/pzemdc.md content
and update it accordingly.

on_offline:
then:
- lambda: |-
ESP_LOGW("pzem_hub", "Controller: Device is offline, zero'ing all sensors");
id(bs_pzem_online).publish_state(false);

//additionally lets zero all sensors as the device is offline
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix apostrophe in YAML comment.

"lets" should be "let's" (contraction of "let us").

📝 Proposed fix
-            //additionally lets zero all sensors as the device is offline
+            //additionally let's zero all sensors as the device is offline
📝 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
//additionally lets zero all sensors as the device is offline
//additionally let's zero all sensors as the device is offline
🤖 Prompt for AI Agents
In `@content/components/sensor/pzemdc.md` at line 188, Update the inline YAML
comment that currently reads "//additionally lets zero all sensors as the device
is offline" to use the correct contraction by replacing "lets" with "let's"
(i.e., "//additionally let's zero all sensors as the device is offline") so the
comment is grammatically correct.

id(pzem_dc_voltage).publish_state(0.0);
id(pzem_dc_current).publish_state(0.0);
id(pzem_dc_power).publish_state(0.0);
```

## See Also

- {{< docref "/components/uart" >}}
- {{< docref "/components/modbus" >}}
- {{< docref "/components/modbus_controller" >}}
- {{< docref "/components/sensor/modbus_controller" >}}
- {{< docref "/components/sensor/total_daily_energy" >}}
Comment on lines +198 to +202
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Replace legacy Hugo shortcodes with standard Markdown links.

These lines use the legacy {{< docref >}} shortcode, which should be replaced with standard Markdown link syntax. As per coding guidelines, Hugo shortcode {{< docref >}} is legacy and should be replaced with standard Markdown links.

🔄 Proposed fix
-- {{< docref "/components/uart" >}}
-- {{< docref "/components/modbus" >}}
-- {{< docref "/components/modbus_controller" >}}
-- {{< docref "/components/sensor/modbus_controller" >}}
-- {{< docref "/components/sensor/total_daily_energy" >}}
+- [UART](/components/uart)
+- [Modbus](/components/modbus)
+- [Modbus Controller](/components/modbus_controller)
+- [Modbus Controller Sensor](/components/sensor/modbus_controller)
+- [Total Daily Energy](/components/sensor/total_daily_energy)
📝 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
- {{< docref "/components/uart" >}}
- {{< docref "/components/modbus" >}}
- {{< docref "/components/modbus_controller" >}}
- {{< docref "/components/sensor/modbus_controller" >}}
- {{< docref "/components/sensor/total_daily_energy" >}}
- [UART](/components/uart)
- [Modbus](/components/modbus)
- [Modbus Controller](/components/modbus_controller)
- [Modbus Controller Sensor](/components/sensor/modbus_controller)
- [Total Daily Energy](/components/sensor/total_daily_energy)
🤖 Prompt for AI Agents
In `@content/components/sensor/pzemdc.md` around lines 202 - 206, Replace the
legacy Hugo shortcodes in content/components/sensor/pzemdc.md (the instances of
{{< docref "/components/uart" >}}, {{< docref "/components/modbus" >}}, {{<
docref "/components/modbus_controller" >}}, {{< docref
"/components/sensor/modbus_controller" >}}, and {{< docref
"/components/sensor/total_daily_energy" >}}) with standard Markdown links; for
each shortcode use [display text](path) — e.g. replace {{< docref
"/components/uart" >}} with [Components: UART](/components/uart) (or a concise
human-friendly label you prefer) and do the same for the other four shortcodes,
ensuring the link paths match the quoted paths and the display text is clear and
consistent.

- [Sensor Filters](/components/sensor#sensor-filters)
- {{< docref "pzem004t/" >}}
- {{< docref "pzemac/" >}}
Expand Down