-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add Modbus alternative configuration and actions #6094
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
base: current
Are you sure you want to change the base?
Changes from 1 commit
4eddd5d
229b483
9be68f5
78dc8ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -75,8 +75,135 @@ | |||||||||||||||||||||
| - 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. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| **Example Config** | ||||||||||||||||||||||
| ```yaml | ||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| #Where is the modbus hardware connect to? | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| uart: | ||||||||||||||||||||||
| - id: modbus_uart | ||||||||||||||||||||||
| tx_pin: gpio03 | ||||||||||||||||||||||
| rx_pin: gpio01 | ||||||||||||||||||||||
|
||||||||||||||||||||||
| baud_rate: 9600 | ||||||||||||||||||||||
| stop_bits: 1 | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's check if the file exists and examine the relevant sections
find . -name "pzemdc.md" -type fRepository: 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.mdRepository: esphome/esphome-docs Length of output: 103 🏁 Script executed: # Read the relevant sections
sed -n '25,35p' content/components/sensor/pzemdc.mdRepository: esphome/esphome-docs Length of output: 211 🏁 Script executed: # Read around line 91
sed -n '85,95p' content/components/sensor/pzemdc.mdRepository: 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.mdRepository: 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.mdRepository: 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 -20Repository: 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 🤖 Prompt for AI Agents |
||||||||||||||||||||||
| parity: NONE | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| #Lets define the modbus to use: | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| modbus: | ||||||||||||||||||||||
| uart_id: modbus_uart | ||||||||||||||||||||||
| id: my_modbus | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| #Lets intiate the Modbus Controller: | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| 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** | ||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| **Scenario:** | ||||||||||||||||||||||
| A binary sensor (id: bs_pzem_online) shall indicate if the device is off- or online. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ```yaml | ||||||||||||||||||||||
| on_online: | ||||||||||||||||||||||
| then: | ||||||||||||||||||||||
| - binary_sensor.template.publish: | ||||||||||||||||||||||
| id: bs_pzem_online | ||||||||||||||||||||||
| state: ON | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| #Also possible writing it in lambdas: | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| 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 | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| id(pzem_dc_voltage).publish_state(0.0); | ||||||||||||||||||||||
| id(pzem_dc_current).publish_state(0.0); | ||||||||||||||||||||||
| id(pzem_dc_power).publish_state(0.0); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||
| ## 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace legacy Hugo shortcodes with standard Markdown links. These lines use the legacy 🔄 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| - [Sensor Filters](/components/sensor#sensor-filters) | ||||||||||||||||||||||
| - {{< docref "pzem004t/" >}} | ||||||||||||||||||||||
| - {{< docref "pzemac/" >}} | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
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.
Improve grammar and clarity of the introductory paragraph.
The text has grammatical issues and unclear phrasing:
📝 Proposed fix
🤖 Prompt for AI Agents