Skip to content

Commit b293639

Browse files
committed
Add new entities (manual discovered)
for smart meter and stream ac
1 parent 09616cb commit b293639

File tree

6 files changed

+128
-43
lines changed

6 files changed

+128
-43
lines changed

custom_components/ecoflow_cloud/devices/const.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,38 @@
281281
SMART_METER_POWER_L1 = "Power Grid L1"
282282
SMART_METER_POWER_L2 = "Power Grid L2"
283283
SMART_METER_POWER_L3 = "Power Grid L3"
284+
SMART_METER_IN_AMPS_L1 = "Power Grid (L1) In Amps"
285+
SMART_METER_IN_AMPS_L2 = "Power Grid (L2) In Amps"
286+
SMART_METER_IN_AMPS_L3 = "Power Grid (L3) In Amps"
287+
SMART_METER_VOLT_L1 = "Power Grid (L1) Volts"
288+
SMART_METER_VOLT_L2 = "Power Grid (L2) Volts"
289+
SMART_METER_VOLT_L3 = "Power Grid (L3) Volts"
290+
SMART_METER_RECORD_ACTIVE_TODAY = "Lifetime consumption"
291+
SMART_METER_RECORD_ACTIVE_TOTAL = "Lifetime net usage"
292+
SMART_METER_RECORD_REACTIVE_TOTAL = "Lifetime injection"
293+
SMART_METER_RECORD_ACTIVE_TODAY_L1 = "L1 Lifetime net usage"
294+
SMART_METER_RECORD_ACTIVE_TODAY_L2 = "L2 Lifetime net usage"
295+
SMART_METER_RECORD_ACTIVE_TODAY_L3 = "L3 Lifetime net usage"
284296

285297
# Stream AC
286298
STREAM_POWER_AC = "Power AC" # <0 import from home to battery / >0 export from battery to home
299+
STREAM_POWER_AC_SYS = "Power AC SYS" # <0 import from home to battery / >0 export from battery to home
287300
STREAM_POWER_PV = "Power PV" # >0 external pv power estimate injection to home/battery
301+
STREAM_GET_SYS_LOAD = "Power Sys Load" # powGetSysLoad
302+
STREAM_GET_SYS_LOAD_FROM_GRID = "Power Sys Load From Grid" # powGetSysLoadFromGrid
303+
STREAM_GET_SCHUKO1 = "Power SCHUKO1" # powGetSchuko1
288304
STREAM_POWER_GRID = "Power Grid" # power from smart meter or shelly
289305
STREAM_POWER_BATTERY = "Power Battery" # <0 discharge battery / >0 charge batterie
306+
STREAM_POWER_BATTERY_SOC = "Power Battery SOC" # <0 discharge battery / >0 charge batterie
307+
STREAM_BATTERY_LEVEL = "Battery Level"
308+
STREAM_DESIGN_CAPACITY = "Design Capacity"
309+
STREAM_FULL_CAPACITY = "Full Capacity"
310+
STREAM_REMAIN_CAPACITY = "Remain Capacity"
311+
STREAM_STR_BATTERY_LEVEL = "Battery Level %s "
312+
STREAM_STR_DESIGN_CAPACITY = "Design Capacity %s "
313+
STREAM_STR_FULL_CAPACITY = "Full Capacity %s "
314+
STREAM_STR_REMAIN_CAPACITY = "Remain Capacity %s "
315+
STREAM_IN_POWER = "In Power"
316+
STREAM_STR_IN_POWER = "In Power %s"
317+
STREAM_OUT_POWER = "Out Power"
318+
STREAM_STR_OUT_POWER = "Out Power %s"

custom_components/ecoflow_cloud/devices/internal/smart_meter.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,35 @@
22
from custom_components.ecoflow_cloud.devices import const, BaseDevice
33
from custom_components.ecoflow_cloud.entities import BaseSensorEntity, BaseNumberEntity, BaseSwitchEntity, \
44
BaseSelectEntity
5-
from custom_components.ecoflow_cloud.sensor import WattsSensorEntity
5+
from custom_components.ecoflow_cloud.sensor import WattsSensorEntity, InAmpSensorEntity, MilliVoltSensorEntity, \
6+
EnergySensorEntity
67

78
class SmartMeter(BaseDevice):
89
def sensors(self, client: EcoflowApiClient) -> list[BaseSensorEntity]:
910
return [
1011
WattsSensorEntity(client, self, "powGetSysGrid", const.SMART_METER_POWER_GLOBAL),
11-
WattsSensorEntity(client, self, "gridConnectionPowerL1", const.SMART_METER_POWER_L1),
12-
WattsSensorEntity(client, self, "gridConnectionPowerL2", const.SMART_METER_POWER_L2),
13-
WattsSensorEntity(client, self, "gridConnectionPowerL3", const.SMART_METER_POWER_L3)
12+
13+
WattsSensorEntity(client, self, "gridConnectionPowerL1", const.SMART_METER_POWER_L1, False),
14+
WattsSensorEntity(client, self, "gridConnectionPowerL2", const.SMART_METER_POWER_L2, False),
15+
WattsSensorEntity(client, self, "gridConnectionPowerL3", const.SMART_METER_POWER_L3, False),
16+
17+
InAmpSensorEntity(client, self, "gridConnectionAmpL1", const.SMART_METER_IN_AMPS_L1, False),
18+
InAmpSensorEntity(client, self, "gridConnectionAmpL2", const.SMART_METER_IN_AMPS_L2, False),
19+
InAmpSensorEntity(client, self, "gridConnectionAmpL3", const.SMART_METER_IN_AMPS_L3, False),
20+
21+
MilliVoltSensorEntity(client, self, "gridConnectionVolL1", const.SMART_METER_VOLT_L1, False),
22+
MilliVoltSensorEntity(client, self, "gridConnectionVolL2", const.SMART_METER_VOLT_L2, False),
23+
MilliVoltSensorEntity(client, self, "gridConnectionVolL3", const.SMART_METER_VOLT_L3, False),
24+
25+
EnergySensorEntity(client, self, "gridConnectionDataRecord.todayActive", const.SMART_METER_RECORD_ACTIVE_TODAY),
26+
EnergySensorEntity(client, self, "gridConnectionDataRecord.totalActiveEnergy", const.SMART_METER_RECORD_ACTIVE_TOTAL),
27+
EnergySensorEntity(client, self, "gridConnectionDataRecord.totalReactiveEnergy", const.SMART_METER_RECORD_REACTIVE_TOTAL),
28+
29+
EnergySensorEntity(client, self, "gridConnectionDataRecord.todayActiveL1", const.SMART_METER_RECORD_ACTIVE_TODAY_L1,False),
30+
EnergySensorEntity(client, self, "gridConnectionDataRecord.todayActiveL2", const.SMART_METER_RECORD_ACTIVE_TODAY_L2, False),
31+
EnergySensorEntity(client, self, "gridConnectionDataRecord.todayActiveL3", const.SMART_METER_RECORD_ACTIVE_TODAY_L3, False),
32+
33+
1434
]
1535

1636
def numbers(self, client: EcoflowApiClient) -> list[BaseNumberEntity]:

custom_components/ecoflow_cloud/devices/internal/stream_ac.py

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,52 @@
22
from custom_components.ecoflow_cloud.devices import const, BaseDevice
33
from custom_components.ecoflow_cloud.entities import BaseSensorEntity, BaseNumberEntity, BaseSwitchEntity, \
44
BaseSelectEntity
5-
from custom_components.ecoflow_cloud.sensor import WattsSensorEntity
5+
from custom_components.ecoflow_cloud.sensor import WattsSensorEntity,LevelSensorEntity,CapacitySensorEntity, \
6+
InWattsSensorEntity,OutWattsSensorEntity, RemainSensorEntity, MilliVoltSensorEntity, TempSensorEntity, \
7+
CyclesSensorEntity
68

79
class StreamAC(BaseDevice):
810
def sensors(self, client: EcoflowApiClient) -> list[BaseSensorEntity]:
911
return [
10-
WattsSensorEntity(client, self, "sysGridConnectionPower", const.STREAM_POWER_AC),
12+
13+
WattsSensorEntity(client, self, "sysGridConnectionPower", const.STREAM_POWER_AC_SYS),
14+
WattsSensorEntity(client, self, "powGetSysLoad", const.STREAM_GET_SYS_LOAD),
15+
WattsSensorEntity(client, self, "powGetSysLoadFromGrid", const.STREAM_GET_SYS_LOAD_FROM_GRID),
16+
WattsSensorEntity(client, self, "powGetSchuko1", const.STREAM_GET_SCHUKO1, False),
17+
WattsSensorEntity(client, self, "gridConnectionPower", const.STREAM_POWER_AC),
1118
WattsSensorEntity(client, self, "powGetSysGrid", const.STREAM_POWER_GRID),
1219
WattsSensorEntity(client, self, "powGetPvSum", const.STREAM_POWER_PV),
13-
WattsSensorEntity(client, self, "powGetBpCms", const.STREAM_POWER_BATTERY)
14-
]
20+
WattsSensorEntity(client, self, "powGetBpCms", const.STREAM_POWER_BATTERY),
21+
LevelSensorEntity(client, self, "f32ShowSoc", const.STREAM_POWER_BATTERY_SOC),
22+
LevelSensorEntity(client, self, "soc", const.STREAM_POWER_BATTERY)
23+
.attr("designCap", const.ATTR_DESIGN_CAPACITY, 0)
24+
.attr("fullCap", const.ATTR_FULL_CAPACITY, 0)
25+
.attr("remainCap", const.ATTR_REMAIN_CAPACITY, 0),
26+
CapacitySensorEntity(client, self, "designCap", const.STREAM_DESIGN_CAPACITY,False),
27+
CapacitySensorEntity(client, self, "fullCap", const.STREAM_FULL_CAPACITY, False),
28+
CapacitySensorEntity(client, self, "remainCap", const.STREAM_REMAIN_CAPACITY,False),
29+
30+
MilliVoltSensorEntity(client, self, "vol", const.BATTERY_VOLT, False)
31+
.attr("minCellVol", const.ATTR_MIN_CELL_VOLT, 0)
32+
.attr("maxCellVol", const.ATTR_MAX_CELL_VOLT, 0),
33+
MilliVoltSensorEntity(client, self, "minCellVol", const.MIN_CELL_VOLT, False),
34+
MilliVoltSensorEntity(client, self, "maxCellVol", const.MAX_CELL_VOLT, False),
35+
LevelSensorEntity(client, self, "soh", const.SOH),
36+
37+
TempSensorEntity(client, self, "temp", const.BATTERY_TEMP)
38+
.attr("minCellTemp", const.ATTR_MIN_CELL_TEMP, 0)
39+
.attr("maxCellTemp", const.ATTR_MAX_CELL_TEMP, 0),
40+
TempSensorEntity(client, self, "minCellTemp", const.MIN_CELL_TEMP, False),
41+
TempSensorEntity(client, self, "maxCellTemp", const.MAX_CELL_TEMP, False),
1542

43+
CyclesSensorEntity(client, self, "cycles", const.CYCLES),
44+
45+
InWattsSensorEntity(client, self, "inputWatts", const.STREAM_IN_POWER),
46+
OutWattsSensorEntity(client, self, "outputWatts", const.STREAM_OUT_POWER),
47+
48+
RemainSensorEntity(client, self, "remainTime", const.REMAINING_TIME),
49+
]
50+
# moduleWifiRssi
1651
def numbers(self, client: EcoflowApiClient) -> list[BaseNumberEntity]:
1752
return []
1853

custom_components/ecoflow_cloud/devices/public/data_bridge.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import logging
2+
3+
_LOGGER = logging.getLogger(__name__)
4+
15
plain_to_status: dict[str, str] = {
26
"pd": "pdStatus",
37
"mppt": "mpptStatus",
@@ -13,42 +17,39 @@
1317

1418

1519
def to_plain(raw_data: dict[str, any]) -> dict[str, any]:
20+
new_params = {}
21+
prefix = ""
1622
if "typeCode" in raw_data:
17-
prefix = status_to_plain.get(
23+
prefix1 = status_to_plain.get(
1824
raw_data["typeCode"], "unknown_" + raw_data["typeCode"]
1925
)
20-
new_params = {}
21-
if "params" in raw_data:
22-
for k, v in raw_data["params"].items():
23-
new_params[f"{prefix}.{k}"] = v
24-
if "param" in raw_data:
25-
for k, v in raw_data["param"].items():
26-
new_params[f"{prefix}.{k}"] = v
27-
28-
result = {"params": new_params}
29-
for k, v in raw_data.items():
30-
if k != "param" and k != "params":
31-
result[k] = v
32-
33-
return result
26+
prefix += f"{prefix1}."
3427
elif "cmdFunc" in raw_data and "cmdId" in raw_data:
35-
new_params = {}
36-
prefix = f"{raw_data['cmdFunc']}_{raw_data['cmdId']}"
28+
prefix += f"{raw_data['cmdFunc']}_{raw_data['cmdId']}."
29+
else :
30+
prefix += ""
3731

38-
if "param" in raw_data:
39-
for k, v in raw_data["param"].items():
40-
new_params[f"{prefix}.{k}"] = v
32+
if "param" in raw_data:
33+
for k, v in raw_data["param"].items():
34+
new_params[f"{prefix}{k}"] = v
4135

42-
if "params" in raw_data:
43-
for k, v in raw_data["params"].items():
44-
new_params[f"{prefix}.{k}"] = v
36+
if "params" in raw_data:
37+
for k, v in raw_data["params"].items():
38+
new_params[f"{prefix}{k}"] = v
4539

46-
result = {"params": new_params}
47-
for k, v in raw_data.items():
48-
if k != "param" and k != "params":
49-
result[k] = v
40+
for k, v in raw_data.items():
41+
if k != "param" and k != "params":
42+
new_params[f"{prefix}{k}"] = v
43+
44+
new_params2 = {}
45+
for k, v in new_params.items():
46+
new_params2[k] = v
47+
if isinstance(v, dict):
48+
for k2, v2 in v.items():
49+
new_params2[f"{k}.{k2}"] = v2
50+
51+
result = {"params": new_params2}
52+
_LOGGER.debug(str(result))
53+
54+
return result
5055

51-
return result
52-
else :
53-
result = {"params": raw_data}
54-
return result

custom_components/ecoflow_cloud/devices/registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"Delta Pro 3": public_delta_pro_3.DeltaPro3,
7272
"Power Kits": public_powerkit.PowerKit,
7373
"Smart Meter": public_smart_meter.SmartMeter,
74-
"Stream AC": public_stream_ac.StreamAC,
74+
"STREAM AC": public_stream_ac.StreamAC,
7575
"Diagnostic": DiagnosticDevice,
7676
}
7777
)

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
homeassistant==2024.5.5
2-
paho_mqtt==2.1.0
3-
protobuf==5.27.0
1+
homeassistant>=2024.5.5
2+
paho_mqtt>=2.1.0
3+
protobuf>=5.27.0
44
jsonpath-ng>=1.7.0

0 commit comments

Comments
 (0)