From c3f99e5385ea40f676e99b4573fcf16abe0bc630 Mon Sep 17 00:00:00 2001 From: Emil Axfors <17743298+murre87@users.noreply.github.com> Date: Tue, 10 Nov 2026 15:39:33 +0000 Subject: [PATCH] fix(deye-svk): skip energy headroom when the SoC read fails bat_soc is nil after a failed SoC read, and the headroom calculation then raised a Lua error whenever battery_capacity_wh was set. Guard it the same way as the 50-125k-svk drivers. Version 0.2.2 -> 0.2.3. Reported and fixed in murre87/energywizard#215 by lazgeo. Co-authored-by: lazgeo Signed-off-by: Emil Axfors <17743298+murre87@users.noreply.github.com> --- CHANGELOG.md | 8 ++++++++ drivers/lua/deye-svk.lua | 6 ++++-- manifests/deye-svk.yaml | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aaf58aa..206056c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ ## [Unreleased] +### deye-svk 0.2.3 + +A poll where the SoC read fails left `bat_soc` nil, and the energy headroom +calculation then raised a Lua error when a battery capacity was set. The +headroom is now skipped for that poll, with the same guard the 50-125k-svk +drivers already use. Seen in the field in EnergyWizard, which runs this driver +(murre87/energywizard#215); not reproduced on hardware here. + ### easee_cloud 1.4.1 The driver says its session energy is coarse, with `session_wh_coarse`. Easee diff --git a/drivers/lua/deye-svk.lua b/drivers/lua/deye-svk.lua index d524d2b..204c151 100644 --- a/drivers/lua/deye-svk.lua +++ b/drivers/lua/deye-svk.lua @@ -64,7 +64,7 @@ DRIVER = { id = "deye-svk", name = "Deye SUN hybrid — lean SvK fast-poll variant", manufacturer = "Deye", - version = "0.2.2", + version = "0.2.3", protocols = { "modbus" }, capabilities = { "battery" }, read_only = false, @@ -359,7 +359,9 @@ function driver_poll() -- Energy headroom (Wh) — operator SoC band + capacity, dispatchable. local chg_eh_wh, dis_eh_wh = 0, 0 - if battery_capacity_wh > 0 then + -- bat_soc is nil when the SoC read failed this poll; skip the headroom + -- instead of raising a Lua error (same guard as the 50-125k-svk drivers). + if battery_capacity_wh > 0 and bat_soc then local soc_pct_int = math.floor(bat_soc * 100 + 0.5) local span = soc_max_pct - soc_min_pct if span > 0 then diff --git a/manifests/deye-svk.yaml b/manifests/deye-svk.yaml index ff8c7d6..da38bbe 100644 --- a/manifests/deye-svk.yaml +++ b/manifests/deye-svk.yaml @@ -1,5 +1,5 @@ name: "deye-svk" -version: "0.2.2" +version: "0.2.3" tier: community author: "Sourceful Labs AB" protocol: modbus