Skip to content

Commit

Permalink
Add battery state sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentwolsink committed Apr 18, 2024
1 parent f2d5082 commit e34e586
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
16 changes: 14 additions & 2 deletions custom_components/enphase_envoy/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@
"800-01127-r02": {"name": "IQ7A Microinverter", "sku": "IQ7A-72-M-INT"},
}

BATTERY_STATE_MAPPING = {
12: "Charging",
13: "Discharging",
14: "Idle. Fully charged.",
17: "Idle. Low charge.",
}


def resolve_product_mapping(product_id):
if PRODUCT_ID_MAPPING.get(product_id, None) != None:
Expand Down Expand Up @@ -182,7 +189,7 @@ def get_model_name(model, hardware_id):
),
SensorEntityDescription(
key="batteries_percentFull",
name="Charged",
name="Charge",
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.BATTERY,
Expand All @@ -209,9 +216,14 @@ def get_model_name(model, hardware_id):
state_class=SensorStateClass.TOTAL,
device_class=SensorDeviceClass.ENERGY,
),
SensorEntityDescription(
key="batteries_led_status",
name="Status",
icon="mdi:battery-sync",
),
SensorEntityDescription(
key="agg_batteries_soc",
name="Batteries Charged",
name="Batteries Charge",
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.BATTERY,
Expand Down
7 changes: 7 additions & 0 deletions custom_components/enphase_envoy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
LIVE_UPDATEABLE_ENTITIES,
ENABLE_ADDITIONAL_METRICS,
ADDITIONAL_METRICS,
BATTERY_STATE_MAPPING,
resolve_hardware_id,
get_model_name,
)
Expand Down Expand Up @@ -387,6 +388,12 @@ def native_value(self):
.get("real_power_mw")
/ 1000
)
elif self.entity_description.key == "batteries_led_status":
return BATTERY_STATE_MAPPING.get(
self.coordinator.data.get("batteries")
.get(self._device_serial_number)
.get("led_status")
)
else:
return (
self.coordinator.data.get("batteries")
Expand Down

0 comments on commit e34e586

Please sign in to comment.