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
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
An update to above to resolve HA device_class warnings:
diff --git a/plugins/deye_plugin_ha_discovery.py b/plugins/deye_plugin_ha_discovery.py index c8792c0..8cbb1f9 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,16 +121,19 @@ 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 @staticmethod def _get_state_class(topic: str) -> str: """Return state_class based on a given topic""" - if topic.endswith("day_energy"): + if topic.endswith("day_energy") or topic.endswith("charge") or "daily_energy" in topic : state_class = "total" - elif topic.endswith("total_energy"): - state_class = "total_increasing" - elif topic == "uptime": + elif "total_energy" in topic or topic == "uptime": state_class = "total_increasing" else: state_class = "measurement"Is there a plan for timeofuse and active_power_regulation?
Thanks, Leon
Let me adapt the existing rules first. We can discuss integration of timeofuse and active_power_regulation in a second step.
I would like to add the topics to the if statements to simplify later maintenance work.
Share a list of all missing topic, please.
I have ended up with the following update without missing sensors.
diff --git a/plugins/deye_plugin_ha_discovery.py b/plugins/deye_plugin_ha_discovery.py index c8792c0..e397210 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,16 +121,19 @@ 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 @staticmethod def _get_state_class(topic: str) -> str: """Return state_class based on a given topic""" - if topic.endswith("day_energy"): - state_class = "total" - elif topic.endswith("total_energy"): + if topic.endswith("day_energy") or topic.endswith("charge") or "daily_energy" in topic : state_class = "total_increasing" - elif topic == "uptime": + elif "total_energy" in topic or topic == "uptime": state_class = "total_increasing" else: state_class = "measurement"I would say that all energy sensors should be total_increasing. Further it bothers me this day_energy that I have daily_energy instead with with bunch of utility meters for exact reset for Energy card and Sunsynk-Power-Flow-Card to work correctly. I have also unsuccessfully tried to manually config the timeofuse switches and could not figure out correct command_topic to change the values in the inverter (see below). Any hint would be appreciated. From deye-inverter-mqtt I am missing several sensors to be R/W such as peak shaving (191), limit_control (142), off grid state...
# # Manual config for deye-inverter-mqtt # mqtt: # sensor: # - switch: # name: "Time of use Enabled 6" # state_topic: "deye/timeofuse/enabled/6" # command_topic: "deye/timeofuse/enabled/6/command" # payload_on: "1" # payload_off: "0" # unique_id: "deye_timeofuse_enabled_6" # device: # name: "Deye" # identifiers: # - "sun12k_sg04lp3" # - number: # - name: "Charge SOC 1" # state_topic: "deye/timeofuse/soc/1" # command_topic: "deye/timeofuse/soc/1/command" # unique_id: "deye_timeofuse_soc_1_set" # device: # name: "Deye" # identifiers: # - "sun12k_sg04lp3"
Published a development branch with new metric and total_increasing state class for day_energy in https://git.sr.ht/~carstengrohmann/deye-mqtt-ha-plugin/tree/more_inverters.
The changes for timeofuse and active_power_regulation are not implemented yet.
I've published a new release with suggested improvements, but without support for timeofuse and active_power_regulation.
Read the Changelog for a full list of changes.
I implemented publishing active power regulation to to HA. The plugin is available in branch active_power_regulation.
Please test and share your feedback.
~kosl Regarding writing time of use configuration: You've to write all configuration first and to send a 'write' command to
{MQTT_TOPIC_PREFIX}/timeofuse/control/command
later according the documentation in Writing Time Of Use configuration. Therefore you need a button to trigger thewrite
command additionally to the sensors.
Unfotunately, I don't have microinverter to test active power regulation. I have tested that anyway and the control shows OK. I am getting
Oct 21 18:46:10 etera python[16612]: 2024-10-21 18:46:10,973 - DeyeHADiscovery - ERROR - Unable to determinate device_class for topic ac/total_energy_bought Oct 21 18:46:10 etera python[16612]: 2024-10-21 18:46:10,974 - DeyeHADiscovery - ERROR - Unable to determinate device_class for topic ac/daily_energy_sold
I found a while ago "Writing Time Of Use configuration" (ToU) too and realised that I am missing several sensors to be R/W such as peak shaving (191), limit_control (142) in order to automate ToU effectively. They are outliers in the ToU Modbus range (146-171), but not that much, so at least 142 could be written in ToU range.
I've fixed the missing device class "energy" for topics ac/total_energy_bought and ac/daily_energy_sold in bbaaf004.
I released a new version 2024-11-20. This version adds support for active power regulation but need the current docker image from Deye solar inverter MQTT bridge.
I'm not able to integrate ToU, based on the current implementation. You can configure it manually in HA.
Full list of changes:
- Add support for active power regulation
- Internal code changes
- Use new public API to create MQTT topic (requires Deye solar inverter MQTT bridge at least version 2024.11.1)
I am closing this ticket. You are welcome to open a new ticket if you encounter any problems.