Zendure SolarFlow 2400 AC+
Moderators: leecollings, remb0
-
Henry
- Posts: 44
- Joined: Tuesday 06 March 2018 18:56
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.7
- Location: Netherlands
- Contact:
Zendure SolarFlow 2400 AC+
Good morning,
I recently got a Zendure SolarFlow 2400 AC+ and want to see some stats on the dashboard. I can't find an integration for this so what is the best approach for this? I'm running Domoticz 2026.2 and mosquitto.
I recently got a Zendure SolarFlow 2400 AC+ and want to see some stats on the dashboard. I can't find an integration for this so what is the best approach for this? I'm running Domoticz 2026.2 and mosquitto.
-
Henry
- Posts: 44
- Joined: Tuesday 06 March 2018 18:56
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.7
- Location: Netherlands
- Contact:
Re: Zendure SolarFlow 2400 AC+
I found out that the stats can be collected from http://[ZENDURE_IP]/properties/report. I've created a DZVents script that collects the data every minute and store it in some dummy devices. Now I have the battery in the Energy Dashboard and on my dynamic home dashboard.
- waltervl
- Posts: 7030
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2026.3
- Location: NL
- Contact:
Re: Zendure SolarFlow 2400 AC+
There is also this topic where the MQTT option was discussed: viewtopic.php?t=42929
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
Henry
- Posts: 44
- Joined: Tuesday 06 March 2018 18:56
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.7
- Location: Netherlands
- Contact:
Re: Zendure SolarFlow 2400 AC+
Thank you. The topic is a bit older but I guess it's worth trying mqtt. For now the direct api works ok.
-
pgit
- Posts: 17
- Joined: Monday 04 August 2014 17:54
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Zendure SolarFlow 2400 AC+
Great, I'm trying to do the same thing, but programming in LUA is not really my thing;Henry wrote: Thursday 06 August 2026 12:51 I found out that the stats can be collected from http://[ZENDURE_IP]/properties/report. I've created a DZVents script that collects the data every minute and store it in some dummy devices. Now I have the battery in the Energy Dashboard and on my dynamic home dashboard.
I'm struggling to togle virtual switches from the values (0 or 1) from the report page...
Would you mind sharing your script?
And which property did you use in the energy dashboard?
I see there is one for battery charge power and a seperate one for battery discharge power, but I can only add one of them in the dashboard...
How did you combine them into one?
Thanks in advance!
-
Henry
- Posts: 44
- Joined: Tuesday 06 March 2018 18:56
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.7
- Location: Netherlands
- Contact:
Re: Zendure SolarFlow 2400 AC+
This is the lua script i'm using:
I'm only reading the vaules, not writing anything. I hope the description in the code says enough.
Code: Select all
--[[
Zendure SolarFlow 2400 AC+ -> Domoticz (via lokale zenSDK-API)
Plaats dit bestand in: <domoticz>/scripts/dzVents/scripts/zendure_local.lua
(of plak de inhoud in Setup -> More Options -> Events -> dzVents nieuw script)
Werkt naast de Zendure-cloud: de HEMS/lokale API is een extra uitgang,
je app blijft gewoon live data tonen.
Bevestigd endpoint: http://[ZENDURE_IP]/properties/report
Data zit onder .properties ; accu's onder .packData[]
Aanmaken in Domoticz (Dummy hardware -> Virtual Sensors):
- Percentage : SoC totaal, en evt. per pack
- Custom Sensor W : laden, ontladen, zon, naar huis, grid
- Temperature : apparaattemperatuur
- Custom Sensor dBm (optioneel): WiFi-signaal
Noteer van elk het idx en vul hieronder in. idx = 0 -> overslaan.
]]
-- >>> AANPASSEN <<<
local ZENDURE_IP = '[ZENDURE_IP]'
local IDX = {
-- kern
soc = 0, -- Percentage (electricLevel, %)
charge = 0, -- Custom Sensor W (outputPackPower = laden)
discharge = 0, -- Custom Sensor W (packInputPower = ontladen)
solar = 0, -- Custom Sensor W (solarInputPower)
toHome = 0, -- Custom Sensor W (outputHomePower)
grid = 0, -- Custom Sensor W (gridInputPower)
netPower = 0, -- Custom Sensor W (netto accuvermogen: + = laden, - = ontladen)
netGrid = 0, -- Custom Sensor W (netto verbruik: gridInputPower - laadvermogen)
remainOut = 0, -- Custom Sensor min (remainOutTime, resterende ontlaadtijd)
-- extra (optioneel)
temp = 0, -- Temperature (hyperTmp / 100)
wifi = 0, -- Custom Sensor dBm (rssi)
pack1soc = 0, -- Percentage (packData[1].socLevel)
pack2soc = 0, -- Percentage (packData[2].socLevel)
pack1temp = 0, -- Temperature (packData[1].maxTemp / 100)
pack2temp = 0, -- Temperature (packData[2].maxTemp / 100)
updated = 0, -- Text (rapporttijd, uit timestamp)
-- Voor het ingebouwde Energiedashboard:
batPower = 0, -- Usage (Electric) netto accuvermogen (Watt-veld "Batterij")
batVolt = 0, -- Voltage (BatVolt / 100)
energyIn = 0, -- Electric (Instant+Counter) laadenergie (In)
energyOut = 0, -- Electric (Instant+Counter) ontlaadenergie (Uit)
netUsed = 0, -- kWh netto verbruik (netGrid > 0)
netBack = 0, -- kWh netto teruglevering (netGrid < 0)
p1 = 1, -- BESTAAND P1-device (Slimme Meter) - niet aanmaken, alleen uitlezen
}
-- >>> EINDE AANPASSEN <<<
return {
on = {
timer = { 'every minute' },
httpResponses = { 'zendureReport' },
},
data = {
lastTs = { initial = 0 }, -- laatste meetmoment (voor kWh-integratie)
whIn = { initial = 0 }, -- cumulatieve laadenergie (Wh)
whOut = { initial = 0 }, -- cumulatieve ontlaadenergie (Wh)
whUsed = { initial = 0 }, -- cumulatief netto verbruik (Wh)
whBack = { initial = 0 }, -- cumulatieve netto teruglevering (Wh)
},
logging = {
level = domoticz.LOG_ERROR, -- zet op LOG_INFO om mee te kijken
marker = 'Zendure',
},
execute = function(domoticz, item)
-- 1) Elke minuut de lokale API opvragen
if item.isTimer then
domoticz.openURL({
url = 'http://' .. ZENDURE_IP .. '/properties/report',
method = 'GET',
callback = 'zendureReport',
})
return
end
-- 2) Antwoord verwerken
if not (item.ok and item.isJSON) then
domoticz.log('Geen geldige JSON van de Zendure', domoticz.LOG_ERROR)
return
end
local p = item.json.properties or {}
local packs = item.json.packData or {}
local function setPct(idx, val)
if idx and idx > 0 and val ~= nil then
domoticz.devices(idx).updatePercentage(val)
end
end
local function setW(idx, val)
if idx and idx > 0 and val ~= nil then
domoticz.devices(idx).updateCustomSensor(val)
end
end
local function setTemp(idx, val)
if idx and idx > 0 and val ~= nil then
domoticz.devices(idx).updateTemperature(val)
end
end
local function setText(idx, val)
if idx and idx > 0 and val ~= nil then
domoticz.devices(idx).updateText(val)
end
end
-- kern
setPct(IDX.soc, p.electricLevel)
setW(IDX.charge, p.outputPackPower)
setW(IDX.discharge, p.packInputPower)
setW(IDX.solar, p.solarInputPower)
setW(IDX.toHome, p.outputHomePower)
setW(IDX.grid, p.gridInputPower)
-- netto accuvermogen: laden positief, ontladen negatief
local charge = p.outputPackPower or 0
local discharge = p.packInputPower or 0
setW(IDX.netPower, charge - discharge)
-- netto verbruik: WERKELIJKE netafname (P1) minus wat er naar de accu gaat.
-- gridInputPower van de Zendure is alleen zijn eigen laadstroom (~= outputPackPower),
-- dus dat geeft altijd 0. De P1-meter is de echte huis-netafname.
local p1net = 0
if IDX.p1 > 0 then
local p1 = domoticz.devices(IDX.p1)
if p1 then p1net = (p1.usage or 0) - (p1.usageDelivered or 0) end
end
local net = p1net - charge
setW(IDX.netGrid, net)
-- === Ingebouwd Energiedashboard ===
-- Netto accuvermogen als Usage-device (Watt-veld "Batterij")
if IDX.batPower > 0 then
local pdev = domoticz.devices(IDX.batPower)
if pdev then pdev.updateEnergy(charge - discharge) end
end
-- Accuspanning
if IDX.batVolt > 0 and p.BatVolt ~= nil then
local vdev = domoticz.devices(IDX.batVolt)
if vdev then vdev.updateVoltage(p.BatVolt / 100.0) end
end
-- kWh-tellers: vermogen zelf integreren op basis van verstreken tijd
local now = os.time()
local dt = 0
if domoticz.data.lastTs > 0 then dt = now - domoticz.data.lastTs end
domoticz.data.lastTs = now
if dt < 0 or dt > 300 then dt = 0 end -- gaten na uitval niet meetellen
domoticz.data.whIn = domoticz.data.whIn + charge * dt / 3600.0
domoticz.data.whOut = domoticz.data.whOut + discharge * dt / 3600.0
if IDX.energyIn > 0 then
local d = domoticz.devices(IDX.energyIn)
if d then d.updateElectricity(charge, domoticz.data.whIn) end
end
if IDX.energyOut > 0 then
local d = domoticz.devices(IDX.energyOut)
if d then d.updateElectricity(discharge, domoticz.data.whOut) end
end
-- netto verbruik/teruglevering als kWh-tellers (net = P1 - laadvermogen, zie boven)
if net >= 0 then
domoticz.data.whUsed = domoticz.data.whUsed + net * dt / 3600.0
else
domoticz.data.whBack = domoticz.data.whBack + (-net) * dt / 3600.0
end
if IDX.netUsed > 0 then
local d = domoticz.devices(IDX.netUsed)
if d then d.updateElectricity(net > 0 and net or 0, domoticz.data.whUsed) end
end
if IDX.netBack > 0 then
local d = domoticz.devices(IDX.netBack)
if d then d.updateElectricity(net < 0 and -net or 0, domoticz.data.whBack) end
end
-- resterende ontlaadtijd: alleen zinvol tijdens ontladen.
-- Laadt/idle -> apparaat geeft een placeholder (42000/59940 min); dan 0 tonen.
if p.remainOutTime ~= nil then
local rot = 0
if discharge > 0 then rot = p.remainOutTime end
setW(IDX.remainOut, rot)
end
-- extra
if p.hyperTmp ~= nil then setTemp(IDX.temp, p.hyperTmp / 100.0) end
setW(IDX.wifi, p.rssi)
if item.json.timestamp ~= nil then
setText(IDX.updated, os.date('%Y-%m-%d %H:%M:%S', item.json.timestamp))
end
if packs[1] then
setPct(IDX.pack1soc, packs[1].socLevel)
if packs[1].maxTemp ~= nil then setTemp(IDX.pack1temp, packs[1].maxTemp / 100.0) end
end
if packs[2] then
setPct(IDX.pack2soc, packs[2].socLevel)
if packs[2].maxTemp ~= nil then setTemp(IDX.pack2temp, packs[2].maxTemp / 100.0) end
end
domoticz.log('Zendure bijgewerkt: SoC=' .. tostring(p.electricLevel)
.. '% laden=' .. tostring(p.outputPackPower)
.. 'W ontladen=' .. tostring(p.packInputPower) .. 'W', domoticz.LOG_INFO)
end
}
-
pgit
- Posts: 17
- Joined: Monday 04 August 2014 17:54
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Zendure SolarFlow 2400 AC+
Fantastic, thank you!
I will add the missing virtual sensors and try your script a.s.a.p.
I assume packData[2] is for one extra battery.
I have added two AB300L's so I wil also try to adapt your script to include packData[3] values.
I will add the missing virtual sensors and try your script a.s.a.p.
I assume packData[2] is for one extra battery.
I have added two AB300L's so I wil also try to adapt your script to include packData[3] values.
-
Henry
- Posts: 44
- Joined: Tuesday 06 March 2018 18:56
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.7
- Location: Netherlands
- Contact:
Re: Zendure SolarFlow 2400 AC+
I indeed have 1 extra pack. You can enter the link in a browser to check the json.
Good luck
Good luck
-
pgit
- Posts: 17
- Joined: Monday 04 August 2014 17:54
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Zendure SolarFlow 2400 AC+
Dear Henry,
Sorry to bother again but... what type of virtual sensors did you use for:
netUsed = 0, -- kWh netto verbruik (netGrid > 0)
netBack = 0, -- kWh netto teruglevering (netGrid < 0)
???
I don't seem to understand how / where they are being used...
Whether I use a Custom Sensor, Usage (Electric), Text, or Counter, I keep getting the following errors in the log:
2026-08-21 01:18:00.631 Error: dzVents: Zendure: Method updateElectricity is not available for device "kWh netto verbruik (netGrid > 0)" (deviceType=General, deviceSubType=Custom Sensor). If you believe this is not correct, please report.
2026-08-21 01:18:00.632 Error: dzVents: Zendure: Method updateElectricity is not available for device "kWh netto teruglevering (netGrid < 0)" (deviceType=General, deviceSubType=Custom Sensor). If you believe this is not correct, please report.
...
2026-08-21 01:53:00.937 Error: dzVents: Zendure: Method updateElectricity is not available for device "kWh ELECTRIC netto verbruik (netGrid > 0)" (deviceType=Usage, deviceSubType=Electric). If you believe this is not correct, please report.
2026-08-21 01:53:00.938 Error: dzVents: Zendure: Method updateElectricity is not available for device "kWh ELECTRIC netto teruglevering (netGrid < 0)" (deviceType=Usage, deviceSubType=Electric). If you believe this is not correct, please report.
2026-08-21 01:54:01.213 Error: dzVents: Zendure: Method updateElectricity is not available for device "kWh TEXT netto verbruik (netGrid > 0)" (deviceType=General, deviceSubType=Text). If you believe this is not correct, please report.
2026-08-21 01:54:01.214 Error: dzVents: Zendure: Method updateElectricity is not available for device "kWh TEXT netto teruglevering (netGrid < 0)" (deviceType=General, deviceSubType=Text). If you believe this is not correct, please report.
...
2026-08-21 02:13:00.950 Error: dzVents: Zendure: Method updateElectricity is not available for device "kWh COUNTER netto verbruik (netGrid > 0)" (deviceType=RFXMeter, deviceSubType=RFXMeter counter). If you believe this is not correct, please report.
2026-08-21 02:13:00.951 Error: dzVents: Zendure: Method updateElectricity is not available for device "kWh COUNTER netto teruglevering (netGrid < 0)" (deviceType=RFXMeter, deviceSubType=RFXMeter counter). If you believe this is not correct, please report.
Yes, I'm having a (very) late night struggle
Thanks (again) for any help!
Sorry to bother again but... what type of virtual sensors did you use for:
netUsed = 0, -- kWh netto verbruik (netGrid > 0)
netBack = 0, -- kWh netto teruglevering (netGrid < 0)
???
I don't seem to understand how / where they are being used...
Whether I use a Custom Sensor, Usage (Electric), Text, or Counter, I keep getting the following errors in the log:
2026-08-21 01:18:00.631 Error: dzVents: Zendure: Method updateElectricity is not available for device "kWh netto verbruik (netGrid > 0)" (deviceType=General, deviceSubType=Custom Sensor). If you believe this is not correct, please report.
2026-08-21 01:18:00.632 Error: dzVents: Zendure: Method updateElectricity is not available for device "kWh netto teruglevering (netGrid < 0)" (deviceType=General, deviceSubType=Custom Sensor). If you believe this is not correct, please report.
...
2026-08-21 01:53:00.937 Error: dzVents: Zendure: Method updateElectricity is not available for device "kWh ELECTRIC netto verbruik (netGrid > 0)" (deviceType=Usage, deviceSubType=Electric). If you believe this is not correct, please report.
2026-08-21 01:53:00.938 Error: dzVents: Zendure: Method updateElectricity is not available for device "kWh ELECTRIC netto teruglevering (netGrid < 0)" (deviceType=Usage, deviceSubType=Electric). If you believe this is not correct, please report.
2026-08-21 01:54:01.213 Error: dzVents: Zendure: Method updateElectricity is not available for device "kWh TEXT netto verbruik (netGrid > 0)" (deviceType=General, deviceSubType=Text). If you believe this is not correct, please report.
2026-08-21 01:54:01.214 Error: dzVents: Zendure: Method updateElectricity is not available for device "kWh TEXT netto teruglevering (netGrid < 0)" (deviceType=General, deviceSubType=Text). If you believe this is not correct, please report.
...
2026-08-21 02:13:00.950 Error: dzVents: Zendure: Method updateElectricity is not available for device "kWh COUNTER netto verbruik (netGrid > 0)" (deviceType=RFXMeter, deviceSubType=RFXMeter counter). If you believe this is not correct, please report.
2026-08-21 02:13:00.951 Error: dzVents: Zendure: Method updateElectricity is not available for device "kWh COUNTER netto teruglevering (netGrid < 0)" (deviceType=RFXMeter, deviceSubType=RFXMeter counter). If you believe this is not correct, please report.
Yes, I'm having a (very) late night struggle
Thanks (again) for any help!
Last edited by pgit on Friday 21 August 2026 2:39, edited 1 time in total.
-
pgit
- Posts: 17
- Joined: Monday 04 August 2014 17:54
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Zendure SolarFlow 2400 AC+
I just figured out they work when I choose them to be Electric (Instant + Counter), right?
But I am yet to grasp their use...
How are the different from the measurements of the P1 meter?
How did you configure them in the settings of the energy dashboard?
(It's still night time, I haven't seen their behaviour when there is solar input from my panels yet)
But I am yet to grasp their use...
How are the different from the measurements of the P1 meter?
How did you configure them in the settings of the energy dashboard?
(It's still night time, I haven't seen their behaviour when there is solar input from my panels yet)
-
Henry
- Posts: 44
- Joined: Tuesday 06 March 2018 18:56
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.7
- Location: Netherlands
- Contact:
Re: Zendure SolarFlow 2400 AC+
The type is type Electric (Instant+Counter) indeed. I’m not at home right now so it’s a bit hard for me to check but some devices are there just for testing. I’ve attached a screenshot of my energy daahboard settings.
- Attachments
-
- IMG_6402.jpeg (344.32 KiB) Viewed 1323 times
-
pgit
- Posts: 17
- Joined: Monday 04 August 2014 17:54
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Zendure SolarFlow 2400 AC+
Thanks a lot, Henry!
Looks like I have my energyboard working now.
(Maybe it's not a very good moment to show you, though, while the batteries are fully charged and the panels are supplying more then demanded, but I couldn't wait )
Next (and the real) challenge will be to be able to use Domoticz as a HEMS for the Zendure...
Looks like I have my energyboard working now.
(Maybe it's not a very good moment to show you, though, while the batteries are fully charged and the panels are supplying more then demanded, but I couldn't wait )
Next (and the real) challenge will be to be able to use Domoticz as a HEMS for the Zendure...
-
Henry
- Posts: 44
- Joined: Tuesday 06 March 2018 18:56
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.7
- Location: Netherlands
- Contact:
Re: Zendure SolarFlow 2400 AC+
Looking good. Let me know if you succeed in controling the battery with domiticz
-
BartSr
- Posts: 550
- Joined: Sunday 03 July 2016 16:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2024.7
- Location: Netherlands
- Contact:
Re: Zendure SolarFlow 2400 AC+
Any news on this topic?
I tend to buy same type.
-Bart
I tend to buy same type.
-Bart
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
Re: Zendure SolarFlow 2400 AC+
this is a Hardware plugin for Zendure, make a folder called Zendure in plugins save this file as plugin.py. Restart domoticz service
and it should be visible under Hardware
and it should be visible under Hardware
Code: Select all
# ZENDURE
#
# Description: Zendure SolarFlow home battery (800, 800 Plus, 800 Pro, 1600 AC+,
# 2400 AC / AC+, 2400 Pro, 4000 AC+, ...). Reads all values over the
# local zenSDK HTTP API (GET /properties/report), no cloud, no MQTT.
#
# History:
# 1.0.0 Initial version
"""
<plugin key="Zendure_Battery" name="Zendure home battery (zenSDK local API)" author="" version="1.0.0" externallink="https://github.com/Zendure/zenSDK">
<description>
<h2>Zendure home battery (zenSDK local API)</h2><br/>
Reads all values of a Zendure SolarFlow battery through the local API:
<i>http://ip/properties/report</i>.<br/><br/>
Creates devices for the state of charge, solar / home / pack / grid power, remaining time,
limits, modes and, per battery pack, the charge level, power, voltage, temperature and health.
Devices are created when the battery reports the value, so models without a value simply
do not get that device.<br/><br/>
The plugin is read-only. The local API (zenSDK) must be enabled on the battery.
</description>
<params>
<param field="Address" label="IP Address" width="200px" required="true" default=""/>
<param field="Port" label="Port" width="40px" required="true" default="80"/>
<param field="Mode3" label="Poll interval" width="100px">
<options>
<option label="10 seconds" value="10"/>
<option label="20 seconds" value="20"/>
<option label="30 seconds" value="30" default="true"/>
<option label="60 seconds" value="60"/>
</options>
</param>
<param field="Mode4" label="Devices for all other numeric values" width="100px">
<options>
<option label="No" value="0" default="true"/>
<option label="Yes" value="1"/>
</options>
</param>
<param field="Mode6" label="Debug" width="100px">
<options>
<option label="Off" value="0" default="true"/>
<option label="On" value="1"/>
</options>
</param>
</params>
</plugin>
"""
import Domoticz
import json
import urllib.request
REQUEST_TIMEOUT = 5 # seconds
UNIT_MODEL = 30 # text device with the product name
UNIT_EXTRA_FIRST = 40 # first unit for "all other numeric values"
UNIT_EXTRA_LAST = 99
UNIT_PACK_BASE = 100 # pack n (0-based) uses 100 + n*10 + offset
MAX_PACKS = 8
STATE_MAP = {0: "Idle", 1: "Charging", 2: "Discharging"}
ACMODE_MAP = {1: "AC input (charging)", 2: "AC output"}
ONOFF_MAP = {0: "Off", 1: "On"}
# (unit, key in "properties", device name, kind, value -> text map)
# kinds: watt, pct, pct10 (divide by 10 when > 100), min, num, text
MAIN = [
(1, "electricLevel", "State of charge", "pct", None),
(2, "solarInputPower", "Solar input power", "watt", None),
(3, "outputHomePower", "Output to home", "watt", None),
(4, "packInputPower", "Pack input power", "watt", None),
(5, "outputPackPower", "Pack output power", "watt", None),
(6, "gridInputPower", "Grid input power", "watt", None),
(7, "remainOutTime", "Remaining discharge time", "min", None),
(8, "remainInputTime", "Remaining charge time", "min", None),
(9, "socSet", "Max charge level (socSet)", "pct10", None),
(10, "minSoc", "Min discharge level (minSoc)", "pct10", None),
(11, "inputLimit", "Input limit", "watt", None),
(12, "outputLimit", "Output limit", "watt", None),
(13, "inverseMaxPower", "Inverter max power", "watt", None),
(14, "acMode", "AC mode", "text", ACMODE_MAP),
(15, "packState", "Pack state", "text", STATE_MAP),
(16, "heatState", "Heating", "text", ONOFF_MAP),
(17, "packNum", "Number of packs", "num", None),
(20, "solarPower1", "Solar panel 1 power", "watt", None),
(21, "solarPower2", "Solar panel 2 power", "watt", None),
(22, "solarPower3", "Solar panel 3 power", "watt", None),
(23, "solarPower4", "Solar panel 4 power", "watt", None),
]
MAIN_KEYS = set(m[1] for m in MAIN)
IGNORE_KEYS = set(["timestamp", "messageId", "version"])
class BasePlugin:
pollTicks = 3 # heartbeat is 10 s, so 3 ticks = 30 s
ticks = 0
extras = False # create devices for other numeric values
extraUnits = {} # property key -> unit
errorReported = False
modelLogged = False
def onStart(self):
if Parameters["Mode6"] == "1":
Domoticz.Debugging(1)
self.extras = (Parameters["Mode4"] == "1")
try:
interval = int(Parameters["Mode3"])
except ValueError:
interval = 30
self.pollTicks = max(1, interval // 10)
# Remember which unit belongs to which extra property (DeviceID = key)
self.extraUnits = {}
for unit in Devices:
if UNIT_EXTRA_FIRST <= unit <= UNIT_EXTRA_LAST:
self.extraUnits[Devices[unit].DeviceID] = unit
Domoticz.Heartbeat(10)
self.ticks = self.pollTicks # poll at the first heartbeat
def onStop(self):
Domoticz.Debug("onStop called")
def onConnect(self, Connection, Status, Description):
pass
def onMessage(self, Connection, Data):
pass
def onCommand(self, Unit, Command, Level, Hue):
Domoticz.Debug("onCommand called for Unit " + str(Unit) + ": " + str(Command) + " (plugin is read-only)")
def onNotification(self, Name, Subject, Text, Status, Priority, Sound, ImageFile):
pass
def onDisconnect(self, Connection):
pass
def onHeartbeat(self):
self.ticks += 1
if self.ticks < self.pollTicks:
return
self.ticks = 0
self.poll()
####################### Plugin specific functions #######################
def poll(self):
url = "http://%s:%s/properties/report" % (Parameters["Address"], Parameters["Port"])
Domoticz.Debug("GET " + url)
try:
with urllib.request.urlopen(url, timeout=REQUEST_TIMEOUT) as response:
raw = response.read().decode("utf-8", "ignore")
Domoticz.Debug("Zendure reply: " + raw)
start = raw.find("{")
if start < 0:
raise ValueError("no JSON in reply: '" + raw[:80] + "'")
report = json.loads(raw[start:])
except Exception as e:
self.fail("Could not read the Zendure at " + url + ": " + str(e))
return
self.errorReported = False
self.update(report)
def fail(self, message):
# Report and mark the devices only once per outage
if self.errorReported:
return
self.errorReported = True
Domoticz.Error(message)
for unit in Devices:
Devices[unit].Update(nValue=Devices[unit].nValue, sValue=Devices[unit].sValue, TimedOut=1)
def update(self, report):
props = report.get("properties")
if not isinstance(props, dict):
props = {}
product = report.get("product")
if product:
if not self.modelLogged:
Domoticz.Log("Zendure product: " + str(product) + ", version " + str(report.get("version")))
self.modelLogged = True
self.setValue(UNIT_MODEL, "Model", "text", None, str(product))
# Known values
for unit, key, name, kind, tmap in MAIN:
if key in props and props[key] is not None:
self.setValue(unit, name, kind, tmap, props[key])
# Other numeric values (optional)
if self.extras:
for key, value in props.items():
if key in MAIN_KEYS or key in IGNORE_KEYS:
continue
if isinstance(value, bool) or not isinstance(value, (int, float)):
continue
unit = self.extraUnit(key)
if unit is not None:
self.setValue(unit, key, "extra", None, value)
# Battery packs
packs = report.get("packData")
if isinstance(packs, list):
for idx, pack in enumerate(packs[:MAX_PACKS]):
if isinstance(pack, dict):
self.updatePack(idx, pack)
def updatePack(self, idx, p):
base = UNIT_PACK_BASE + idx * 10
n = "Pack %d " % (idx + 1)
if p.get("socLevel") is not None:
self.setValue(base + 0, n + "charge level", "pct", None, p["socLevel"])
if p.get("power") is not None:
self.setValue(base + 1, n + "power", "watt", None, p["power"])
if p.get("totalVol") is not None: # hundredths of a volt
self.setValue(base + 2, n + "voltage", "volt", None, self.number(p["totalVol"]) / 100.0)
if p.get("maxTemp") is not None: # tenths of a kelvin
self.setValue(base + 3, n + "temperature", "temp", None, self.toCelsius(p["maxTemp"]))
if p.get("soh") is not None: # tenths of a percent
self.setValue(base + 4, n + "health", "pct10", None, p["soh"])
if p.get("state") is not None:
self.setValue(base + 5, n + "state", "text", STATE_MAP, p["state"])
def toCelsius(self, value):
v = self.number(value)
if v > 1000: # tenths of a kelvin
return v / 10.0 - 273.15
return v # already degrees C
def extraUnit(self, key):
if key in self.extraUnits:
return self.extraUnits[key]
used = set(self.extraUnits.values())
for unit in range(UNIT_EXTRA_FIRST, UNIT_EXTRA_LAST + 1):
if unit not in used and unit not in Devices:
self.extraUnits[key] = unit
return unit
Domoticz.Error("No free unit left for extra value " + key)
return None
def number(self, value):
try:
return float(value)
except (TypeError, ValueError):
return 0.0
def guessLabel(self, key):
k = key.lower()
if k.endswith("power"):
return "W"
if k.endswith("time"):
return "min"
if k.endswith("soc") or k.endswith("level"):
return "%"
return "value"
def createDevice(self, unit, name, kind):
if kind == "watt":
Domoticz.Device(Name=name, Unit=unit, Type=248, Subtype=1, Used=1).Create()
elif kind in ("pct", "pct10"):
Domoticz.Device(Name=name, Unit=unit, Type=243, Subtype=6, Used=1).Create()
elif kind == "volt":
Domoticz.Device(Name=name, Unit=unit, Type=243, Subtype=8, Used=1).Create()
elif kind == "temp":
Domoticz.Device(Name=name, Unit=unit, Type=80, Subtype=5, Used=1).Create()
elif kind == "text":
Domoticz.Device(Name=name, Unit=unit, Type=243, Subtype=19, Used=1).Create()
elif kind == "min":
Domoticz.Device(Name=name, Unit=unit, Type=243, Subtype=31, Options={"Custom": "1;min"}, Used=1).Create()
elif kind == "num":
Domoticz.Device(Name=name, Unit=unit, Type=243, Subtype=31, Options={"Custom": "1;pcs"}, Used=1).Create()
elif kind == "extra":
Domoticz.Device(Name=name, Unit=unit, DeviceID=name, Type=243, Subtype=31,
Options={"Custom": "1;" + self.guessLabel(name)}, Used=1).Create()
def formatValue(self, kind, tmap, value):
if kind == "text":
if tmap is not None:
try:
return tmap.get(int(value), str(value))
except (TypeError, ValueError):
pass
return str(value)
v = self.number(value)
if kind == "watt":
return "%.0f" % v
if kind == "pct":
return "%.1f" % v
if kind == "pct10":
return "%.1f" % (v / 10.0 if v > 100 else v)
if kind == "volt":
return "%.2f" % v
if kind == "temp":
return "%.1f" % v
if kind in ("min", "num"):
return "%d" % int(v)
# extra
return ("%d" % v) if v == int(v) else ("%.2f" % v)
def setValue(self, unit, name, kind, tmap, value):
if unit not in Devices:
self.createDevice(unit, name, kind)
if unit in Devices:
s = self.formatValue(kind, tmap, value)
if Devices[unit].sValue != s or Devices[unit].TimedOut:
Devices[unit].Update(nValue=0, sValue=s, TimedOut=0)
####################### Global functions for plugin #######################
global _plugin
_plugin = BasePlugin()
def onStart():
global _plugin
_plugin.onStart()
def onStop():
global _plugin
_plugin.onStop()
def onConnect(Connection, Status, Description):
global _plugin
_plugin.onConnect(Connection, Status, Description)
def onMessage(Connection, Data):
global _plugin
_plugin.onMessage(Connection, Data)
def onCommand(Unit, Command, Level, Hue):
global _plugin
_plugin.onCommand(Unit, Command, Level, Hue)
def onNotification(Name, Subject, Text, Status, Priority, Sound, ImageFile):
global _plugin
_plugin.onNotification(Name, Subject, Text, Status, Priority, Sound, ImageFile)
def onDisconnect(Connection):
global _plugin
_plugin.onDisconnect(Connection)
def onHeartbeat():
global _plugin
_plugin.onHeartbeat()