New OH3 Binding - Midea Air Conditioning (LAN)

Hi Jacek,
Look forward to your updates to use the measure framework after reading a few other blog posts that discuss UoM It seems it would solution this F to C conversion automatically

@JacekDob
Hi Jacek,
So a new version of the msmart has published and promoted on mac-zhou repo
GitHub - mac-zhou/midea-msmart: This is a library to allow communicating to a Midea AC via the Local area network. revision 0.1.29 as of this posting.
And then there is this repo which is geared to those using Home Assistant approach and it covers what his instructions are in regards on how to get the token and K1 values.
GitHub - mac-zhou/midea-ac-py: This is a custom component for Home Assistant to integrate the Midea Air Conditioners via the Local area network.
@eranl The above 2 repos I linked here are the original actual master repoā€™s that the links you mentioned were branched from as a fyi.
I can confirm this most recent revision does in fact work with a Version 3 module
The only catch is what you have to do to get the token and K1 key but after obtaining them it does work just fine.
without the fake server or the other DNS hack or any other requirements
I was able to use a basic example.py and fully control my version 3 AC just fine.
Hopefully this is enough info for you I included in my next post results as well as the example.py I used to validate with.
Also to anyone else reading this the device.py in the new revision has a check for the example.py from other repos to allow a Version 2 device to also use the example.py I pasted below in next post This also works without having to comment out the device.authenticate call just in case you want to test it with new revision from macā€™s repo only thing I did observe was that if you have multiple acā€™s and mixed like 1 version 2 device and 1 version 3 the results when just using the example.py was not always as expected.
snippet from device.py
def authenticate(self, key: str, token: str):
# compatible example.py
if key != ā€œYOUR_AC_K1ā€ and token != ā€œYOUR_AC_TOKENā€:
self._protocol_version = 3
self._token = bytearray.fromhex(token)
self._key = bytearray.fromhex(key)
self._authenticate()

1 Like

Below is the output of my test of the example.py with the new msmart revision 0.1.29

DEBUG:msmart.lan:Received from 192.168.1.178:6444 8370004020012c4 -truncated for obvious and for clarity
INFO:msmart.lan:Got TCP key for 192.168.1.178:6444 a84353 - truncated for obvious
DEBUG:msmart.command:Finalize request data: aa20ac - truncated for obvious
DEBUG:msmart.device:pkt_builder: 192.168.1.178:192.168.1.178 len: 104 data: 5a5a01116 -truncated for obvious
DEBUG:msmart.lan:Sending to 192.168.1.178:6444 8370008e20 - truncated for obvious
DEBUG:msmart.lan:Received from 192.168.1.178:6444 837000 - truncated for obvious
DEBUG:msmart.device:Got responses from 192.168.1.178:192.168.1.178 Version: 3 Count: 1
DEBUG:msmart.device:Update from 192.168.1.178:192.168.1.178 aa1eac000000000000031ea - truncated for obvious
DEBUG:msmart.command:Appliance response data: 1eacb20000 - truncated for obvious
{ā€˜idā€™: 307863257XXXXX, ā€˜nameā€™: ā€˜192.168.1.178ā€™, ā€˜power_stateā€™: False, ā€˜prompt_toneā€™: False, ā€˜target_temperatureā€™: 17.0, ā€˜operational_modeā€™: <operational_mode_enum.auto: 1>, ā€˜fan_speedā€™: <fan_speed_enum.Auto: 102>, ā€˜swing_modeā€™: <swing_mode_enum.Off: 0>, ā€˜eco_modeā€™: False, ā€˜turbo_modeā€™: False, ā€˜indoor_temperatureā€™: 0.0, ā€˜outdoor_temperatureā€™: 0.0} -XXXXX replaced device real ID
DEBUG:msmart.command:Finalize request data: aa23ac000000000000024001485 - truncated for obvious
DEBUG:msmart.device:pkt_builder: 192.168.1.178:192.168.1.178 len: 104 data: 5a5a01116 - truncated for obvious
DEBUG:msmart.lan:Sending to 192.168.1.178:6444 8370008e20 - truncated for obvious
DEBUG:msmart.lan:Received from 192.168.1.178:6444 8370007e2 - truncated for obvious
DEBUG:msmart.device:Got responses from 192.168.1.178:192.168.1.178 Version: 3 Count: 1
DEBUG:msmart.device:Update from 192.168.1.178:192.168.1.178 aa1eac000000 - truncated for obvious
DEBUG:msmart.command:Appliance response data: c00148507 - truncated for obvious
{ā€˜idā€™: 307863257XXXXX, ā€˜nameā€™: ā€˜192.168.1.178ā€™, ā€˜power_stateā€™: True, ā€˜prompt_toneā€™: False, ā€˜target_temperatureā€™: 24.0, ā€˜operational_modeā€™: <operational_mode_enum.cool: 2>, ā€˜fan_speedā€™: <fan_speed_enum.High: 80>, ā€˜swing_modeā€™: <swing_mode_enum.Off: 0>, ā€˜eco_modeā€™: False, ā€˜turbo_modeā€™: False, ā€˜indoor_temperatureā€™: 24.0, ā€˜outdoor_temperatureā€™: 34.5} - Replaced real ID with XXXXX

This is what I used as example.py

from msmart.device import air_conditioning_device as ac
import logging
logging.basicConfig(level=logging.DEBUG)

"# first take deviceā€™s ip and id, port is generally 6444
"# pip3 install msmart; midea-discover
device = ac(ā€˜YOUR_AC_IPā€™, YOUR_AC_ID, 6444)
"# If the device is using protocol 3 (aka 8370)
"# you must authenticate with deviceā€™s k1 and token.
"# adb logcat | grep doKeyAgree
device.authenticate(ā€˜YOUR_AC_K1ā€™, ā€˜YOUR_AC_TOKENā€™)

"# Refresh the object with the actual state by querying it
device.refresh()
print({
ā€˜idā€™: device.id,
ā€˜nameā€™: device.ip,
ā€˜power_stateā€™: device.power_state,
ā€˜prompt_toneā€™: device.prompt_tone,
ā€˜target_temperatureā€™: device.target_temperature,
ā€˜operational_modeā€™: device.operational_mode,
ā€˜fan_speedā€™: device.fan_speed,
ā€˜swing_modeā€™: device.swing_mode,
ā€˜eco_modeā€™: device.eco_mode,
ā€˜turbo_modeā€™: device.turbo_mode,
ā€˜indoor_temperatureā€™: device.indoor_temperature,
ā€˜outdoor_temperatureā€™: device.outdoor_temperature
})

"# Set the state of the device and
device.prompt_tone = True
device.power_state = True
"# device.prompt_tone = False
device.target_temperature = 24
device.operational_mode = ac.operational_mode_enum.cool
device.fan_speed = ac.fan_speed_enum.High
"# commit the changes with apply()
device.apply()
print({
ā€˜idā€™: device.id,
ā€˜nameā€™: device.ip,
ā€˜power_stateā€™: device.power_state,
ā€˜prompt_toneā€™: device.prompt_tone,
ā€˜target_temperatureā€™: device.target_temperature,
ā€˜operational_modeā€™: device.operational_mode,
ā€˜fan_speedā€™: device.fan_speed,
ā€˜swing_modeā€™: device.swing_mode,
ā€˜eco_modeā€™: device.eco_mode,
ā€˜turbo_modeā€™: device.turbo_mode,
ā€˜indoor_temperatureā€™: device.indoor_temperature,
ā€˜outdoor_temperatureā€™: device.outdoor_temperature
})
ā€“fyi the double quotes I put in front of the comments was to stop the blog from bold and cap font size changes remove if you copy paste this example of course otherwise it is syntactically correct also note the YOUR_AC_ID has to be a intgr not a string or it will not workā€”
----------Below is for folks who may read this and not be sure what is needed/or how to get token------
There may be easier ways and if someone wants to add them please feel free to share.
For anyone wondering below outlines exactly what I did to get the token and key1
In order to get those values for your version 3 device you have to be able run a terminal session elevated (rooted)on your device with the midea app installed and also have a valid (its free) midea account set up and BE LOGGED INTO THE APP on the Emulator or phone you are using to retrieve the token and key1 !.
Also what I did may not be the way you want to do it but it was easier for me to just download a ISO of the android-x86 emulator I ended up using the Oreo (8.1-r6) version as pie (9.0-r2) did not seem to allow me to see the token and value for some reason. Yet as soon as I tried exactly the same steps on the Oreo version everything just worked fine. I downloaded Oreo(8.1-r6) version of android-x86 from here( Android-x86 - Porting Android to x86 and ran it in a hyper-v instance I then downloaded the apk from the link mac-zhou uploaded from here
https://media.githubusercontent.com/media/mac-zhou/LFS/main/Midea-Air-gettoken-only-oversea.apk
directly in the emulator and allowed it to install (It prompts a nag message about not installing from google play btw)
after that was in and running I logged into my nethome account same creds as normal (you could create new I guess also) after it found my A/C I continued as follows
I enabled the emulator to allow developer mode(7 taps blagh blagh as always on android)
I then opened up the terminal app that comes preinstalled on the emulator
and ran the command
logcat | grep doKeyAgree
It displayed the values I was looking for almost immediately
as for how you save off the values I will let you decide how you want to do it
But for me I went ahead and set up adb to connect wireless to my regular windows PC command prompt using the android sdk I dlā€™d from android studio developer site and had already configured a long while ago when dinosaurā€™s still roamed the earth :roll_eyes:
As for how to allow the PC make a connection to the emulator in the terminal(command) window
you can follow these steps from stack overflow as well .
networking - How can I connect to Android with ADB over TCP? - Stack Overflow
To enable the connection from device to PC on the device or emulatorā€™s terminal app(window)
run
su (it will nag about you elevating super user and make you choose for how long)
setprop service.adb.tcp.port 5555 (you can use any port you want just has to match with what you run with sdk side)
next you need to recycle the adb service so it picks up your new service entry property and begins listening on the tcp port instead of USB
run
stop adbd
start adbd
on the PC you have the sdk installed on
open a elevated command prompt
run
adb connect ā€˜IP and port of your emulatorā€™ (example : adb connect 192.168.1.177:5555)
if all is good it will respond back with something like so
C:\WINDOWS\system32>adb connect 192.168.1.177:5555

  • daemon not running; starting now at tcp:5037
  • daemon started successfully
    connected to 192.168.1.177:5555
    then run
    adb shell
    you should see it switch to
    C:\WINDOWS\system32>adb shell
    x86:/ $
    now from the shell command line
    run
    logcat | grep doKeyAgree
    you should get something like this back (I have replaced much of the values with Xā€™s for obvious reasons!)
    08-13 08:57:07.043 5055 5169 D sstwzs : doKeyAgree ip:192.168.1.178 udpid:08d9efcff5815a754c93XXXXXXXXXXXX token:38D4DB7519E14F20049BB3CCA6B56C285FFCC43E9A64966DC99D0E56F2961D97F446E309380298E66EXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX k1:2FBF9CD6F0E2452CAF316BCD2BBEFBXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    from there it is basic good old MSFT cmd line easy cut and paste mode :yum:
    Any way hope this is helpful to someone at some point and saves them a bunch of searching various sites looking for how to do itā€™s!! :grinning:
    Regards,
    Justan Oldman
1 Like

@justaoldman

Thank you so much for such an effort and checking above solutions.

Indeed recent commits handles protocol 3 with this authentication.

Unfortenatully it does not seem to be a simple fix/implementation in comparison to existing implementation.

I donā€™t think it would be possible for me to implement it without having such a device.

I think a contributor to the existing code would very appreciated.

Jacek

Hey guys, did anyone already install OH 3.2 and got the latest version of this binding running? Is there a chance, to get it working without changes? Otherwise, Iā€™ll wait and hope @JacekDob will do the necessary changes :wink:

1 Like

Hi,

I have two midea aircons both with EU-OSK103 wifi modules. I have setup the ip, port 6444 and my deviceid in openhab. But it keeps on timing out

What can I do to fix this?

I want to try this addon because I have numerous issues linking midea air to google home. Keep on getting midea air is unreachable.

Hi everyone,

I am getting the following errors every few minutes:

2022-03-26 16:49:11.909 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'mideaac:ac:mideaac__192_168_112_473_net_ac_abcd' changed from UNKNOWN to OFFLINE (COMMUNICATION_ERROR): Read timed out

2022-03-26 16:49:11.912 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'mideaac:ac:mideaac__192_168_112_473_net_ac_abcd' changed from OFFLINE (COMMUNICATION_ERROR): Read timed out to UNKNOWN

2022-03-26 16:49:12.161 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'mideaac:ac:mideaac__192_168_112_473_net_ac_abcd' changed from UNKNOWN to OFFLINE (COMMUNICATION_ERROR): Device not responding with its status.

What can be done to fix it ? Do we know what is causing this time outs ?

Hi Jacek,
I am new to OH3 (little bit more familiar with OH2).
I just got Rotenso AC with EU-OSK105 dongle. This works with NetHome Plus app for Android.
Configured AC to use my home WiFi, app works.
I donā€™t like to use any kind of ā€œcloudā€, as it involves possibility to control takeover by someone.

Got to this thread by googling ā€œopenhab EU-OSK105ā€

How can I try to use this AC with OH3?
Are there some howtos?

Laurent (Wawrzyniec)

Hi,

Steps to use my binding are:

  1. Install binding (download jar mentioned in first post and place it in add-on folder)
  2. Go to administration panel and then to Settings->Things->ā€œ+ā€->MideaAC Binding->Scan and then select found device and create a thing.
  3. Attach/Add thing channels to items.

Jacek

Release notes (202204111742):

  • Unit provider fix
    Tested on openHAB 3.2.0 - Release Build
1 Like

Hello Jacek,
nice work. I have an AC Rotenso IMoto 3.5kW, equipped with EU-OSK105 ā€œWiFi kit modemā€.
This connects with NetHome Plus app on Android. Works OK.
(this is how I went here googling about WiFi module symbol).

Can Your binding be useful with this device?
(may provide help /tests with this on my lan. Have OH2 on ARM32, OH3 on ARM64, all Armbian Buster, and OH2 on x86_64 Linux Fedora 30/35).

[edit]
Installed JAR in add-ons on ARM64, could add a device with Your binding by address/port (without restarting OH!). Now it flickers (on Things list) between ā€œOnlineā€ and ā€œOfflineā€ ā€œcommunications errorā€. Possibly it got ā€œdeviceIdā€ as ā€œcodeā€ view exhibits some data in this field (and I left ā€œ0ā€ during setup).

What should I do next? (Provide logs? - Which ones?). I am not Java-aware man, but still informatician / programmer ;p.

[edit2]
ā€œScanā€ didnā€™t worked for me, probably because AC is on another IP network (mine is ..1.0/24 and AC is on ..10.0/24, there is routing between, working as I can ping AC).

[edit3]
Port 6444 is open on AC, I can telnet to, but no ā€œwelcome messageā€ :slight

Laurent (Wawrzyniec)

Hi

I just started using Our binding a few days ago

does this release fix the occasional disconnecting of the device as well?

If not do you have any suggestions of what I could to to fix it ?

If there is any way I can be of help let me know

Please post your Device Properties, it seems that you have device version 3, which is not yet supported by the binding.

Jacek

@laurentppol, please post your Device Properties, it seems that you have device version 3, which is not yet supported by the binding.

How to do it? (sorry I am OpenHAB newbie).

UID: mideaac:ac:32445f98ed
label: Rotenso IMoto AC
thingTypeUID: mideaac:ac
configuration:
  ipAddress: 192.168.10.254
  pollingTime: 10
  promptTone: true
  ipPort: "6444"
  deviceId: "31885837915485"
location: Salon

?
Or something else?

Dear All interested in support of binding with devices using version 3.

Somebody with Java skills needed, to enhance binding code to support it.
Code is open and available on Github.

@justaoldman did a lot of research (many thanks!!!) and it seems that it should work and could be implemented.

On the one hand, I donā€™t have such a device, but on the other hand I donā€™t have so much time for it. although I can support it.

Polish speaking person would be the best.

Jacek

Go to administration page of openHAB->Settings->Things->Click on your device and there is Information section like this:

Version is last parameter.

Jacek

Latest version of binding works for me with OH 3.2.0.

Jacek

What device version do you have (should be provided in Device information as a property)?

Jacek

Does the latest version support correctly temperature units?

Jacek