georgezhao2010 / midea_ac_lan

Auto-configure and then control your Midea M-Smart devices (Air conditioner, Fan, Water heater, Washer, etc) via local area network.
MIT License
1.24k stars 194 forks source link

Heat Pumps: getting other data entities #179

Closed GoodLug closed 10 months ago

GoodLug commented 1 year ago

This code is fabulous, it managed to connect to my Midea heat pump, and gets the tank_actual_temperature as expected.

Like others, I would very much like to get other data, in particular:

outdoor temperature LWT (leaving or flow temp out of heat pump) RWT (returning water temp back to the heat pump) flow rate current current use and maybe some other data

all of which are visible on the wired controller, and must get sent over wifi to the midea cloud to provide data for the Midea app. I don't want to use the app/cloud, I am just suggesting it shows the data should be there).

But I can't see how to do this. I can add another entity in the code, and select it in Home Assistant, but how to get and parse the data message with the added data requests? With debugging on, I can see the code request data and gets a 50 character string that is then converted into a 25 item status update suggesting perhaps two characters for each item. Elsewhere the code uses a data offset to get the data, eg the tank_actual_temperature offset is + 21.

But how to request specific data, and convert the reply into human readable form? Does anyone know how to do this?

Perfect-Web commented 1 year ago

Can we please get a answer to this? would be a mandatory requirement imo

endigarnek commented 1 year ago

Hi, I also want to read more data from the heat pump

pmp02 commented 1 year ago

Hi, I have a Midea Heat Pump (C3 Wifi Controller) and this kind of data would be great to have! 👍

pmp02 commented 1 year ago

In wasilukm's fork I see that he managed to extract few more sensors. Maybe integrate some of those changes?

https://github.com/wasilukm/midea_ac_lan/blob/hp_state/doc/C3.md

endigarnek commented 1 year ago

How to add additional sensors? I can't handle the installation.

GoodLug commented 1 year ago

In wasilukm's fork you do indeed get total energy produced and consumed, but that's about it. It may be possible to get ambient temp as well. But that's it. Despite lots of painstaking work, I couldn't get anything else.

The total energy figures are always integers, meaning rounding errors, and we don't know how Midea does the rounding, so we don't know for sure which way the errors go.

The bottom line is this approach is limited. You don't get much, and what you do get is suspect.

As other have said, this isn't the way to get this data. Much better instead to use modbus over a wired connection. No encryption to get past, no flaky wifi connections, and full access to everything in the Midea modbus register tables. You don't even need Home Assistant, though it does have its uses. You can even dump that pesky Midea MSmarthome app. See here (and numerous other posts on the forum this link goes to):

https://renewableheatinghub.co.uk/forums/renewable-heating-air-source-heap-pumps-ashps/connecting-home-assistant-to-a-midea-heat-pump/paged/8#post-18441

pmp02 commented 1 year ago

Yes, indeed, the data is very truncated and rounded in midea app as well,.not quite accurate. Thank you for the link, I will check it out!

GoodLug commented 1 year ago

"not quite accurate" - very inaccurate much of the time, and variably so, so you can't use a constant correction factor. It does appear to get better (but still not accurate) over longer time frames, as the rounding error becomes smaller in proportion to the real amount of energy use over the time period: rounding 1.4 to 2 over a one hour period is a bigger proportional error than rounding 33.6 to 37 over a 24 hour period. But the real problem as I say is the error isn't constant, meaning there is no way it can be factored in.

The Midea app is terribly flaky. It (but not midea_ac_lan, which means the wired controller is still doing its thing) has been down for over 24 hours, with a message saying 'download plugin failed' but no apparent way to fix it.

georgezhao2010 commented 10 months ago

In wasilukm's fork you do indeed get total energy produced and consumed, but that's about it. It may be possible to get ambient temp as well. But that's it. Despite lots of painstaking work, I couldn't get anything else.

The total energy figures are always integers, meaning rounding errors, and we don't know how Midea does the rounding, so we don't know for sure which way the errors go.

The bottom line is this approach is limited. You don't get much, and what you do get is suspect.

As other have said, this isn't the way to get this data. Much better instead to use modbus over a wired connection. No encryption to get past, no flaky wifi connections, and full access to everything in the Midea modbus register tables. You don't even need Home Assistant, though it does have its uses. You can even dump that pesky Midea MSmarthome app. See here (and numerous other posts on the forum this link goes to):

https://renewableheatinghub.co.uk/forums/renewable-heating-air-source-heap-pumps-ashps/connecting-home-assistant-to-a-midea-heat-pump/paged/8#post-18441

Two interesting guys studied the code for a long time, but they didn’t even understand how the command is sent to the device.

One of them was furious at NotImplementedError because he couldn’t understand the basic concepts of superclass/subclass/abstract/implementation, while another one insisted that the TCP message was sent to Python’s _logging and then sent to the device by discover().

I can say very politely that almost all of their discussions are meaningless because they lack the basic knowledge to understand it all. Even their starting point was wrong from the beginning, as they studied how to obtain notify2, but failed to see that notify2 had already been handled in the code below.

        if (self._message_type in [MessageType.notify1, MessageType.query] and self._body_type == 0x01) or \
                self._message_type == MessageType.notify2:

See the notify2?

I’m sorry for losing my temper. I feel that their discussions are full of disrespect for others and self-righteousness. ”and your expert knowledge“, it's a joke.

GoodLug commented 10 months ago

georgezhao2010 - I am not sure whether I am also in the firing line, if I am, I meant no disrespect for the work you and wasilukm have done, which has achieved much given what you have had to work with. The problem as I see it is in the Midea code, and what it does and doesn't do, and does and doesn't make available, and the fact it is commercial, which opens up another can of worms. What other data are the collecting, and what do they do with the data?

I did spot the different message/notify types and tried writing code to manage these but failed. I also never really got clear in my mind whether there were real requests, or whether the code was as it were eavesdropping on Midea initiated messages (I inclined to think the latter, but in the HA logs there are two patterns, Sending/Received/Status update for the 'message type': '03', 'body type': '01' messages but only Received/Status update for the 'message type': '04', 'body type': '04' messages). Some of the messages appear to have a lot of data none of which appears to have any meaning. I think I did work out the latter 'message type': '04', 'body type': '04' messages also had the ambient temp in them at 'byte 09' if I remember correctly.

As I mentioned back in April, I ended up using modbus over a wired connection. This is very easy to set up, the Midea wired controller already has the necessary connections, and the only other hardware needed is a cable (I used Cat 5E) and a RS485 to USB adaptor. You then have access to all the data listed with their register addresses in the Midea wired controller manual, using whatever method you prefer (I used simple python scripts with minimal modbus). You can also, I suspect, but haven't yet tried it, also control the heat pump via the same connection.

georgezhao2010 commented 10 months ago

georgezhao2010 - I am not sure whether I am also in the firing line, if I am, I meant no disrespect for the work you and wasilukm have done, which has achieved much given what you have had to work with. The problem as I see it is in the Midea code, and what it does and doesn't do, and does and doesn't make available, and the fact it is commercial, which opens up another can of worms. What other data are the collecting, and what do they do with the data?

I did spot the different message/notify types and tried writing code to manage these but failed. I also never really got clear in my mind whether there were real requests, or whether the code was as it were eavesdropping on Midea initiated messages (I inclined to think the latter, but in the HA logs there are two patterns, Sending/Received/Status update for the 'message type': '03', 'body type': '01' messages but only Received/Status update for the 'message type': '04', 'body type': '04' messages). Some of the messages appear to have a lot of data none of which appears to have any meaning. I think I did work out the latter 'message type': '04', 'body type': '04' messages also had the ambient temp in them at 'byte 09' if I remember correctly.

As I mentioned back in April, I ended up using modbus over a wired connection. This is very easy to set up, the Midea wired controller already has the necessary connections, and the only other hardware needed is a cable (I used Cat 5E) and a RS485 to USB adaptor. You then have access to all the data listed with their register addresses in the Midea wired controller manual, using whatever method you prefer (I used simple python scripts with minimal modbus). You can also, I suspect, but haven't yet tried it, also control the heat pump via the same connection.

Modbus is a good choice for you if you need to get LWT/RWT and other numbers because I can’t get them from the notification of the Midea device. Like you, I can’t get the details of Midea’s message except through speculation. To make matters worse, I don't have a heat pump that I can track messages from, and no one has provided me with a log of messages to analyze. So I’ve tried to do everything that I can do.

PS. You mentioned the Midea code, but there is no code provided by Midea, not even a single line. All of it was written by me and other contributors.

Anyway, good luck to you.

GoodLug commented 10 months ago

georgezhao2010 - thanks, yes, using modbus has been successful and relatively painless. My python script simply writes the data every minute to a csv file, and includes the parameters needed to calculate COP (amps and volts for kWh in and flow rate and LWT/RWT for kWh out) as well as derive them from the Midea totals (by subtracting past total from current total) and the results are credible and mostly agree with each other, and the resulting COPs behave as expected ie go down when the unit is working harder eg in colder weather. I do have a dedicated external kWh meter that supplies only the heat pump and the Midea generated data is similar but not the same (about 2.5% less kWh in over longer periods, but with larger variations over shorter periods, meaning the Midea generated COPs are probably a little over-optimistic, but then again, it is after all marking it's own homework...

I don't have external third party kWh out metering equipment at the moment and am trying to decide whether it is worth installing it. It is not cheap, there are uncertainties as to how accurate it is, and it is complicated by the fact I have 'hydraulic separation' ie a plate heat exchanger between the primary ASHP circuit (which has glycol, another complication, as it alters the specific heat) and the secondary radiator circuit, raising the questions of where to set up the monitoring, and whether I should monitor both circuits.

Another oddity of the Midea unit is that the primary circuit always seems to run at a fixed flow rate when it is running, (around 1.4m^3/h, which is confirmed by a totally analogue rather basic flow rate sensor in the primary circuit) ie all modulation is done by changing flow and return temps, meaning it might be possible just to use affordable modbus connected flow and return temp sensors to get the kWh out for the primary circuit, and get a reasonable kWh out for the primary circuit that way. But that still tells me nothing (apart from a value it can't be above, ie the primary circuit kWh out) about the net kWh delivered to the rads is, and arguably that is what really matters...

PS I appreciate you wrote all the code, what I meant by the Midea code is the unseen Midea code that does what ever it does behind the scenes, and you very cleverly managed to work out enough to achieve what you did