3232-- pv: -W generation
3333-- battery:+W charge, -W discharge
3434--
35- -- Meter schema compatibility: some Zap firmware serves the local data model
36- -- v2 (srcful-data-models 2.3.0, "version":"v2" in /data/json), which renames
37- -- every meter field with an "_ac" suffix and lowercases the L1/L2/L3 phase
38- -- prefix (e.g. "L1_V" -> "l1_V_ac", "W" -> "W_ac"; "Hz" is unchanged either
39- -- way). This driver reads both v1 and v2 field names for the meter DER; see
40- -- https://github.com/srcfl/device-drivers/issues/170 for the full v2 scope
41- -- (pv -> solar, battery, DC/AC split), which is not yet covered here.
35+ -- Data model v2: Zap firmware 7.x serves the local API in data model v2
36+ -- ("version":"v2" in /data/json). Older firmware uses the 1.x names. This
37+ -- driver reads both, and a value v2 sends as null stays unknown. v2 moved:
38+ -- meter: W -> W_ac, L1_V -> l1_V_ac, total_import_Wh -> total_import_Wh_ac
39+ -- pv: the DER is "solar"; power and energy are on one side, _ac or _dc;
40+ -- mppt1_V -> mppt[1].V_dc; heatsink_C -> inverter.temperature_C
41+ -- battery: power and energy likewise; V -> V_dc, A -> A_dc;
42+ -- SoC_nom_fract -> soc_nom_fract; heatsink_C -> temperature_C
43+ -- ratings: from /api/devices: rated_power_W_ac on the "inverter" DER,
44+ -- installed_power_W_dc on "solar", rated_power_W_dc and
45+ -- capacity_Wh_dc on "battery"
4246
4347DRIVER = {
4448 host_api_min = 1 ,
4549 host_api_max = 1 ,
4650 id = " zap" ,
4751 name = " Sourceful Zap (P1/HAN meter)" ,
4852 manufacturer = " Sourceful" ,
49- version = " 3.1.2 " ,
53+ version = " 3.1.3 " ,
5054 protocols = { " http" },
5155 capabilities = { " meter" , " pv" , " battery" },
5256 read_only = true ,
@@ -57,7 +61,7 @@ DRIVER = {
5761 verification_status = " production" ,
5862 verified_by = { " erikarenhill@fortytwo:3d" },
5963 verified_at = " 2026-07-17" ,
60- verification_notes = " P1/HAN live-hardware verified against the official Zap Local API (srcful-zap-x-firmware 96e0258). PV aggregation was live-hardware verified on the same API before the 3.0 meter-only cut; it returns as an operator opt-in. Battery payloads are contract-tested against the firmware serializers. Inverters, batteries and chargers found on Zap are not ingested unless read_pv / read_battery is set." ,
64+ verification_notes = " P1/HAN live-hardware verified against the official Zap Local API (srcful-zap-x-firmware 96e0258). PV aggregation was live-hardware verified on the same API before the 3.0 meter-only cut; it returns as an operator opt-in. Battery payloads are contract-tested against the firmware serializers. Inverters, batteries and chargers found on Zap are not ingested unless read_pv / read_battery is set. Data model v2 checked 2026-11-04 on firmware 7.0.3: the meter on a Zap-HAN with a real meter; PV and battery on a Zap-P1 with a simulated Solis, not on a real inverter. " ,
6165 tested_models = { " Sourceful Zap (ESP32-C3 controller firmware)" },
6266 connection_defaults = {
6367 host = " zap.local" ,
@@ -98,6 +102,24 @@ local function number(v)
98102 return n
99103end
100104
105+ local function positive (v )
106+ local n = number (v )
107+ if n ~= nil and n > 0 then return n end
108+ return nil
109+ end
110+
111+ -- Data model v2 sends a power or energy value on one side, _ac or _dc, and the
112+ -- other side null. A 1.x payload has the plain name.
113+ local function sided (raw , name )
114+ return number (raw [name ]) or number (raw [name .. " _ac" ]) or number (raw [name .. " _dc" ])
115+ end
116+
117+ -- A battery's or a string's own voltage and current. An AC-side value is the
118+ -- grid's, not theirs.
119+ local function dc_side (raw , name )
120+ return number (raw [name ]) or number (raw [name .. " _dc" ])
121+ end
122+
101123local function cfg_true (v )
102124 return v == true or v == " true" or v == 1 or v == " 1"
103125end
@@ -252,22 +274,29 @@ local function discover_devices()
252274 if der .type == " meter" then
253275 rec .meter = true
254276 if not first_meter then first_meter = sn end
255- elseif der .type == " pv" then
277+ elseif der .type == " pv" or der . type == " solar " then
256278 if read_pv then
257279 rec .pv = true
258- rec .pv_rated_w = number (der .rated_power ) or number (der .installed_power ) or rec .pv_rated_w
280+ rec .pv_rated_w = number (der .rated_power ) or number (der .installed_power )
281+ or number (der .installed_power_W_dc ) or rec .pv_rated_w
259282 else
260283 add_other (extras , seen , " PV inverter" )
261284 end
262285 elseif der .type == " battery" then
263286 if read_battery then
264287 rec .battery = true
265- rec .battery_rated_w = number (der .rated_power ) or rec .battery_rated_w
266- rec .battery_capacity_wh = number (der .capacity ) or rec .battery_capacity_wh
288+ rec .battery_rated_w = number (der .rated_power ) or number (der .rated_power_W_dc )
289+ or rec .battery_rated_w
290+ rec .battery_capacity_wh = number (der .capacity ) or number (der .capacity_Wh_dc )
291+ or rec .battery_capacity_wh
267292 else
268293 add_other (extras , seen , " battery" )
269294 end
270- elseif der .type == " v2x_charger" or der .type == " ev" then
295+ elseif der .type == " inverter" then
296+ -- The AC stage and rating of a device already
297+ -- listed, not a resource of its own.
298+ rec .inverter_rated_w = positive (der .rated_power_W_ac ) or rec .inverter_rated_w
299+ elseif der .type == " v2x_charger" or der .type == " ev" or der .type == " ev_charger_port" then
271300 add_other (extras , seen , " charger" )
272301 elseif der .type ~= nil and der .type ~= " " and der .type ~= " meter" then
273302 add_other (extras , seen , tostring (der .type ))
@@ -454,6 +483,11 @@ local function snapshot_map()
454483 return out
455484end
456485
486+ local function mppt_input (pv , index )
487+ local inputs = type (pv .mppt ) == " table" and pv .mppt or {}
488+ return type (inputs [index ]) == " table" and inputs [index ] or {}
489+ end
490+
457491local function emit_pv (snapshots )
458492 local source_count = count_kind (" pv" )
459493 if source_count == 0 then return end
@@ -467,14 +501,14 @@ local function emit_pv(snapshots)
467501
468502 for _ , rec in ipairs (tracked ) do
469503 local data = snapshots [rec .sn ]
470- local pv = data and data .pv
504+ local pv = data and ( data .pv or data . solar )
471505 if rec .pv and type (pv ) == " table" then
472- local rated = number (pv .rated_power_W ) or rec .pv_rated_w
506+ local rated = number (pv .rated_power_W ) or rec .inverter_rated_w or rec . pv_rated_w
473507 if rated and rated > 0 then
474508 total_rated_w = total_rated_w + rated
475509 any_rating = true
476510 end
477- local w = sane_power (pv . W , rated )
511+ local w = sane_power (sided ( pv , " W " ) , rated )
478512 if w ~= nil and w <= 0 then
479513 total_w = total_w + w
480514 any_power = true
@@ -485,18 +519,20 @@ local function emit_pv(snapshots)
485519 host .log (" warn" , " Zap: rejected positive PV power for " .. rec .sn .. " : " .. w .. " W" )
486520 end
487521
488- local generation = bounded (pv . total_generation_Wh , 0 , nil )
522+ local generation = bounded (sided ( pv , " total_generation_Wh" ) , 0 , nil )
489523 if generation ~= nil then
490524 total_generation_wh = total_generation_wh + generation
491525 any_generation = true
492526 end
493527
494528 local tag = source_count > 1 and (" _" .. metric_tag (rec .sn )) or " "
495- emit_optional_metric (" pv_heatsink_c" .. tag , number (pv .heatsink_C ), " °C" )
496- emit_optional_metric (" pv_mppt1_v" .. tag , number (pv .mppt1_V ), " V" )
497- emit_optional_metric (" pv_mppt1_a" .. tag , number (pv .mppt1_A ), " A" )
498- emit_optional_metric (" pv_mppt2_v" .. tag , number (pv .mppt2_V ), " V" )
499- emit_optional_metric (" pv_mppt2_a" .. tag , number (pv .mppt2_A ), " A" )
529+ local inverter = type (data .inverter ) == " table" and data .inverter or {}
530+ local mppt1 , mppt2 = mppt_input (pv , 1 ), mppt_input (pv , 2 )
531+ emit_optional_metric (" pv_heatsink_c" .. tag , number (pv .heatsink_C ) or number (inverter .temperature_C ), " °C" )
532+ emit_optional_metric (" pv_mppt1_v" .. tag , number (pv .mppt1_V ) or number (mppt1 .V_dc ), " V" )
533+ emit_optional_metric (" pv_mppt1_a" .. tag , number (pv .mppt1_A ) or number (mppt1 .A_dc ), " A" )
534+ emit_optional_metric (" pv_mppt2_v" .. tag , number (pv .mppt2_V ) or number (mppt2 .V_dc ), " V" )
535+ emit_optional_metric (" pv_mppt2_a" .. tag , number (pv .mppt2_A ) or number (mppt2 .A_dc ), " A" )
500536 end
501537 end
502538
@@ -544,15 +580,15 @@ local function emit_battery(snapshots)
544580 total_rated_w = total_rated_w + rated
545581 any_rating = true
546582 end
547- local w = sane_power (battery . W , rated )
583+ local w = sane_power (sided ( battery , " W " ) , rated )
548584 if w ~= nil then
549585 total_w = total_w + w
550586 any_power = true
551587 end
552588
553589 -- Firmware SoC_nom_fract is 0-1. Identifier keeps the
554590 -- catalog check that soc is already a fraction, not percent.
555- local soc_already_fract = bounded (battery .SoC_nom_fract , 0 , 1 )
591+ local soc_already_fract = bounded (number ( battery .SoC_nom_fract ) or number ( battery . soc_nom_fract ) , 0 , 1 )
556592 local soc = soc_already_fract
557593 if soc ~= nil then
558594 soc_sum = soc_sum + soc
@@ -565,17 +601,17 @@ local function emit_battery(snapshots)
565601 end
566602 end
567603
568- local charge = bounded (battery . total_charge_Wh , 0 , nil )
604+ local charge = bounded (sided ( battery , " total_charge_Wh" ) , 0 , nil )
569605 if charge ~= nil then total_charge_wh = total_charge_wh + charge ; any_charge_energy = true end
570- local discharge = bounded (battery . total_discharge_Wh , 0 , nil )
606+ local discharge = bounded (sided ( battery , " total_discharge_Wh" ) , 0 , nil )
571607 if discharge ~= nil then total_discharge_wh = total_discharge_wh + discharge ; any_discharge_energy = true end
572608
573609 local tag = source_count > 1 and (" _" .. metric_tag (rec .sn )) or " "
574610 if source_count > 1 and w ~= nil then host .emit_metric (" battery_w" .. tag , w , " W" ) end
575611 if source_count > 1 and soc ~= nil then host .emit_metric (" battery_soc" .. tag , soc , " fraction" ) end
576- emit_optional_metric (" battery_dc_v" .. tag , number (battery . V ), " V" )
577- emit_optional_metric (" battery_dc_a" .. tag , number (battery . A ), " A" )
578- emit_optional_metric (" battery_temp_c" .. tag , number (battery .heatsink_C ), " °C" )
612+ emit_optional_metric (" battery_dc_v" .. tag , dc_side (battery , " V " ), " V" )
613+ emit_optional_metric (" battery_dc_a" .. tag , dc_side (battery , " A " ), " A" )
614+ emit_optional_metric (" battery_temp_c" .. tag , number (battery .heatsink_C ) or number ( battery . temperature_C ) , " °C" )
579615 end
580616 end
581617
@@ -600,9 +636,9 @@ local function emit_battery(snapshots)
600636 if any_rating then battery_reading .rated_w = total_rated_w end
601637
602638 if source_count == 1 and single then
603- battery_reading .v = number (single . V )
604- battery_reading .a = number (single . A )
605- battery_reading .temp_c = number (single .heatsink_C )
639+ battery_reading .v = dc_side (single , " V " )
640+ battery_reading .a = dc_side (single , " A " )
641+ battery_reading .temp_c = number (single .heatsink_C ) or number ( single . temperature_C )
606642 end
607643
608644 host .emit (" battery" , battery_reading )
0 commit comments