Skip to content

Commit de4e7b7

Browse files
committed
feat(sma_sunny_boy): implement energy.pv_inverter.1_phase
1 parent 31f4f70 commit de4e7b7

2 files changed

Lines changed: 88 additions & 22 deletions

File tree

β€Žsolar_inverters/sma_sunny_boy_v3/manifest.ymlβ€Ž

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ contributors:
1212
support:
1313
url: https://go.enapter.com/enapter-blueprint-support
1414
email: support@enapter.com
15+
implements: energy.pv_inverter.1_phase
1516

1617
runtime:
1718
type: lua
1819
requirements:
1920
- lua_api_ver_3
2021
- modbus
21-
opts:
22+
options:
2223
dir: src
2324

2425
configuration:
@@ -42,15 +43,19 @@ properties:
4243
model:
4344
display_name: Model
4445
type: string
45-
serial_num:
46+
vendor:
47+
display_name: Vendor
48+
type: string
49+
serial_number:
4650
display_name: Serial Number
47-
type: integer
48-
fw_ver:
51+
type: string
52+
firmware_version:
4953
display_name: Firmware Version
5054
type: string
51-
rated_power_va:
55+
inverter_nameplate_capacity:
5256
display_name: Rated Power
5357
type: integer
58+
unit: VA
5459
country_code:
5560
display_name: Country Code
5661
type: string
@@ -65,13 +70,40 @@ telemetry:
6570
status:
6671
display_name: Status
6772
type: string
73+
description: Current operational status of the inverter
74+
enum:
75+
"off":
76+
display_name: "Off"
77+
description: Inverter is switched off
78+
standby:
79+
display_name: Standby
80+
description: |
81+
Inverter is in standby mode waiting for startup conditions.
82+
Examples:
83+
- AC grid voltage unavailable for grid-tied inverters
84+
- DC voltage too low (night time for PV inverters)
85+
- External control signal forcing standby
86+
starting:
87+
display_name: Starting
88+
description: Inverter is going through startup procedure
89+
operating:
90+
display_name: Operating
91+
description: Inverter is actively producing power
92+
shutting_down:
93+
display_name: Shutting Down
94+
description: Inverter is going through shutdown procedure
95+
fault:
96+
display_name: Fault
97+
description: Inverter has detected a fault and is not operating
98+
health:
99+
display_name: Health Status
100+
type: string
68101
enum:
69102
- ok
70103
- warning
71104
- fault
72-
- "off"
73-
operation_status:
74-
display_name: Operation Status
105+
operating_status:
106+
display_name: Operating Status
75107
type: string
76108
enum:
77109
- standby
@@ -81,12 +113,10 @@ telemetry:
81113
- shutdown
82114
- waiting_utilities
83115
- bolted
84-
- standalone
85116
- derating
86117
- mpp
87118
- "off"
88119
- stop
89-
- const_voltage
90120
- run
91121
recom_action:
92122
display_name: Recommended Action
@@ -122,10 +152,16 @@ telemetry:
122152
display_name: DC Power
123153
type: float
124154
unit: W
155+
implements: energy.pv_inverter.1_phase.
156+
ac_total_power:
157+
display_name: AC Total Power
158+
type: float
159+
unit: W
125160
ac_power:
126161
display_name: AC Power
127162
type: float
128163
unit: W
164+
implements: energy.pv_inverter.1_phase.ac_l1_power
129165
ac_frequency:
130166
display_name: AC Frequency
131167
type: float
@@ -134,6 +170,12 @@ telemetry:
134170
display_name: AC Voltage
135171
type: float
136172
unit: V
173+
implements: energy.pv_inverter.1_phase.ac_l1_voltage
174+
ac_current:
175+
display_name: AC Current
176+
type: float
177+
unit: A
178+
implements: energy.pv_inverter.1_phase.ac_l1_current
137179
ac_power_var:
138180
display_name: AC Reavtive Power
139181
type: float

β€Žsolar_inverters/sma_sunny_boy_v3/src/main.luaβ€Ž

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ function send_properties()
4949

5050
local properties = {}
5151
properties.model = parse_model(conn:read_u32_enum(30053))
52-
properties.serial_num = conn:read_u32_fix0(30057)
53-
properties.fw_ver = parse_firmware_version(conn:read_u32_fix0(30059))
54-
properties.rated_power_va = conn:read_u32_fix0(40185)
52+
properties.vendor = 'SMA'
53+
properties.serial_number = tostring(conn:read_u32_fix0(30057))
54+
properties.firmware_version = parse_firmware_version(conn:read_u32_fix0(30059))
55+
properties.inverter_nameplate_capacity = conn:read_u32_fix0(40185)
5556
properties.country_code = parse_country_code(conn:read_u32_fix0(40109))
5657
if conn_cfg then
5758
properties.address = conn_cfg.address
@@ -72,14 +73,17 @@ function send_realtime_telemetry()
7273
end
7374

7475
local started = os.clock()
76+
local operating_status = parse_operating_status(conn:read_u32_enum(40029))
7577
local telemetry = {
7678
alerts = parse_alerts(conn:read_u32_enum(30213), conn:read_u32_enum(30247)),
77-
status = parse_status(conn:read_u32_enum(30201)),
78-
operation_status = parse_operation_status(conn:read_u32_enum(40029)),
79+
health = parse_health_status(conn:read_u32_enum(30201)),
80+
operating_status = operating_status,
81+
status = convert_operating_status_to_status(operating_status),
7982

8083
dc_voltage = conn:read_s32_fix2(30771),
8184
dc_power = conn:read_s32_fix0(30773),
8285
ac_power = conn:read_s32_fix0(30775),
86+
ac_total_power = conn:read_s32_fix0(30777),
8387
ac_frequency = conn:read_u32_fix2(30803),
8488
}
8589
telemetry.read_time = math.ceil((os.clock() - started) * 1000) / 1000 -- round
@@ -273,15 +277,15 @@ function parse_model(value)
273277
end
274278
end
275279

276-
function parse_status(value)
280+
function parse_health_status(value)
277281
if not value then
278282
return
279283
end
280284

281285
if value == 35 then
282286
return 'fault'
283287
elseif value == 303 then
284-
return 'off'
288+
return nil
285289
elseif value == 307 then
286290
return 'ok'
287291
elseif value == 455 then
@@ -324,7 +328,7 @@ function parse_grid_relay_closed(value)
324328
end
325329
end
326330

327-
function parse_operation_status(value)
331+
function parse_operating_status(value)
328332
if not value then
329333
return
330334
end
@@ -336,9 +340,9 @@ function parse_operation_status(value)
336340
elseif value == 1393 then
337341
return 'waiting_pv_voltage'
338342
elseif value == 1467 then
339-
return 'start'
343+
return 'starting'
340344
elseif value == 1469 then
341-
return 'shutdown'
345+
return 'shutting_down'
342346
elseif value == 1480 then
343347
return 'waiting_utilities'
344348
elseif value == 1795 then
@@ -356,13 +360,33 @@ function parse_operation_status(value)
356360
elseif value == 443 then
357361
return 'const_voltage'
358362
elseif value == 569 then
359-
return 'run'
363+
return 'operating'
360364
else
361-
enapter.log('Cannot decode operation status: ' .. tostring(value), 'error')
365+
enapter.log('Cannot decode operating status: ' .. tostring(value), 'error')
362366
return tostring(value)
363367
end
364368
end
365369

370+
function convert_operating_status_to_status(value)
371+
if not value then
372+
return
373+
end
374+
375+
if value == 'off' or value == 'stop' then
376+
return 'off'
377+
elseif value == 'standby' or value == 'waiting_pv_voltage' or value == 'waiting_utilities' or value == 'bolted' then
378+
return 'standby'
379+
elseif value == 'start' then
380+
return 'starting'
381+
elseif value == 'derating' or value == 'mpp' or value == 'run' then
382+
return 'operating'
383+
elseif value == 'shutdown' then
384+
return 'shutting_down'
385+
elseif value == 'fault' then
386+
return 'fault'
387+
end
388+
end
389+
366390
function parse_alerts(presence, message)
367391
if not presence and not message then
368392
return

0 commit comments

Comments
Β (0)