K02 WIFI USB with NetHome app

How do you mean that it’s been blacklisted? The python script? If it’s blacklisted by OH, I guess you’ll need to add it to an exec.whitelist file. Fe: in /etc/openhab2/misc/exec.whitelist

/etc/openhab2/scripts/midea_check.sh
/etc/openhab2/scripts/midea_start.sh

Personally, I start the python script over a standard linux cron (every 20 min check and restart if necessary).

@brononius
How did you connect the new scripts midea-msmart with OpenHAB?

In the new updated version which uses the LAN conntection. Is the 17 degree bug still existent (the bug where it resets the air conditioner to 17 degree fan all the time ?

if i do:
python3 main.py

I get the following:

2020-06-22 09:56:51,740 Setting OH: ac_Woonkamer_active (active) = ON
2020-06-22 09:56:51,749 OH ac_Woonkamer_active not found, blacklisting
2020-06-22 09:56:51,750 Setting OH: ac_Woonkamer_online (online) = ON
2020-06-22 09:56:51,758 OH ac_Woonkamer_online not found, blacklisting
2020-06-22 09:56:51,758 Setting OH: ac_Woonkamer_indoor_temperature (indoor_temperature) = 24.5
2020-06-22 09:56:51,763 OH ac_Woonkamer_indoor_temperature not found, blacklisting
2020-06-22 09:56:51,763 Setting OH: ac_Woonkamer_outdoor_temperature (outdoor_temperature) = 31.0
2020-06-22 09:56:51,768 OH ac_Woonkamer_outdoor_temperature not found, blacklisting
2020-06-22 09:56:51,768 Setting OH: ac_Woonkamer_power_state (power_state) = OFF
2020-06-22 09:56:51,773 OH ac_Woonkamer_power_state not found, blacklisting
2020-06-22 09:56:51,774 Setting OH: ac_Woonkamer_target_temperature (target_temperature) = 21.0
2020-06-22 09:56:51,779 OH ac_Woonkamer_target_temperature not found, blacklisting
2020-06-22 09:56:51,779 Setting OH: ac_Woonkamer_operational_mode (operational_mode) = 1.0
2020-06-22 09:56:51,784 OH ac_Woonkamer_operational_mode not found, blacklisting
2020-06-22 09:56:51,784 Setting OH: ac_Woonkamer_fan_speed (fan_speed) = 102.0
2020-06-22 09:56:51,788 OH ac_Woonkamer_fan_speed not found, blacklisting
2020-06-22 09:56:51,789 Setting OH: ac_Woonkamer_swing_mode (swing_mode) = 0.0
2020-06-22 09:56:51,793 OH ac_Woonkamer_swing_mode not found, blacklisting
2020-06-22 09:56:51,794 Setting OH: ac_Woonkamer_eco_mode (eco_mode) = OFF
2020-06-22 09:56:51,799 OH ac_Woonkamer_eco_mode not found, blacklisting
2020-06-22 09:56:51,799 Setting OH: ac_Woonkamer_turbo_mode (turbo_mode) = OFF
2020-06-22 09:56:51,803 OH ac_Woonkamer_turbo_mode not found, blacklisting

So it is making connection to the AC’s but i don’t know how to connect it to openhab.
Should i create things or bindings?
i already created the following items:

Switch  ac_Woonkamer_online                     "Online [%s]"                   <switch>                (GF_LivingRoom)
Switch  ac_Woonkamer_power_state                "Power state [%s]"              <switch>                (GF_LivingRoom)
Number  ac_Woonkamer_operational_mode           "Modus []"                       <pump>                 (GF_LivingRoom)
Switch  ac_Woonkamer_active                     "Actief [%s]"                   <switch>                (GF_LivingRoom)
Number  ac_Woonkamer_target_temperature         "Doel temperatuur [%d°C]"     <temperature_cold>      	(GF_LivingRoom)
Number  ac_Woonkamer_indoor_temperature         "Binnen temperatuur [%.1f°C]"   <temperature>           (GF_LivingRoom)
Number  ac_Woonkamer_outdoor_temperature        "Buiten temperatuur [%.1f°C]"  <temperature>           	(GF_LivingRoom)
Number  ac_Woonkamer_fan_speed                  "Fan speed []"                  <fan>                   (GF_LivingRoom)
Number  ac_Woonkamer_swing_mode                 "Swing mode []"                 <flow>                  (GF_LivingRoom)
Switch  ac_Woonkamer_eco_mode                   "Eco mode [%s]"                 <switch>                (GF_LivingRoom)
Switch  ac_Woonkamer_turbo_mode                 "Turbo mode [%s]"               <switch>                (GF_LivingRoom)

Switch  ac_Zolder_online                     "Online [%s]"                   <switch>                	(AT_Bedroom)
Switch  ac_Zolder_power_state                "Power state [%s]"              <switch>                	(AT_Bedroom)
Number  ac_Zolder_operational_mode           "Modus []"                       <pump>                  	(AT_Bedroom)
Switch  ac_Zolder_active                     "Actief [%s]"                   <switch>                	(AT_Bedroom)
Number  ac_Zolder_target_temperature         "Doel temperatuur [%d°C]"     <temperature_cold>      		(AT_Bedroom)
Number  ac_Zolder_indoor_temperature         "Binnen temperatuur [%.1f°C]"   <temperature>           	(AT_Bedroom)
Number  ac_Zolder_outdoor_temperature        "Buiten temperatuur [%.1f°C]"  <temperature>           	(AT_Bedroom)
Number  ac_Zolder_fan_speed                  "Fan speed []"                  <fan>                   	(AT_Bedroom)
Number  ac_Zolder_swing_mode                 "Swing mode []"                 <flow>                  	(AT_Bedroom)
Switch  ac_Zolder_eco_mode                   "Eco mode [%s]"                 <switch>                	(AT_Bedroom)
Switch  ac_Zolder_turbo_mode                 "Turbo mode [%s]"               <switch>                	(AT_Bedroom)

(BTW. I am running on a hyper-v ubuntu-linux 20.04 server)

No binding or thing needed. The python script does the work. Just be sure that this script is running. I created a small script that checks every 20 minutes if it runs, and if not, it (tries) to start it.

Add (gPersChng) to each item lines. My items for reference:

Switch  ac_Leefruimte_online                    "Leefruimte [%s]"               <switch>                (gPersChng, hvac)
Switch  ac_Leefruimte_power_state               "Status[%s]"                    <switch>                (gPersChng, hvac_On, hvac_leefruimte_status)
Number  ac_Leefruimte_operational_mode          "Mode [%s]"                     <pump>                  (gPersChng, hvac_operational_mode)
Switch  ac_Leefruimte_active                    "Activeer [%s]"                 <switch>                (gPersChng)
Number  ac_Leefruimte_target_temperature        "Gewenste temperatuur [%d ÂC]"  <temperature_cold>      (gPersChng, hvac_target_temperature)
Number  ac_Leefruimte_indoor_temperature        "HVAC Hal [%.1f ÂC]"            <temperature>           (gPersChng, hvac_indoor_temperature, tem_HAL, tem_LEE, WO_tem)
Number  a...

And keep in mind that it won't trigger right away. All depends on your poll sequences. For me, it can take sometimes 30 seconds before the units react. Patience is a beautifull virtue.

@brononius

Before there was a bug that each time data was pulled that the air condition unit would switch mode to fan and switch to 17 degrees. Is that still the case with the latest version of the script ?

In my case, it works as expected. My temperature stays stable (fe the whole day here at 24), and mode is cooling now. But it’s auto in my case. I don’t really change this.

@brononius I have just installed the midea-msmart via pip3 as shown on the github page of the project on my openhabian.
Could you please advice on how I can use this new midea-msmart with openhab.
I am a little lost right now

Guess I’ll need some extra info to know where you are. :blush:

  1. Did you update the settings.py file with your specific settings?

  2. Are you running the python script?
    When you start this script, it gives you direct some good info about the status of your connection.
    Btw, this script must run the whole time! so best to run it in a script that you start when you boot.
    Not sure where you placed it, but in my case:

    python3 /etc/openhab2/scripts/midea/main.py

  3. Did you create the OpenHAB items already?

  4. If so, do you have any entries for the items in the events.log?

Hello guys,

Is there anyone who could create an midea2mqtt version with this script?

That would make it easy to setup for everyone.

I would pay for a development of that.

best,
salexes

There is also a LAN branch from bricky now:

The only issue I have with that is that when using it the sound/beep is missing. Any idea how to get it back/activate the sound when using this script?

Trying out the LAN version.
I can nicely poll the unit, and the first run gives me all necessary data.
But then, something goes wrong?

2021-01-06 09:35:11,290 Setting OH: ac_acOuderkamer_outdoor_temperature (outdoor_temperature) = 3.5
2021-01-06 09:35:11,295 Setting OH: ac_acOuderkamer_power_state (power_state) = OFF
2021-01-06 09:35:11,299 Setting OH: ac_acOuderkamer_target_temperature (target_temperature) = 24.0
2021-01-06 09:35:11,304 Setting OH: ac_acOuderkamer_operational_mode (operational_mode) = 1.0
2021-01-06 09:35:11,309 Setting OH: ac_acOuderkamer_fan_speed (fan_speed) = 102.0
2021-01-06 09:35:11,313 Setting OH: ac_acOuderkamer_swing_mode (swing_mode) = 15.0
2021-01-06 09:35:11,318 Setting OH: ac_acOuderkamer_eco_mode (eco_mode) = OFF
2021-01-06 09:35:11,322 Setting OH: ac_acOuderkamer_turbo_mode (turbo_mode) = OFF
Exception in sse_loop: JSONDecodeError('Expecting value: line 1 column 1 (char 0)')
2021-01-06 09:35:12,889 Failure in sse_loop
Traceback (most recent call last):
  File "main.py", line 317, in sse_loop
    data = json.loads(evt.data)
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Exception in sse_loop: JSONDecodeError('Expecting value: line 1 column 1 (char 0)')
2021-01-06 09:35:18,961 Failure in sse_loop
Traceback (most recent call last):
  File "main.py", line 317, in sse_loop
    data = json.loads(evt.data)
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Exception in sse_loop: JSONDecodeError('Expecting value: line 1 column 1 (char 0)')
2021-01-06 09:35:25,821 Failure in sse_loop
Traceback (most recent call last):
  File "main.py", line 317, in sse_loop
    data = json.loads(evt.data)
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)

I’ve got also errors in openhab.log (OH3):

2021-01-06 09:55:49,148 Setting OH: ac_Ouderkamer_turbo_mode (turbo_mode) = OFF
2021-01-06 09:55:49.151 [ERROR] [rg.apache.cxf.jaxrs.utils.JAXRSUtils] - No message body reader has been found for class java.lang.String, ContentType: application/octet-stream
2021-01-06 09:55:49.151 [WARN ] [s.impl.WebApplicationExceptionMapper] - javax.ws.rs.WebApplicationException: HTTP 415 Unsupported Media Type
	at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1382)
	at org.apache.cxf.jaxrs.utils.JAXRSUtils.processRequestBodyParameter(JAXRSUtils.java:877)
	at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:822)
	at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:214)
	at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:78)
	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
	at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
	at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:267)
	at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)
	at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)
	at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)
	at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:216)
	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:301)
	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPut(AbstractHTTPServlet.java:237)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:276)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:852)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:544)
	at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:536)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1581)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1307)
	at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:293)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:482)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1549)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1204)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
	at org.eclipse.jetty.server.Server.handle(Server.java:494)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:374)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:268)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129)
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:367)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:782)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:918)
	at java.base/java.lang.Thread.run(Thread.java:834)


What version of python are you using? I’m currently on 3.8.
I’m also running OH3, not sure if that has an impact on the OH_URL?

I am using openhab 2 still for me everything works. (Except there is no audible feedback anymore when changing something)

In main.py, I’ve changed line 141 in main.py to

    response = session.put(url, data=value, headers={'Content-type': 'text/plain'})

Functions seem to be working:

  1. When I put a unit ON, with the next run, my OH items are being updated.
  2. And when I put an OH item ON, the unit reacts direct (2 sec delay).
  3. When target-temperature is changed, this is nicely updated in OH.

I’m missing the update of the indoor_temperature. That part isn’t working for the moment. Looks like just one update with start?

Sometimes, I’m still having following error. But not so often as before. Looks like it’s not every run anymore.

Exception in sse_loop: JSONDecodeError('Expecting value: line 1 column 1 (char 0)')
2021-01-07 16:52:35,012 Failure in sse_loop
Traceback (most recent call last):
  File "main.py", line 317, in sse_loop
    data = json.loads(evt.data)
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Glad you have found a solution to make it work with OH 3.0, will switch to it soon as well… Once I got the time to do it.

Will check later if indor temperature is updating for me when using it on oh 2.5

Any idea to get the “beep” sound back ?

The outdoor temperature has been updated 346 in the last 12 hours (of course, I’m having 4 inside units, so 80x / 12 hour?). The inside temperature is updated 36? So 9x / 12 hour?

Maybe a ‘small’ details, degrees seem to be only measure with 0,5 degrees difference? So maybe it’s normal that these temperatures aren’t so often updated as fe a KNX or zwave sensor?
Any idea if this is build in the hvac units, or if it’s something in the script?

I’ll check later on if I have a beeping sound when I change something…

Hello guys!
Could somebody write a short Howto for installing and configuring LAN version on Raspberry pi?
I have RPi 3B+ with Openhabian (OH3).
I dont want to break installation…

I don’t have the midea k02 wifi Key, i found this git : GitHub - Links2004/arduinoMideaAC: hack job for decoding and sending Midea AC Serial commands
With a custom esp8266, i ordered everything and I will give it a try.
Somebody did something similar?

If you are interested, everything work great with an ESP32 : [Tutorial] Connect your dumb Midea AC Unit to Openhab with MQTT

1 Like

New OH3 Binding - Midea Air Conditioning (LAN)

1 Like