Skip to content
Merged
Show file tree
Hide file tree
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
34 changes: 34 additions & 0 deletions pv_inverter/packages/deye_hybrid_1p/grid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

substitutions:
# Register 54 = "AC power ratio". Only scale when it reads a known 10W/LSB
# value; pass raw watts through otherwise (covers 1, 0/unsupported and the
# not-yet-read NaN state).
func_scale_ac_power: "return (id(ac_power_ratio).state == 10.0f) ? x * 10.0f : x;"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · AC power reads are under-scaled

When register 54 fails or its initial read completes after AC power reads succeed on a 10 W/LSB inverter, func_scale_ac_power returns raw x while ac_power_ratio is unread or invalid, so affected power sensors publish values 10× too low until a valid ratio read and power poll succeed.

Handle an unread or failed ratio separately from a genuine non-10 ratio so 10 W/LSB power is not published unscaled.

Also at pv_inverter/packages/deye_hybrid_1p/load.yaml:19.

Prompt for AI agents
In `pv_inverter/packages/deye_hybrid_1p/grid.yaml` at line 19:

**AC power reads are under-scaled**

When register 54 fails or its initial read completes after AC power reads succeed on a 10 W/LSB inverter, `func_scale_ac_power` returns raw `x` while `ac_power_ratio` is unread or invalid, so affected power sensors publish values 10× too low until a valid ratio read and power poll succeed.

Handle an unread or failed ratio separately from a genuine non-10 ratio so 10 W/LSB power is not published unscaled.

Also at `pv_inverter/packages/deye_hybrid_1p/load.yaml:19`.


globals:
- id: last_total_energy_bought
type: float
Expand All @@ -21,11 +27,29 @@ globals:
restore_value: yes

sensor:
# Register 54 = "AC power ratio". Per the V119 protocol, the AC power registers
# 167-169, 170-172 and 176-178 are reported in units of this value (1W or 10W
# per LSB). Verified on hardware: SG02 10kW reads 10 (10W units), SG04 6kW
# reads 0 (1W units) - so only a value of 10 triggers scaling.
- platform: modbus_controller
modbus_controller_id: ${modbus_controller_id}
name: "AC Power Ratio"
id: ac_power_ratio
register_type: holding

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.

change register type to read only

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Isn't it a holding register?

modbus 0x03? is to read from the holding register

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In ESPHome's modbus_controller, register_type: read doesn't mean "read-only", it means input registers, read with Modbus function 0x04. Deye exposes everything as holding registers (function 0x03): my raw poll 01 03 0036 0001 used 0x03 and got an answer.
Plus in the entire repo, every single sensor in both the 1P and 3P packages uses register_type: holding. Switching register 54 to read would actually break it (the inverter likely won't answer 0x04).
A sensor never writes regardless, so there's no write-safety concern.

Register_type: read = FC 0x04 input registers, which Deye doesn't serve (atleast according to the documentation), and that it would be inconsistent with every other sensor in the repo.

image

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.

Ok you are right about register type. Instead make it: internal: true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok you are right about register type. Instead make it: internal: true

I think it would be useful to keep it shown. It would be useful in the diagnostic section like this:

image

Setting it to internal: true will hide it, which doesnt really provide any benefit that i can see.

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.

It never change and it is related to modbus version. In older release this register address is use as a different parameter. It may confuse other people. Also it is use to change values of other sensor. So it role is done and nothing more is needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ahh okay I understand. I will update it accordingly.

address: 54
value_type: U_WORD
accuracy_decimals: 0
entity_category: diagnostic
icon: "mdi:multiplication"
internal: true

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Ratio is hidden from Home Assistant

When a Home Assistant user or automation tries to inspect the documented AC Power Ratio entity, internal: true keeps ESPHome from exposing the sensor to Home Assistant, so users and automations cannot inspect the ratio or applied factor.

Remove internal: true from the AC Power Ratio sensor.

Also at pv_inverter/packages/deye_hybrid_1p/grid.yaml:45.

Prompt for AI agents
In `pv_inverter/packages/deye_hybrid_1p/grid.yaml` at line 44:

**Ratio is hidden from Home Assistant**

When a Home Assistant user or automation tries to inspect the documented AC Power Ratio entity, `internal: true` keeps ESPHome from exposing the sensor to Home Assistant, so users and automations cannot inspect the ratio or applied factor.

Remove `internal: true` from the AC Power Ratio sensor.

Also at `pv_inverter/packages/deye_hybrid_1p/grid.yaml:45`.


- platform: modbus_controller
modbus_controller_id: ${modbus_controller_id}
name: "Grid L1 Power"
register_type: holding
address: 167
filters:
- lambda: ${func_scale_ac_power}
unit_of_measurement: "W"
device_class: power
state_class: "measurement"
Expand All @@ -38,6 +62,8 @@ sensor:
name: "Grid L2 Power"
register_type: holding
address: 168
filters:
- lambda: ${func_scale_ac_power}
unit_of_measurement: "W"
device_class: power
state_class: "measurement"
Expand All @@ -50,6 +76,8 @@ sensor:
name: "Grid Power"
register_type: holding
address: 169
filters:
- lambda: ${func_scale_ac_power}
unit_of_measurement: "W"
device_class: power
state_class: "measurement"
Expand Down Expand Up @@ -208,6 +236,8 @@ sensor:
name: "External CT L1 Power"
register_type: holding
address: 170
filters:
- lambda: ${func_scale_ac_power}
unit_of_measurement: "W"
device_class: power
accuracy_decimals: 0
Expand All @@ -219,6 +249,8 @@ sensor:
name: "External CT L2 Power"
register_type: holding
address: 171
filters:
- lambda: ${func_scale_ac_power}
unit_of_measurement: "W"
device_class: power
accuracy_decimals: 0
Expand All @@ -230,6 +262,8 @@ sensor:
name: "External CT Power"
register_type: holding
address: 172
filters:
- lambda: ${func_scale_ac_power}
unit_of_measurement: "W"
device_class: power
accuracy_decimals: 0
Expand Down
13 changes: 13 additions & 0 deletions pv_inverter/packages/deye_hybrid_1p/load.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

substitutions:
# Register 54 = "AC power ratio" (defined in grid.yaml). Only scale when it
# reads a known 10W/LSB value; pass raw watts through otherwise (covers 1,
# 0/unsupported and the not-yet-read NaN state).
func_scale_ac_power: "return (id(ac_power_ratio).state == 10.0f) ? x * 10.0f : x;"

sensor:
- platform: modbus_controller
modbus_controller_id: ${modbus_controller_id}
Expand Down Expand Up @@ -43,6 +50,8 @@ sensor:
name: "Load L1 Power"
register_type: holding
address: 176
filters:
- lambda: ${func_scale_ac_power}
unit_of_measurement: "W"
device_class: power
state_class: "measurement"
Expand All @@ -55,6 +64,8 @@ sensor:
name: "Load L2 Power"
register_type: holding
address: 177
filters:
- lambda: ${func_scale_ac_power}
unit_of_measurement: "W"
device_class: power
state_class: "measurement"
Expand All @@ -67,6 +78,8 @@ sensor:
name: "Load Power"
register_type: holding
address: 178
filters:
- lambda: ${func_scale_ac_power}
unit_of_measurement: "W"
device_class: power
state_class: "measurement"
Expand Down
Loading