From f367b6238d32ff2164a2aeb5a8f3d6d0d1d857d6 Mon Sep 17 00:00:00 2001 From: Fredrik Ahlgren Date: Wed, 25 Nov 2026 08:32:21 +0100 Subject: [PATCH 1/2] feat(pixii): report the Pixii's own charge ceiling (2.2.0) A Pixii can stop charging below 100 %. On one site its SoC held at 90 while Core kept planning and ordering charge to 95 %, and the Pixii app showed 100 % (#175). Pixii's Modbus mapping (U8022_06ENG rev 2.20) gives the SoC register as a percentage and names the upper limits on the same scale: SoCMax (40128), SoCRsvMax (40130) and the maximum SoC safety limit (39917, per mille, where "regulation will stop"). The driver reports the lowest valid one as max_soc_fract, the `@srcful/data-models` name for a battery's own maximum SoC. The SoC stays as read: the document does not say how the Pixii app maps it to 100 %. Every limit, the lower ones and the gross SoC go to history so a field check can show which one holds. Refs #175 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Fredrik Ahlgren --- CHANGELOG.md | 12 +++ SUPPORT_STATUS.md | 4 +- devices.yaml | 2 +- docs/WRITING-A-DRIVER.md | 10 ++ drivers/lua/pixii.lua | 89 +++++++++++++++- drivers/tests/test_emit_fields.py | 4 + drivers/tests/test_pixii_charge_ceiling.py | 115 +++++++++++++++++++++ index.yaml | 6 +- manifests/pixii.yaml | 10 +- support-status.json | 2 +- 10 files changed, 243 insertions(+), 11 deletions(-) create mode 100644 drivers/tests/test_pixii_charge_ceiling.py diff --git a/CHANGELOG.md b/CHANGELOG.md index e716fb78..b70af14a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ ## [Unreleased] +### pixii 2.2.0 + +A Pixii can stop charging below 100 %. On one site its SoC held at 90 while +Core kept planning and ordering charge to 95 %, and the Pixii app showed +100 % (#175). The driver now reads the upper SoC limits Pixii documents on the +same scale as its SoC (SoCMax 40128, SoCRsvMax 40130 and the maximum SoC +safety limit 39917) and reports the lowest as `max_soc_fract`. Core plans and +dispatches to it (srcfl/ftw, paired PR). The SoC is still reported as read: +Pixii does not document how its app maps the gross SoC to 100 %. Every limit, +the lower ones and the gross SoC (39915) also go to history, so a field check +can show which limit holds. + ### zaptec_cloud 0.3.0 First field test (Zaptec Go, 20 A main fuse, two one-phase cars) found diff --git a/SUPPORT_STATUS.md b/SUPPORT_STATUS.md index dc869d3e..5a0c423b 100644 --- a/SUPPORT_STATUS.md +++ b/SUPPORT_STATUS.md @@ -112,8 +112,8 @@ Catalog source is not proof that a target can install or run a driver. | p1_hdlc | 2.0.2 | blixt-l1 | not_assessed | — | not_recorded | not_assessed | | p1_meter | 2.0.2 | ftw-core | not_assessed | — | not_recorded | not_assessed | | p1_meter | 2.0.2 | blixt-l1 | not_assessed | — | not_recorded | not_assessed | -| pixii | 2.1.9 | ftw-core | not_assessed | — | not_recorded | not_assessed | -| pixii | 2.1.9 | blixt-l1 | not_assessed | — | not_recorded | not_assessed | +| pixii | 2.2.0 | ftw-core | not_assessed | — | not_recorded | not_assessed | +| pixii | 2.2.0 | blixt-l1 | not_assessed | — | not_recorded | not_assessed | | pixii_pv | 0.3.3 | ftw-core | not_assessed | — | not_recorded | not_assessed | | pixii_pv | 0.3.3 | blixt-l1 | not_assessed | — | not_recorded | not_assessed | | remne_p1ib | 0.1.0 | ftw-core | not_assessed | — | not_recorded | not_assessed | diff --git a/devices.yaml b/devices.yaml index f4fb4f3e..f45d200d 100644 --- a/devices.yaml +++ b/devices.yaml @@ -1045,7 +1045,7 @@ manufacturers: protocols: - protocol: modbus driver: "pixii" - version: "2.1.9" + version: "2.2.0" ders: [battery, meter] control: true firmware_versions: "" diff --git a/docs/WRITING-A-DRIVER.md b/docs/WRITING-A-DRIVER.md index 6deef1b7..4e8dc31d 100644 --- a/docs/WRITING-A-DRIVER.md +++ b/docs/WRITING-A-DRIVER.md @@ -556,3 +556,13 @@ and, when the device reports them, `battery_cell_temp_min_c`, `battery_cell_temp_max_c`, `battery_charge_limit_a` and `battery_discharge_limit_a`. The inverter's own temperature goes in `inverter_temp_c`. + +### The battery's own charge ceiling + +Some batteries stop charging below 100 % at a limit of their own. When the +device reports that limit, send it as `max_soc_fract` on `battery`, 0..1, on +the same scale as `soc`. It is the name @srcful/data-models gives a battery's +own maximum SoC. Core plans and dispatches to the lower of it and its own +ceiling. Leave it out when the read fails, and never rescale `soc` to make the +limit read as 100 % unless the vendor documents that mapping. `pixii` is the +worked example. diff --git a/drivers/lua/pixii.lua b/drivers/lua/pixii.lua index d2e8f8d4..af6cae23 100644 --- a/drivers/lua/pixii.lua +++ b/drivers/lua/pixii.lua @@ -29,7 +29,7 @@ DRIVER = { id = "pixii", name = "Pixii PowerShaper", manufacturer = "Pixii", - version = "2.1.9", + version = "2.2.0", protocols = { "modbus" }, capabilities = { "battery", "meter" }, description = "Pixii PowerShaper commercial battery storage via Modbus TCP.", @@ -380,6 +380,91 @@ local function emit_troubleshooting_metrics(setpoint_pixii_w) end end +---------------------------------------------------------------------------- +-- Charge ceiling +---------------------------------------------------------------------------- +-- A Pixii can stop charging below 100 %. On one site the SoC register held +-- at 90 while charge orders went undelivered and the Pixii app showed 100 % +-- (srcfl/device-drivers#175). Pixii's Modbus mapping (U8022_06ENG rev 2.20) +-- gives the SoC register as "State of charge in %" and 39915 as the gross +-- SoC, so the SoC is reported as read. The same document names the upper +-- limits, on the same scale: +-- +-- 40128 SoCMax maximum state of charge (SoC_SF, 40177) +-- 40129 SoCMin minimum state of charge (SoC_SF, 40177) +-- 40130 SoCRsvMax maximum reserved state of charge (SoC_SF, 40177) +-- 40131 SoCRsvMin minimum reserved state of charge (SoC_SF, 40177) +-- 39915 average battery SoC, gross (per mille) +-- 39916 battery minimum SoC safety limit, gross (per mille) +-- 39917 battery maximum SoC safety limit, gross: "regulation will stop" +-- +-- Its remaining charging energy (39932) is SoH x (Max Reserved SoC - SoC) x +-- nominal energy, so charging ends at the reserved maximum. The lowest valid +-- upper limit goes to Core as max_soc_fract, the @srcful/data-models name +-- for a battery's own maximum SoC. How the Pixii app turns the gross SoC +-- into its 100 % is not documented, so no remap is made here. Every limit +-- also goes to history, which shows a field check which one holds. +local REG_SOC_LIMITS = 40128 -- SoCMax, SoCMin, SoCRsvMax, SoCRsvMin +local REG_GROSS_SOC = 39915 -- gross SoC, min and max safety limits +local CEILING_METRICS = { + "battery_soc_max_pct", + "battery_soc_reserve_max_pct", + "battery_soc_safety_max_pct", +} +local last_ceiling_key = nil + +local function soc_point_pct(raw, soc_sf) + if raw == nil or raw == 0xffff then return nil end + return scale(raw, soc_sf) +end + +local function per_mille_pct(raw) + if raw == nil or raw == 0xffff then return nil end + return raw / 10 +end + +-- Returns the charge ceiling as a fraction, or nil when no limit was read. +-- A limit of 0, above 100 % or marked unsupported (0xffff) is not one. +local function read_charge_ceiling(soc_sf) + local limits = {} + local regs = probe_read(REG_SOC_LIMITS, 4, "holding") + if regs and regs[4] ~= nil then + limits.battery_soc_max_pct = soc_point_pct(regs[1], soc_sf) + limits.battery_soc_min_pct = soc_point_pct(regs[2], soc_sf) + limits.battery_soc_reserve_max_pct = soc_point_pct(regs[3], soc_sf) + limits.battery_soc_reserve_min_pct = soc_point_pct(regs[4], soc_sf) + end + local gross = probe_read(REG_GROSS_SOC, 3, "holding") + if gross and gross[3] ~= nil then + limits.battery_soc_gross_pct = per_mille_pct(gross[1]) + limits.battery_soc_safety_min_pct = per_mille_pct(gross[2]) + limits.battery_soc_safety_max_pct = per_mille_pct(gross[3]) + end + for name, value in pairs(limits) do + host.emit_metric(name, value) + end + + local ceiling, source = nil, nil + for _, name in ipairs(CEILING_METRICS) do + local pct = limits[name] + if pct ~= nil and pct > 0 and pct <= 100 and (ceiling == nil or pct < ceiling) then + ceiling, source = pct, name + end + end + local key = ceiling and (tostring(ceiling) .. "/" .. source) or "none" + if key ~= last_ceiling_key then + if ceiling ~= nil then + host.log("info", "Pixii: charge ceiling " .. tostring(ceiling) + .. " % from " .. source) + elseif last_ceiling_key ~= nil then + host.log("info", "Pixii: no charge ceiling read; Core uses its own") + end + last_ceiling_key = key + end + if ceiling == nil then return nil end + return ceiling / 100 +end + ---------------------------------------------------------------------------- -- Fingerprint ---------------------------------------------------------------------------- @@ -587,6 +672,8 @@ function driver_poll() battery_event1 = status.event1, } if bat_soc ~= nil then battery.soc = bat_soc end + local soc_ceiling = read_charge_ceiling(soc_sf) + if soc_ceiling ~= nil then battery.max_soc_fract = soc_ceiling end host.emit("battery", battery) -- Diagnostics: long-format TS DB host.emit_metric("battery_dc_v", bat_v) diff --git a/drivers/tests/test_emit_fields.py b/drivers/tests/test_emit_fields.py index 768558dc..4cc2e4e1 100644 --- a/drivers/tests/test_emit_fields.py +++ b/drivers/tests/test_emit_fields.py @@ -84,6 +84,10 @@ # "standby" or "starting" (docs/WRITING-A-DRIVER.md, What a battery # can do now). "device_state", + # The battery's own upper SoC limit, 0..1. @srcful/data-models has it + # as battery metadata; FTW has no metadata channel, so it rides on the + # reading (docs/WRITING-A-DRIVER.md, The battery's own charge ceiling). + "max_soc_fract", }, "v2x_charger": { "w", "a", "v", "hz", diff --git a/drivers/tests/test_pixii_charge_ceiling.py b/drivers/tests/test_pixii_charge_ceiling.py new file mode 100644 index 00000000..8f0e7751 --- /dev/null +++ b/drivers/tests/test_pixii_charge_ceiling.py @@ -0,0 +1,115 @@ +"""Pixii reports the highest charge level it will accept. + +On one site the Pixii SoC register held at 90 while charge orders went +undelivered, and the Pixii app showed 100 % (srcfl/device-drivers#175). Pixii's +Modbus mapping names its upper SoC limits on the same scale as the SoC: SunSpec +SoCMax (40128) and SoCRsvMax (40130), and the maximum SoC safety limit (39917) +in tenths of a percent. The driver passes the lowest valid one to Core as +max_soc_fract and leaves the SoC as read. +""" + +from pathlib import Path +import subprocess + +import pytest + +ROOT = Path(__file__).resolve().parents[2] +LUA = ROOT / "lua55" +pytestmark = pytest.mark.skipif(not LUA.exists(), reason="run make test-driver ID=pixii") + + +def run_lua(body: str) -> None: + script = ''' +package.path = "drivers/tests/lua_harness/?.lua;" .. package.path +require("host_mock") +host.reset() +host._modbus_registers.holding[40000] = {0x5375, 0x6e53} +host._modbus_registers.holding[40132] = 90 +host._modbus_registers.holding[40137] = 4 +host._modbus_registers.holding[40138] = 0 +host._modbus_registers.holding[40143] = 3 +dofile("drivers/lua/pixii.lua") +driver_init({}) +local function poll() + host._metrics = {} + driver_poll() + return host._emitted.battery[#host._emitted.battery] +end +local function near(a, b) + return a ~= nil and math.abs(a - b) < 1e-9 +end +''' + body + result = subprocess.run([str(LUA), "-e", script], cwd=ROOT, text=True, capture_output=True) + assert result.returncode == 0, result.stdout + result.stderr + + +def test_reserved_maximum_is_the_ceiling_and_soc_is_not_remapped() -> None: + run_lua(''' +host._modbus_registers.holding[40128] = {100, 5, 90, 10} +local battery = poll() +assert(near(battery.max_soc_fract, 0.90), "ceiling " .. tostring(battery.max_soc_fract)) +assert(near(battery.soc, 0.90), "SoC was remapped: " .. tostring(battery.soc)) +assert(host._metrics.battery_soc_max_pct.value == 100) +assert(host._metrics.battery_soc_min_pct.value == 5) +assert(host._metrics.battery_soc_reserve_max_pct.value == 90) +assert(host._metrics.battery_soc_reserve_min_pct.value == 10) +local logged = false +for _, message in ipairs(host._logs) do + if message:find("charge ceiling 90", 1, true) + and message:find("battery_soc_reserve_max_pct", 1, true) then + logged = true + end +end +assert(logged, "the ceiling and its source were not logged") +''') + + +def test_lowest_upper_limit_wins_and_safety_limit_is_per_mille() -> None: + run_lua(''' +host._modbus_registers.holding[40128] = {100, 5, 95, 10} +host._modbus_registers.holding[39915] = {899, 50, 900} +local battery = poll() +assert(near(battery.max_soc_fract, 0.90), "ceiling " .. tostring(battery.max_soc_fract)) +assert(near(host._metrics.battery_soc_gross_pct.value, 89.9)) +assert(near(host._metrics.battery_soc_safety_min_pct.value, 5)) +assert(near(host._metrics.battery_soc_safety_max_pct.value, 90)) +''') + + +def test_soc_scale_factor_applies_to_the_limits() -> None: + run_lua(''' +host._modbus_registers.holding[40177] = 0xffff -- SoC_SF = -1 +host._modbus_registers.holding[40132] = 900 +host._modbus_registers.holding[40128] = {1000, 50, 900, 100} +local battery = poll() +assert(near(battery.soc, 0.90), "SoC " .. tostring(battery.soc)) +assert(near(battery.max_soc_fract, 0.90), "ceiling " .. tostring(battery.max_soc_fract)) +''') + + +@pytest.mark.parametrize("raw", ["0", "0xffff", "1010"]) +def test_zero_unsupported_or_impossible_limits_are_not_a_ceiling(raw: str) -> None: + run_lua(f''' +host._modbus_registers.holding[40128] = {{{raw}, 0, {raw}, 0}} +host._modbus_registers.holding[39915] = {{0, 0, {raw}}} +local battery = poll() +assert(battery.max_soc_fract == nil, "invented ceiling " .. tostring(battery.max_soc_fract)) +assert(near(battery.soc, 0.90), "SoC changed without a ceiling") +''') + + +def test_failed_limit_reads_leave_the_ceiling_out() -> None: + run_lua(''' +host._modbus_registers.holding[40128] = {100, 5, 90, 10} +assert(near(poll().max_soc_fract, 0.90)) +host._modbus_read_fail_addresses[40128] = "timeout" +host._modbus_read_fail_addresses[39915] = "timeout" +local battery = poll() +assert(battery.max_soc_fract == nil, "a failed read kept or invented a ceiling") +for _, name in ipairs({"battery_soc_max_pct", "battery_soc_reserve_max_pct", + "battery_soc_safety_max_pct", "battery_soc_gross_pct"}) do + assert(host._metrics[name] == nil, name .. " emitted without a read") +end +assert(near(battery.soc, 0.90), "a failed limit read lost the SoC") +assert(#host._emitted.meter == 2, "a failed limit read stopped meter telemetry") +''') diff --git a/index.yaml b/index.yaml index b222c7ff..8186739b 100644 --- a/index.yaml +++ b/index.yaml @@ -508,14 +508,14 @@ drivers: size_bytes: 19344 sha256: "29f2bd2f73c0d39d809839ca60b40c3e4281f1dda267ba2b26e66bd9ab80c27b" - name: "pixii" - version: "2.1.9" + version: "2.2.0" tier: core protocol: modbus connectivity: local ders: [battery, meter] control: true - size_bytes: 32519 - sha256: "77e233e2d24e970ebff8eaacd67967f57b651677d25ce7b57a1f97c3eaeb71fe" + size_bytes: 36493 + sha256: "76b886fdd20e89f7fd2752ce4e1689c0545dccf0f3e02c6ee124478653e92615" - name: "pixii_pv" version: "0.3.3" tier: core diff --git a/manifests/pixii.yaml b/manifests/pixii.yaml index 083a6fc6..3c902ff6 100644 --- a/manifests/pixii.yaml +++ b/manifests/pixii.yaml @@ -1,5 +1,5 @@ name: "pixii" -version: "2.1.9" +version: "2.2.0" tier: core author: "Sourceful Labs AB and community contributors" protocol: modbus @@ -16,6 +16,10 @@ tested_devices: min_driver_version: "1.1.0" min_host_version: "2.0.0" upstream_docs: + - url: "https://www.pixii.com/wp-content/uploads/2026/06/U8022_06ENG_2v20_Configuration_Guide_Pixii_Powershaper_Modbus_Mapping.pdf" + title: "Pixii PowerShaper Modbus Mapping: SoC limits 40128-40131 and 39915-39917" + kind: register_map + url_stability: stable - url: "https://sunspec.org/wp-content/uploads/2025/01/SunSpec-Device-Information-Model-Specificiation-V1-1-final-1.pdf" title: "SunSpec Device Information Model 1.1: unsupported enum16 and uint16 values" kind: manual @@ -24,9 +28,9 @@ upstream_docs: title: "SunSpec model 802: battery charge and control states" kind: register_map url_stability: stable -size_bytes: 32519 +size_bytes: 36493 dkb_id: "pixii" -sha256: "77e233e2d24e970ebff8eaacd67967f57b651677d25ce7b57a1f97c3eaeb71fe" +sha256: "76b886fdd20e89f7fd2752ce4e1689c0545dccf0f3e02c6ee124478653e92615" signature: "" bytecode_sha256: "" diff --git a/support-status.json b/support-status.json index 63fbc010..6aa3638d 100644 --- a/support-status.json +++ b/support-status.json @@ -1136,7 +1136,7 @@ }, { "catalog_source": true, - "catalog_version": "2.1.9", + "catalog_version": "2.2.0", "driver_id": "pixii", "targets": { "blixt-l1": { From 0fd3b1a67cf84bacafa7c36eed39ddc63918a0f2 Mon Sep 17 00:00:00 2001 From: Fredrik Ahlgren Date: Wed, 25 Nov 2026 08:54:52 +0100 Subject: [PATCH 2/2] fix(pixii): take the ceiling only from SoC-scale limits, with a floor Review findings: - 39917 is a gross safety limit in tenths of a percent, and Pixii does not document how gross relates to the SoC at 40132. max_soc_fract now comes only from SoCMax (40128) and SoCRsvMax (40130), which share the SoC's scale factor. 39915-39917 stay in history. - A limit below 50 % is taken as a misread and left out. Real ceilings sit around 80-100 %, and Core applies the same bound. - read_sf treats 0x8000, SunSpec's unimplemented scale factor, as no scaling. Read as -32768 it scaled the SoC and every limit to zero. Refs #175 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Fredrik Ahlgren --- CHANGELOG.md | 14 ++++--- docs/WRITING-A-DRIVER.md | 12 +++--- drivers/lua/pixii.lua | 43 ++++++++++++---------- drivers/tests/test_pixii_charge_ceiling.py | 37 ++++++++++++++----- index.yaml | 4 +- manifests/pixii.yaml | 4 +- 6 files changed, 69 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b70af14a..7aefa4df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,12 +7,14 @@ A Pixii can stop charging below 100 %. On one site its SoC held at 90 while Core kept planning and ordering charge to 95 %, and the Pixii app showed 100 % (#175). The driver now reads the upper SoC limits Pixii documents on the -same scale as its SoC (SoCMax 40128, SoCRsvMax 40130 and the maximum SoC -safety limit 39917) and reports the lowest as `max_soc_fract`. Core plans and -dispatches to it (srcfl/ftw, paired PR). The SoC is still reported as read: -Pixii does not document how its app maps the gross SoC to 100 %. Every limit, -the lower ones and the gross SoC (39915) also go to history, so a field check -can show which limit holds. +same scale as its SoC, SoCMax (40128) and SoCRsvMax (40130), and reports the +lower as `max_soc_fract`. A limit below 50 % is taken as a misread and left +out. Core plans and dispatches to it (srcfl/ftw#2083). The SoC is still +reported as read: Pixii does not document how its app maps it to 100 %. The +lower limits and the gross SoC with its safety limits (39915-39917, on a scale +Pixii does not relate to the SoC) go to history only, so a field check can +show which limit holds. An unimplemented SunSpec scale factor (0x8000) now +reads as no scaling instead of scaling every value to zero. ### zaptec_cloud 0.3.0 diff --git a/docs/WRITING-A-DRIVER.md b/docs/WRITING-A-DRIVER.md index 4e8dc31d..33159815 100644 --- a/docs/WRITING-A-DRIVER.md +++ b/docs/WRITING-A-DRIVER.md @@ -560,9 +560,9 @@ and, when the device reports them, `battery_cell_temp_min_c`, ### The battery's own charge ceiling Some batteries stop charging below 100 % at a limit of their own. When the -device reports that limit, send it as `max_soc_fract` on `battery`, 0..1, on -the same scale as `soc`. It is the name @srcful/data-models gives a battery's -own maximum SoC. Core plans and dispatches to the lower of it and its own -ceiling. Leave it out when the read fails, and never rescale `soc` to make the -limit read as 100 % unless the vendor documents that mapping. `pixii` is the -worked example. +device reports that limit on the same scale as `soc`, send it as +`max_soc_fract` on `battery`, 0..1. It is the name @srcful/data-models gives a +battery's own maximum SoC. Core plans and dispatches to the lower of it and +its own ceiling. Leave it out when the read fails or the value is below 50 %, +which Core takes as a misread. Never rescale `soc` to make the limit read as +100 % unless the vendor documents that mapping. `pixii` is the worked example. diff --git a/drivers/lua/pixii.lua b/drivers/lua/pixii.lua index af6cae23..88c63e98 100644 --- a/drivers/lua/pixii.lua +++ b/drivers/lua/pixii.lua @@ -223,10 +223,11 @@ end -- Read a single i16-typed scale factor register. SF=0 (x1 scaling) is the -- right fallback when the register is absent, and matches units where it --- exists but reads zero. +-- exists but reads zero. SunSpec marks an unimplemented scale factor 0x8000; +-- read as -32768 it would scale every value to zero. local function read_sf(addr) local regs = probe_read(addr, 1, "holding") - if regs then return host.decode_i16(regs[1]) end + if regs and regs[1] ~= 0x8000 then return host.decode_i16(regs[1]) end return 0 end @@ -386,31 +387,32 @@ end -- A Pixii can stop charging below 100 %. On one site the SoC register held -- at 90 while charge orders went undelivered and the Pixii app showed 100 % -- (srcfl/device-drivers#175). Pixii's Modbus mapping (U8022_06ENG rev 2.20) --- gives the SoC register as "State of charge in %" and 39915 as the gross --- SoC, so the SoC is reported as read. The same document names the upper --- limits, on the same scale: +-- gives the SoC register as "State of charge in %", so the SoC is reported +-- as read. On the same scale it names the upper limits: -- -- 40128 SoCMax maximum state of charge (SoC_SF, 40177) -- 40129 SoCMin minimum state of charge (SoC_SF, 40177) -- 40130 SoCRsvMax maximum reserved state of charge (SoC_SF, 40177) -- 40131 SoCRsvMin minimum reserved state of charge (SoC_SF, 40177) --- 39915 average battery SoC, gross (per mille) --- 39916 battery minimum SoC safety limit, gross (per mille) --- 39917 battery maximum SoC safety limit, gross: "regulation will stop" -- -- Its remaining charging energy (39932) is SoH x (Max Reserved SoC - SoC) x --- nominal energy, so charging ends at the reserved maximum. The lowest valid --- upper limit goes to Core as max_soc_fract, the @srcful/data-models name --- for a battery's own maximum SoC. How the Pixii app turns the gross SoC --- into its 100 % is not documented, so no remap is made here. Every limit --- also goes to history, which shows a field check which one holds. +-- nominal energy, so charging ends at the reserved maximum. The lower of +-- SoCMax and SoCRsvMax goes to Core as max_soc_fract, the +-- @srcful/data-models name for a battery's own maximum SoC. +-- +-- 39915-39917 are the gross SoC and its minimum and maximum safety limits, +-- in tenths of a percent. How gross relates to the SoC above is not +-- documented, so they go to history only, never into the ceiling. Nor is +-- it documented how the Pixii app turns a SoC into its 100 %, so no remap +-- is made. Every value goes to history, which shows a field check which +-- limit holds. local REG_SOC_LIMITS = 40128 -- SoCMax, SoCMin, SoCRsvMax, SoCRsvMin local REG_GROSS_SOC = 39915 -- gross SoC, min and max safety limits -local CEILING_METRICS = { - "battery_soc_max_pct", - "battery_soc_reserve_max_pct", - "battery_soc_safety_max_pct", -} +local CEILING_METRICS = { "battery_soc_max_pct", "battery_soc_reserve_max_pct" } +-- Real ceilings sit around 80-100 %. A limit below this is taken as a +-- misread, not a ceiling: it would stop all charging. Core applies the same +-- bound. +local MIN_CEILING_PCT = 50 local last_ceiling_key = nil local function soc_point_pct(raw, soc_sf) @@ -424,7 +426,8 @@ local function per_mille_pct(raw) end -- Returns the charge ceiling as a fraction, or nil when no limit was read. --- A limit of 0, above 100 % or marked unsupported (0xffff) is not one. +-- A limit below MIN_CEILING_PCT, above 100 % or marked unsupported (0xffff) +-- is not one. local function read_charge_ceiling(soc_sf) local limits = {} local regs = probe_read(REG_SOC_LIMITS, 4, "holding") @@ -447,7 +450,7 @@ local function read_charge_ceiling(soc_sf) local ceiling, source = nil, nil for _, name in ipairs(CEILING_METRICS) do local pct = limits[name] - if pct ~= nil and pct > 0 and pct <= 100 and (ceiling == nil or pct < ceiling) then + if pct ~= nil and pct >= MIN_CEILING_PCT and pct <= 100 and (ceiling == nil or pct < ceiling) then ceiling, source = pct, name end end diff --git a/drivers/tests/test_pixii_charge_ceiling.py b/drivers/tests/test_pixii_charge_ceiling.py index 8f0e7751..2de60a9f 100644 --- a/drivers/tests/test_pixii_charge_ceiling.py +++ b/drivers/tests/test_pixii_charge_ceiling.py @@ -2,10 +2,10 @@ On one site the Pixii SoC register held at 90 while charge orders went undelivered, and the Pixii app showed 100 % (srcfl/device-drivers#175). Pixii's -Modbus mapping names its upper SoC limits on the same scale as the SoC: SunSpec -SoCMax (40128) and SoCRsvMax (40130), and the maximum SoC safety limit (39917) -in tenths of a percent. The driver passes the lowest valid one to Core as -max_soc_fract and leaves the SoC as read. +Modbus mapping names its upper SoC limits on the same scale as the SoC, SunSpec +SoCMax (40128) and SoCRsvMax (40130). The driver passes the lower valid one to +Core as max_soc_fract and leaves the SoC as read. The gross safety limits +(39915-39917) are on an undocumented scale and go to history only. """ from pathlib import Path @@ -64,12 +64,21 @@ def test_reserved_maximum_is_the_ceiling_and_soc_is_not_remapped() -> None: ''') -def test_lowest_upper_limit_wins_and_safety_limit_is_per_mille() -> None: +def test_lower_of_soc_max_and_reserved_maximum_wins() -> None: + run_lua(''' +host._modbus_registers.holding[40128] = {92, 5, 95, 10} +local battery = poll() +assert(near(battery.max_soc_fract, 0.92), "ceiling " .. tostring(battery.max_soc_fract)) +''') + + +def test_gross_safety_limits_are_history_only() -> None: run_lua(''' host._modbus_registers.holding[40128] = {100, 5, 95, 10} host._modbus_registers.holding[39915] = {899, 50, 900} local battery = poll() -assert(near(battery.max_soc_fract, 0.90), "ceiling " .. tostring(battery.max_soc_fract)) +assert(near(battery.max_soc_fract, 0.95), "a gross safety limit set the ceiling: " + .. tostring(battery.max_soc_fract)) assert(near(host._metrics.battery_soc_gross_pct.value, 89.9)) assert(near(host._metrics.battery_soc_safety_min_pct.value, 5)) assert(near(host._metrics.battery_soc_safety_max_pct.value, 90)) @@ -87,11 +96,21 @@ def test_soc_scale_factor_applies_to_the_limits() -> None: ''') -@pytest.mark.parametrize("raw", ["0", "0xffff", "1010"]) -def test_zero_unsupported_or_impossible_limits_are_not_a_ceiling(raw: str) -> None: +def test_unimplemented_scale_factor_does_not_zero_the_soc() -> None: + run_lua(''' +host._modbus_registers.holding[40177] = 0x8000 -- SunSpec: not implemented +host._modbus_registers.holding[40128] = {100, 5, 90, 10} +local battery = poll() +assert(near(battery.soc, 0.90), "SoC " .. tostring(battery.soc)) +assert(near(battery.max_soc_fract, 0.90), "ceiling " .. tostring(battery.max_soc_fract)) +''') + + +@pytest.mark.parametrize("raw", ["0", "0xffff", "1010", "49"]) +def test_zero_unsupported_implausible_or_impossible_limits_are_not_a_ceiling(raw: str) -> None: run_lua(f''' host._modbus_registers.holding[40128] = {{{raw}, 0, {raw}, 0}} -host._modbus_registers.holding[39915] = {{0, 0, {raw}}} +host._modbus_registers.holding[39915] = {{0, 0, 900}} local battery = poll() assert(battery.max_soc_fract == nil, "invented ceiling " .. tostring(battery.max_soc_fract)) assert(near(battery.soc, 0.90), "SoC changed without a ceiling") diff --git a/index.yaml b/index.yaml index 8186739b..670abd1d 100644 --- a/index.yaml +++ b/index.yaml @@ -514,8 +514,8 @@ drivers: connectivity: local ders: [battery, meter] control: true - size_bytes: 36493 - sha256: "76b886fdd20e89f7fd2752ce4e1689c0545dccf0f3e02c6ee124478653e92615" + size_bytes: 36746 + sha256: "11a8e4e952f00746107d5760fdde2efb22befd25fca06792b23e4caf6b74b6a6" - name: "pixii_pv" version: "0.3.3" tier: core diff --git a/manifests/pixii.yaml b/manifests/pixii.yaml index 3c902ff6..55027b8d 100644 --- a/manifests/pixii.yaml +++ b/manifests/pixii.yaml @@ -28,9 +28,9 @@ upstream_docs: title: "SunSpec model 802: battery charge and control states" kind: register_map url_stability: stable -size_bytes: 36493 +size_bytes: 36746 dkb_id: "pixii" -sha256: "76b886fdd20e89f7fd2752ce4e1689c0545dccf0f3e02c6ee124478653e92615" +sha256: "11a8e4e952f00746107d5760fdde2efb22befd25fca06792b23e4caf6b74b6a6" signature: "" bytecode_sha256: ""