Skip to content

Commit 8e3d72b

Browse files
fix(1P): ac power scaling (#123)
* fix(1P): scale AC power registers by register 54 (AC power ratio) Per the V119 protocol, the AC power registers 167-169 (grid), 170-172 (external CT) and 176-178 (load) are reported in units of register 54 (1W or 10W per LSB). Read register 54 as an "AC Power Ratio" sensor and multiply those power sensors by it, so values match the inverter display (e.g. External CT Power 875 -> 8750 when the ratio is 10). Falls back to the raw value while the ratio is unread. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * refactor(1P): only scale AC power on known ratio, hoist lambda into substitution Per PR #123 review: guard the register 54 multiply so it only applies on a verified 10W/LSB value and passes raw watts through otherwise. Confirmed on hardware: SG02 10kW reports ratio 10 (10W units), SG04 6kW reports 0 (1W units). NaN == 10.0f is false, so the not-yet-read state needs no isnan check. Lambda hoisted into a substitution following the tou.yaml pattern. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(1P): mark AC power ratio register 54 as internal --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent cbb2f1d commit 8e3d72b

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

‎pv_inverter/packages/deye_hybrid_1p/grid.yaml‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
substitutions:
16+
# Register 54 = "AC power ratio". Only scale when it reads a known 10W/LSB
17+
# value; pass raw watts through otherwise (covers 1, 0/unsupported and the
18+
# not-yet-read NaN state).
19+
func_scale_ac_power: "return (id(ac_power_ratio).state == 10.0f) ? x * 10.0f : x;"
20+
1521
globals:
1622
- id: last_total_energy_bought
1723
type: float
@@ -21,11 +27,29 @@ globals:
2127
restore_value: yes
2228

2329
sensor:
30+
# Register 54 = "AC power ratio". Per the V119 protocol, the AC power registers
31+
# 167-169, 170-172 and 176-178 are reported in units of this value (1W or 10W
32+
# per LSB). Verified on hardware: SG02 10kW reads 10 (10W units), SG04 6kW
33+
# reads 0 (1W units) - so only a value of 10 triggers scaling.
34+
- platform: modbus_controller
35+
modbus_controller_id: ${modbus_controller_id}
36+
name: "AC Power Ratio"
37+
id: ac_power_ratio
38+
register_type: holding
39+
address: 54
40+
value_type: U_WORD
41+
accuracy_decimals: 0
42+
entity_category: diagnostic
43+
icon: "mdi:multiplication"
44+
internal: true
45+
2446
- platform: modbus_controller
2547
modbus_controller_id: ${modbus_controller_id}
2648
name: "Grid L1 Power"
2749
register_type: holding
2850
address: 167
51+
filters:
52+
- lambda: ${func_scale_ac_power}
2953
unit_of_measurement: "W"
3054
device_class: power
3155
state_class: "measurement"
@@ -38,6 +62,8 @@ sensor:
3862
name: "Grid L2 Power"
3963
register_type: holding
4064
address: 168
65+
filters:
66+
- lambda: ${func_scale_ac_power}
4167
unit_of_measurement: "W"
4268
device_class: power
4369
state_class: "measurement"
@@ -50,6 +76,8 @@ sensor:
5076
name: "Grid Power"
5177
register_type: holding
5278
address: 169
79+
filters:
80+
- lambda: ${func_scale_ac_power}
5381
unit_of_measurement: "W"
5482
device_class: power
5583
state_class: "measurement"
@@ -208,6 +236,8 @@ sensor:
208236
name: "External CT L1 Power"
209237
register_type: holding
210238
address: 170
239+
filters:
240+
- lambda: ${func_scale_ac_power}
211241
unit_of_measurement: "W"
212242
device_class: power
213243
accuracy_decimals: 0
@@ -219,6 +249,8 @@ sensor:
219249
name: "External CT L2 Power"
220250
register_type: holding
221251
address: 171
252+
filters:
253+
- lambda: ${func_scale_ac_power}
222254
unit_of_measurement: "W"
223255
device_class: power
224256
accuracy_decimals: 0
@@ -230,6 +262,8 @@ sensor:
230262
name: "External CT Power"
231263
register_type: holding
232264
address: 172
265+
filters:
266+
- lambda: ${func_scale_ac_power}
233267
unit_of_measurement: "W"
234268
device_class: power
235269
accuracy_decimals: 0

‎pv_inverter/packages/deye_hybrid_1p/load.yaml‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
15+
substitutions:
16+
# Register 54 = "AC power ratio" (defined in grid.yaml). Only scale when it
17+
# reads a known 10W/LSB value; pass raw watts through otherwise (covers 1,
18+
# 0/unsupported and the not-yet-read NaN state).
19+
func_scale_ac_power: "return (id(ac_power_ratio).state == 10.0f) ? x * 10.0f : x;"
20+
1421
sensor:
1522
- platform: modbus_controller
1623
modbus_controller_id: ${modbus_controller_id}
@@ -43,6 +50,8 @@ sensor:
4350
name: "Load L1 Power"
4451
register_type: holding
4552
address: 176
53+
filters:
54+
- lambda: ${func_scale_ac_power}
4655
unit_of_measurement: "W"
4756
device_class: power
4857
state_class: "measurement"
@@ -55,6 +64,8 @@ sensor:
5564
name: "Load L2 Power"
5665
register_type: holding
5766
address: 177
67+
filters:
68+
- lambda: ${func_scale_ac_power}
5869
unit_of_measurement: "W"
5970
device_class: power
6071
state_class: "measurement"
@@ -67,6 +78,8 @@ sensor:
6778
name: "Load Power"
6879
register_type: holding
6980
address: 178
81+
filters:
82+
- lambda: ${func_scale_ac_power}
7083
unit_of_measurement: "W"
7184
device_class: power
7285
state_class: "measurement"

0 commit comments

Comments
 (0)