Mitsubishi Heavy Industries MHI air conditioning with WF-RAC binding development

I’m going to port Mitsubishi Heavy Industries air conditioning code from HA. Is there a binding template that I could use?

So far I found this:

  1. Bindings | openHAB
  2. Developer Guide | openHAB

Creating skeleton from scratch using maven. Starting point: openhabian:

git clone https://github.com/openhab/openhab-addons.git
$cd openhab-addons/bundles/
./create_openhab_binding_skeleton.sh <BindingIdInCamelCase> <Author> <GitHub Username>

Related topic: MHI (Mitsubishi Heavy Industries) AC control through build in WF-RAC module

Reference code from HA: GitHub - jeatheak/Mitsubishi-WF-RAC-Integration: WF-RAC homeassistant integration
HA topic about MHI WF-RAC: Mitsubishi Wifi Module WF-RAC (Smart M-Air) - Feature Requests - Home Assistant Community

2 Likes

Either create an empty skeleton with the maven script or take a look at the intesis Binding, which was written for intesis/AirConWithMe WiFi adapters used in MHI and several other aircon devices.

1 Like

I know from experience that the Daikin AC binding worked very well: Daikin - Bindings | openHAB

I have not looked at the code, so I cannot comment on suitability from that angle.

1 Like

@bartsnijder I feel you might be interested in this topic :slight_smile:
Nothing to test yet, but I’ll need your help once I have something ready for tests.

Is nagios something that can be leveraged? Those 4 IPs are my MHI AC units with RAC-WF modules. I have the Home Assistant code (using python zeroconf for discovery) and I’m working in that direction as well.

$ nmap -sV 192.168.1.0/24 -p 51443
Starting Nmap 7.93 ( https://nmap.org ) at 2024-03-22 20:24 CET
Nmap scan report for _gateway (192.168.1.2)
Host is up (0.0040s latency).

[..]
Nmap scan report for 192.168.1.110
Host is up (0.053s latency).

PORT      STATE SERVICE     VERSION
51443/tcp open  nagios-nsca Nagios NSCA

Nmap scan report for 192.168.1.111
Host is up (0.079s latency).

PORT      STATE SERVICE     VERSION
51443/tcp open  nagios-nsca Nagios NSCA

Nmap scan report for 192.168.1.112
Host is up (0.014s latency).

PORT      STATE SERVICE     VERSION
51443/tcp open  nagios-nsca Nagios NSCA

Nmap scan report for 192.168.1.113
Host is up (0.048s latency).

PORT      STATE SERVICE     VERSION
51443/tcp open  nagios-nsca Nagios NSCA

[..]
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 256 IP addresses (18 hosts up) scanned in 17.41 seconds

I have discovery working for the RAC-WF :heart_eyes: Thanks for all heavy work done by authors of other bindings, obviously! All I had to do was put together a binding skeleton, copy over Daikin binding (and modify the naming, trim some stuff) and copy over the zeroconf discovery from MPD binding.

I’d appreciate help with naming - are there any rules I should stick to? I tried to use the best guess so the binding name is mhiaircon, but should it be just the brand name? Without the aircon part?

Edit:
Update:

I missed the trigger (space between @ and bartsnijder :-))… Was by accident checking out how this was going. Good to see that there is good progress. Is anything open yet to try?

1 Like

Ohhh… my coding skills are hopefully better than the forum skills. If you like dirty code… Only the discovery works, the rest is just copy from Daikin binding, so obviously not working.
The code is here:

If you need detailed download/compilation/installation instruction let me know.

Edit: Rough guide here: Amending existing binding code - what is the "right" way to install it? - #7 by PrzemoF

1 Like

Hi @PrzemoF

Shout if there’s anything i can help with. I’m not very familiar with openhab addon structure. (Ngl it looks very overwhelming from that gitlabs repo) If there’s specific elements of the home assistant python code you want translated I’m happy to lend a hand where i can.
(I’ll try read up on openhab addon layouts but could be awhile, however happy to help write/translate python to java)

1 Like

Thank you - any help would be fantastic. OH is an elephant, it can be only eaten piece by piece. I don’t understand it as well :slight_smile: despite of amending denon binding and making mhiaircon binding from scratch. I can give you developer access to my gitlab if you want. All the code is here: bundles/org.openhab.binding.mhiaircon · mhi · Przemo Firszt / mhiaircon · GitLab

I can help with setting up the development environment on linux (compilation, ssh for easy copying of the jar, etc but I use vim…).

I’m trying to figure out what should happen after an item has been added. The progress is mediocre - I´m working on many non-OH items as well…

Thanks, my plan is to write it in “plain” java, almost like a library. So make one giant aircon object, store all the data and methods for sending/receiving commands and parsing responses. I’ve got the bulk of this setup using the home assistant python code as a guide for parsing etc.
I’m away from home atm so can’t test but I think it’s pretty much drafted. However it’lll need a fair bit of debuging and some logging/error handling needed.

Then hoping someone on here can lend a hand in how we use this aircon object in openhab/how to map it to openhab.

Current test code is setup something like this:

AirCon aircon = new AirCon();
aircon.setHostname = “192.168.x.x”;
aircon.setPort = “5443”;
aircon.setminRefreshRate = 1L; //max 1s intervals between commands;

//I assume openhab is setup to something like this periodically
aircon.getAirconStats();

//Then I’d want to map openhab channels to specific methods/commands.
ie On/off channel mapped to the below
aircon.setOperation(true);
aircon.send();

Imagine there’s some standard way you guy lock the .getAirconStats periodic run from running when user is updating/before updates have been sent over to external device.

However I’ll get to reading into all that once I’ve tested the “plain” java version. @PrzemoF Once i’ve got it tested on my unit I’ll give you a shout/make my repo public and we can work out how to integrate into openhab.

You’re miles ahead of me in understanding what needs to be done and in writing java. I’m just piggybacking daikin binding and I’m planning to port the already existing python code (HA).

As ugly as one can imagine, but I’m trying to make some progress. bundles/org.openhab.binding.mhiaircon · mhi · Przemo Firszt / mhiaircon · GitLab

I don’t know if it will help any, but there has been a “forum” binding for Midea AC devices. Lately I have been working on it to possibly become “official”. It was also originally derived from python code for HA. You are welcome to review any code that might help your efforts here.

1 Like

@apella12 Thanks! I’ll check that!
I’m at the stage where the basic stuff works: discovery, settings, refresh time. Now the binding is trying to connect the unit on IP and port, but obviously the connection fails as it’s still trying to connect it as it was a Daikin unit.

20:35:27.620 [DEBUG] [hiaircon.internal.MHIairconWebTargets] - getRootCause
20:35:37.838 [TRACE] [internal.handler.MHIairconBaseHandler] - Polling for state
20:35:37.846 [DEBUG] [hiaircon.internal.MHIairconWebTargets] - invoke
20:35:37.853 [DEBUG] [hiaircon.internal.MHIairconWebTargets] - invoke synchronised
20:35:37.861 [DEBUG] [hiaircon.internal.MHIairconWebTargets] - executeUrl
20:35:37.868 [TRACE] [hiaircon.internal.MHIairconWebTargets] - Calling url: http://192.168.1.110/aircon/get_control_info
20:35:38.046 [DEBUG] [hiaircon.internal.MHIairconWebTargets] - HTTP request error on attempt #1: http://192.168.1.110/aircon/get_control_info java.net.ConnectException: Connection refused
20:35:38.555 [DEBUG] [hiaircon.internal.MHIairconWebTargets] - executeUrl
20:35:38.562 [TRACE] [hiaircon.internal.MHIairconWebTargets] - Calling url: http://192.168.1.110/aircon/get_control_info
20:35:38.661 [DEBUG] [hiaircon.internal.MHIairconWebTargets] - HTTP request error on attempt #2: http://192.168.1.110/aircon/get_control_info java.net.ConnectException: Connection refused
20:35:39.668 [DEBUG] [hiaircon.internal.MHIairconWebTargets] - executeUrl
20:35:39.676 [TRACE] [hiaircon.internal.MHIairconWebTargets] - Calling url: http://192.168.1.110/aircon/get_control_info
20:35:39.888 [DEBUG] [hiaircon.internal.MHIairconWebTargets] - HTTP request failed after 3 attempts: http://192.168.1.110/aircon/get_control_info
java.util.concurrent.ExecutionException: java.net.ConnectException: Connection refused

Please do not assess my coding skills by the binding. It’s a mess, trimmed and squashed, sprinkled with debug code. Nothing pretty.

No worries there I have no formal training myself :wink:

Unfortunately, because of this I really can’t jump in and offer anything of value beyond that I do recognize some similar items in the code. I also see some differences that might be deal breakers.

The Midea binding uses a socket to write() a command (like a poll or power ON) and an input stream that collects the bytes sent back by the device. Code extract using IP and Port;

            // Open socket
            try {
                socket = new Socket();
                socket.setSoTimeout(config.getTimeout() * 1000);
                if (ipPort != null) {
                    int port = Integer.parseInt(ipPort);
                    socket.connect(new InetSocketAddress(ipAddress, port), config.getTimeout() * 1000);
                }
            // Create streams
            try {
                writer = new DataOutputStream(socket.getOutputStream());
                inputStream = socket.getInputStream();

Also, the V3 models use encryption so both the write() and read() have code/decode elements. The cloud application(s) for Midea provide the token and key used with the encryption.

Sorry, I can help more.

1 Like

Status:

  1. Discovery works (better than in the Mitsubishi android app :smiley: )
  2. Some limited communication with units, with parsing of the responses into a java structure
  3. HA python parser converted to standalone code + some response string examples
  4. No real information exchange yet, fake online status set
    image
  5. Bunch of parameters in the config
  6. Half-set power channel
    image
    The next step - convert the standalone HA parser code into java and use the values to get real unit stats.
  7. The code is still unworkable for other developers (really messy) as I’m still trimming the Daikin parts and learning how openhab works.

Reading real values from the units:

20:19:41.214 [DEBUG] [hiaircon.internal.MHIairconWebTargets] - getAirconStat org.openhab.binding.mhiaircon.internal.MHIairconWebTargets$Result@16cc73e
20:19:41.221 [DEBUG] [ing.mhiaircon.internal.api.InfoParser] - MHI_AirconStats operation false
20:19:41.223 [DEBUG] [ing.mhiaircon.internal.api.InfoParser] - MHI_AirconStats presetTemp 26.5
20:19:41.225 [DEBUG] [ing.mhiaircon.internal.api.InfoParser] - MHI_AirconStats operationMode 1

Read only mode: power, preset temp, indoor and outdoor temperatures work

15:50:04.575 [TRACE] [ng.mhiaircon.internal.api.ControlInfo] - info.power: false
15:50:04.578 [TRACE] [ng.mhiaircon.internal.api.ControlInfo] - info.presetTemp: Optional[26.0]
15:50:04.581 [TRACE] [ng.mhiaircon.internal.api.ControlInfo] - info.outdoorTemp: Optional[31.2]
15:50:04.584 [TRACE] [ng.mhiaircon.internal.api.ControlInfo] - info.indoorTemp: Optional[28.7]

HA uses a table for temperature conversion, but I decided to use polynomial curves. The significant discrepancies are only around the extreme values, that are probably inaccurate anyway. :nerd_face:

More stuff added, all read only

Wind direction up down and right left readable. Naming consistency to be improved. Due to some weird problems (more here) the development is for now based on 4.1.3 and under name mhiairconditioning Files · mhi-413 · Przemo Firszt / mhiaircon · GitLab