~mikaabra


#1 enhancement with deye battery inverter 8 months ago

Comment by ~mikaabra on ~carstengrohmann/deye-mqtt-ha-plugin

Found out how to do code blocks in markdown.

diff --git a/plugins/deye_plugin_ha_discovery.py b/plugins/deye_plugin_ha_discovery.py
index c8792c0..4a25ae4 100644
--- a/plugins/deye_plugin_ha_discovery.py
+++ b/plugins/deye_plugin_ha_discovery.py
@@ -106,10 +106,13 @@ class DeyeHADiscovery(DeyeEventProcessor):
             device_class = "voltage"
         elif topic.endswith("/current"):
             device_class = "current"
-        elif topic.endswith("day_energy"):
+        elif "energy" in topic:
             device_class = "energy"
-        elif topic.endswith("total_energy"):
+        elif "charge" in topic:
             device_class = "energy"
+        elif topic.endswith("/internal") or topic.endswith("/external"):
+            if any(l in topic for l in ["/l1/", "/l2/", "/l3/"]):
+                device_class = "power"
         elif topic.endswith("power"):
             device_class = "power"
         elif topic.endswith("/freq"):
@@ -118,6 +121,11 @@ class DeyeHADiscovery(DeyeEventProcessor):
             device_class = "duration"
         elif topic == "radiator_temp":
             device_class = "temperature"
+        elif "temperature" in topic:
+            device_class = "temperature"
+        elif topic == "battery/soc":
+            device_class = "battery"
+            unit_of_measurement: '%'
         return device_class

#1 enhancement with deye battery inverter 8 months ago

Ticket created by ~mikaabra on ~carstengrohmann/deye-mqtt-ha-plugin

I'm a bit confused over how to submit a diff so doing it via ticket instead.

On my Deye inverter there are numerous values that the ha-plugin doesn't recognize, for instance:

deye-mqtt-1  | 2024-09-04 08:41:20,374 - DeyeHADiscovery - ERROR - Unable to determinate device_class for topic battery/daily_charge
deye-mqtt-1  | 2024-09-04 08:41:20,374 - DeyeHADiscovery - ERROR - Unable to determinate device_class for topic battery/daily_discharge
deye-mqtt-1  | 2024-09-04 08:41:20,374 - DeyeHADiscovery - ERROR - Unable to determinate device_class for topic battery/total_charge
deye-mqtt-1  | 2024-09-04 08:41:20,374 - DeyeHADiscovery - ERROR - Unable to determinate device_class for topic battery/total_discharge
deye-mqtt-1  | 2024-09-04 08:41:20,375 - DeyeHADiscovery - ERROR - Unable to determinate device_class for topic battery/soc
deye-mqtt-1  | 2024-09-04 08:41:20,376 - DeyeHADiscovery - ERROR - Unable to determinate device_class for topic battery/temperature
deye-mqtt-1  | 2024-09-04 08:41:20,379 - DeyeHADiscovery - ERROR - Unable to determinate device_class for topic ac/l1/ct/internal
deye-mqtt-1  | 2024-09-04 08:41:20,379 - DeyeHADiscovery - ERROR - Unable to determinate device_class for topic ac/l2/ct/internal
deye-mqtt-1  | 2024-09-04 08:41:20,379 - DeyeHADiscovery - ERROR - Unable to determinate device_class for topic ac/l3/ct/internal
deye-mqtt-1  | 2024-09-04 08:41:20,379 - DeyeHADiscovery - ERROR - Unable to determinate device_class for topic ac/l1/ct/external
deye-mqtt-1  | 2024-09-04 08:41:20,379 - DeyeHADiscovery - ERROR - Unable to determinate device_class for topic ac/l2/ct/external
deye-mqtt-1  | 2024-09-04 08:41:20,379 - DeyeHADiscovery - ERROR - Unable to determinate device_class for topic ac/l3/ct/external
deye-mqtt-1  | 2024-09-04 08:41:20,386 - DeyeHADiscovery - ERROR - Unable to determinate device_class for topic ac/temperature

The below diff addresses all of these and runs without errors.

diff --git a/plugins/deye_plugin_ha_discovery.py b/plugins/deye_plugin_ha_discovery.py
index c8792c0..4a25ae4 100644
--- a/plugins/deye_plugin_ha_discovery.py
+++ b/plugins/deye_plugin_ha_discovery.py
@@ -106,10 +106,13 @@ class DeyeHADiscovery(DeyeEventProcessor):
             device_class = "voltage"
         elif topic.endswith("/current"):
             device_class = "current"
-        elif topic.endswith("day_energy"):
+        elif "energy" in topic:
             device_class = "energy"
-        elif topic.endswith("total_energy"):
+        elif "charge" in topic:
             device_class = "energy"
+        elif topic.endswith("/internal") or topic.endswith("/external"):
+            if any(l in topic for l in ["/l1/", "/l2/", "/l3/"]):
+                device_class = "power"
         elif topic.endswith("power"):
             device_class = "power"
         elif topic.endswith("/freq"):
@@ -118,6 +121,11 @@ class DeyeHADiscovery(DeyeEventProcessor):
             device_class = "duration"
         elif topic == "radiator_temp":
             device_class = "temperature"
+        elif "temperature" in topic:
+            device_class = "temperature"
+        elif topic == "battery/soc":
+            device_class = "battery"
+            unit_of_measurement: '%'
         return device_class