diff --git a/CHANGELOG.md b/CHANGELOG.md index e716fb7..7aefa4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,20 @@ ## [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) 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 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 dc869d3..5a0c423 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 f4fb4f3..f45d200 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 6deef1b..3315981 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 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 d2e8f8d..88c63e9 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.", @@ -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 @@ -380,6 +381,93 @@ 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 %", 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) +-- +-- Its remaining charging energy (39932) is SoH x (Max Reserved SoC - SoC) x +-- 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" } +-- 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) + 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 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") + 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 >= MIN_CEILING_PCT 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 +675,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 768558d..4cc2e4e 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 0000000..2de60a9 --- /dev/null +++ b/drivers/tests/test_pixii_charge_ceiling.py @@ -0,0 +1,134 @@ +"""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). 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 +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_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.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)) +''') + + +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)) +''') + + +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, 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") +''') + + +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 b222c7f..670abd1 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: 36746 + sha256: "11a8e4e952f00746107d5760fdde2efb22befd25fca06792b23e4caf6b74b6a6" - name: "pixii_pv" version: "0.3.3" tier: core diff --git a/manifests/pixii.yaml b/manifests/pixii.yaml index 083a6fc..55027b8 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: 36746 dkb_id: "pixii" -sha256: "77e233e2d24e970ebff8eaacd67967f57b651677d25ce7b57a1f97c3eaeb71fe" +sha256: "11a8e4e952f00746107d5760fdde2efb22befd25fca06792b23e4caf6b74b6a6" signature: "" bytecode_sha256: "" diff --git a/support-status.json b/support-status.json index 63fbc01..6aa3638 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": {