Skip to content

Commit

Permalink
Upgrade energy entities (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
vwt12eh8 authored Jul 30, 2022
1 parent 1fb2ae2 commit 932468b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,29 @@ Once installed, after restarting Home Assistant, you can start integration as us
- [ ] Extra Battery

## How to register for the Energy Dashboard
- MPPT input energy : Solar Panels -> Solar production energy
- total input energy : Home Battery Storage -> Energy going in to the battery
- total output energy : Home Battery Storage -> Energy coming out of the battery
With this integration, total input and total output energy can be obtained from the device in AC and DC respectively.

The process of excluding pass-through power is necessary to display the correct graph on the energy dashboard.

This process can easily be done using the [Pass-Through Meter](https://github.com/vwt12eh8/hassio-pass-through-meter) integration.

1. Install both the EcoFlow integration and the Pass-Through Meter integration.
2. Set up the EcoFlow integration first
3. Set up the Pass-Through Meter integration and specify the EcoFlow integration entities as follows
- Input entities: AC input energy, Car input energy, MPPT input energy
- Output entities: AC output energy, DC output energy
- Device: Your EcoFlow device
- Hide members: ON is recommended
4. Register the following entities created by the Pass-Through Meter integration in the energy dashboard as storage batteries
- Energy charged
- Energy discharged
5. Register the following entities created by EcoFlow integration in the energy dashboard as solar panels
- MPPT input energy

Note that due to firmware specifications, the DELTA series devices will not correctly record the amount of power with an MPPT input of less than 20W (Pro: less than 40W).
To resolve this, create an integral helper from the DC input entity and specify it as an alternative to Car input energy and MPPT input energy in the Input Entities of the Pass-Through Meter integration.

However, this method will not record the power generated while the device is out of the LAN.

## About Remain Entities
The Remain entity is disabled by default because it is highly variable and generates a large number of writes to the database.
Expand Down
4 changes: 2 additions & 2 deletions custom_components/ecoflow/ecoflow/receive.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def parse_pd_delta(d: bytes):
("car_in_energy", 4, _to_int),
("mppt_in_energy", 4, _to_int),
("ac_in_energy", 4, _to_int),
("car_out_energy", 4, _to_int),
("dc_out_energy", 4, _to_int),
("ac_out_energy", 4, _to_int),
("usb_time", 4, _to_timedelta_sec),
("typec_time", 4, _to_timedelta_sec),
Expand Down Expand Up @@ -484,7 +484,7 @@ def parse_pd_river(d: bytes):
("car_in_energy", 4, _to_int),
("mppt_in_energy", 4, _to_int),
("ac_in_energy", 4, _to_int),
("car_out_energy", 4, _to_int),
("dc_out_energy", 4, _to_int),
("ac_out_energy", 4, _to_int),
("usb_time", 4, _to_timedelta_sec),
("usbqc_time", 4, _to_timedelta_sec),
Expand Down
25 changes: 8 additions & 17 deletions custom_components/ecoflow/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_e
"ac_in_current", "AC input current"),
CurrentEntity(client, client.inverter,
"ac_out_current", "AC output current"),
EnergyEntity(client, client.pd, "ac_in_energy",
"AC input energy"),
EnergyEntity(client, client.pd, "ac_out_energy",
"AC output energy"),
EnergyEntity(client, client.pd, "car_in_energy",
"Car input energy"),
EnergyEntity(client, client.pd, "dc_out_energy",
"DC output energy"),
EnergyEntity(client, client.pd, "mppt_in_energy",
"MPPT input energy"),
EnergySumEntity(client, "in_energy", [
"ac", "car", "mppt"], "Total input energy"),
EnergySumEntity(client, "out_energy", [
"ac", "car"], "Total output energy"),
FanEntity(client, client.inverter, "fan_state", "Fan"),
FrequencyEntity(client, client.inverter,
"ac_in_freq", "AC input frequency"),
Expand Down Expand Up @@ -199,19 +203,6 @@ class EnergyEntity(BaseEntity):
_attr_state_class = SensorStateClass.TOTAL_INCREASING


class EnergySumEntity(EnergyEntity):
def __init__(self, client: HassioEcoFlowClient, key: str, keys: list[str], name: str):
super().__init__(client, client.pd, key, name)
self._suffix_len = len(key) + 1
self._keys = [f"{x}_{key}" for x in keys]

def _on_updated(self, data: dict[str, Any]):
values = {key[:-self._suffix_len]: data[key]
for key in data if key in self._keys}
self._attr_extra_state_attributes = values
self._attr_native_value = sum(values.values())


class FanEntity(BaseEntity):
_attr_state_class = SensorStateClass.MEASUREMENT

Expand Down

0 comments on commit 932468b

Please sign in to comment.