Integrating Midea Air Conditioners With Shelly Smart Control Via Rs485 Xye Protocol A Comprehensive Guide

image-20261102-114816.png

Integrate a compatible Midea air conditioner directly with the Shelly ecosystem using the XYE communication interface. This guide covers RS485 wiring, serial configuration, Shelly Script, Virtual Components, local air-conditioner control, and integration with Shelly Smart Control.


Overview

This guide explains how to integrate a compatible Midea air conditioner with Shelly Smart Control using a direct RS485 connection and the Midea XYE communication protocol.

The solution uses:

  • The Pill by Shelly

  • 5-Terminal Add-on for The Pill

  • Modbus RS485 Add-on for The Pill

  • Shelly Script

  • Shelly Virtual Components

  • Shelly Smart Control

The Pill exchanges data directly with the indoor unit over RS485. The solution runs locally without a separate protocol gateway or cloud integration.

Once configured, the integration provides monitoring and control of:

  • Air-conditioner power

  • Operating mode — Auto, Cool, Heat, Dry, and Fan

  • Fan speed — Auto, Low, Medium, and High

  • Target room temperature

  • Current room temperature

  • Communication and operating status

The integration was tested with a Midea MCA4U-18HRFNX(GA) indoor unit using XYE address 0.

Important

Midea XYE uses RS485 for physical communication, but it is not Modbus RTU. The Shelly RS485 Add-on provides the electrical interface, while the Shelly Script implements the Midea XYE protocol through the UART API.

The described connection and protocol behavior were verified on a specific Midea indoor unit. The connector layout and supported commands may differ between models. Always check the documentation for the exact indoor unit before connecting or enabling control.

How the integration works

The local communication path is:

Midea Air Conditioner ↕ RS485 / Midea XYE ↕ Shelly RS485 Add-on ↕ The Pill by Shelly ├── Shelly Script └── Virtual Components ↕ Shelly Smart Control 

The Shelly Script:

  1. Configures the serial interface for XYE communication.

  2. Sends a request to the Midea indoor unit.

  3. Reads the physical operating state of the air conditioner.

  4. Synchronizes the received values with Shelly Virtual Components.

  5. Accepts supported control commands from the Virtual Components.

  6. Sends the corresponding XYE command to the air conditioner.

  7. Reads the physical state again to check the result.

The result is two-way communication between the indoor unit and Shelly Smart Control.

Requirements

Hardware

You need:

  • A compatible Midea indoor unit with an accessible XYE communication interface

  • The Pill by Shelly

  • 5-Terminal Add-on for The Pill

  • Modbus RS485 Add-on for The Pill

  • Suitable RS485 communication cable

  • A power supply suitable for the selected The Pill installation

The Modbus RS485 Add-on is installed together with the 5-Terminal Add-on. The add-on provides the RS485 A and B terminals required for communication with the indoor unit.

Software

Use Shelly firmware that supports:

  • Shelly Scripts

  • Virtual Components

  • The Pill js_uart mode

  • The Serial component and UART scripting API

The js_uart mode is documented for firmware 2.0.1 or later. The reference script is available in the official Shelly script examples repository.

RS485 connection

On the tested Midea installation, the XYE interface is connected through a connector marked:

CN3

The following wiring was used:

Midea CN3

Shelly RS485 Add-on

Description

X

A

RS485 communication line

Y

B

RS485 communication line

E

GND

Communication reference

Midea indoor unit Shelly RS485 Add-on CN3 — X ──────────── A CN3 — Y ──────────── B CN3 — E ──────────── GND 

The connector designation and wiring must be checked against the service documentation for the exact Midea control board. Do not assume that the E terminal is protective earth.

For longer RS485 connections:

  • Use a twisted pair for the A/B communication lines.

  • Keep communication cables away from high-current wiring where possible.

  • Avoid star topology.

  • Apply termination according to the bus topology and equipment documentation.

  • Check the RS485 A/B polarity if communication is not established.

Disconnect power before working inside the air-conditioner electrical compartment. Electrical connections should be made by a qualified technician.

XYE communication configuration

The tested equipment used these settings:

Parameter

Value

Protocol

Midea XYE

Physical interface

RS485

Baud rate

4800

Data bits

8

Parity

None

Stop bits

1

Format

8N1

Midea unit address

0

Shelly UART ID

0

Polling interval

10 seconds

The Pill must be configured for raw UART communication rather than Modbus RTU Client operation.

Set the Pill mode to:

js_uart

This can be done through the device's RPC interface using:

JSON
{ "id": 1, "method": "Pill.SetConfig", "params": { "config": { "mode": "js_uart" } } } 

The script then opens UART 0 and configures the communication parameters:

port = UART.get(0); port.configure({ baud: 4800, format: "8N1" }); port.recv(onData); 

Only one Shelly Script can use UART 0 at a time.

XYE protocol and addressing

The script communicates with the Midea indoor unit using binary XYE frames. It does not use Modbus registers or function codes.

The two main commands are:

Command

Function

Request length

0xC0

Read air-conditioner status

16 bytes

0xC3

Set operating mode, fan speed, and target temperature

16 bytes

The indoor unit returns a 32-byte status frame. The script checks the beginning and ending bytes, checksum, and unit address before processing it.

The address is configured in the script using:

UNIT: 0 

If the indoor unit has a different XYE address, change UNIT to the address configured on that machine. The current script communicates with one selected indoor unit and does not automatically scan multiple addresses.

Data points used by the integration

The script reads the following information from the tested Midea unit:

Function

XYE response byte

Processing

Operating mode

8

Off, Auto, Cool, Heat, Dry, Fan

Fan speed

9

Auto, Low, Medium, High

Target temperature

10

°C

Room temperature (T1)

11

Decoded to °C

Additional temperature (T2A)

12

Decoded internally

Additional temperature (T3)

14

Decoded internally

Compressor status

19

Operating-status field

Error information

22–23

Numeric error value

Protection information

24–25

Numeric protection value

The temperature fields T1, T2A, and T3 use the following conversion:

Temperature °C = (Raw value - 40) / 2 

For example:

84 → 22 °C

The target temperature uses a different encoding and is not converted with this formula.

The current implementation exposes T1 as a Virtual Component. T2A and T3 are read internally but are not displayed as separate Virtual Components.

This table describes the data used by the tested integration. It should not be treated as a universal XYE protocol specification for all Midea products.

Virtual Components

The integration exposes the Midea air conditioner through six Shelly Virtual Components.

Virtual Component

Name

Function

enum:200

AC Mode

Operating mode selection

enum:201

AC Fan

Fan speed selection

number:202

AC Setpoint

Target temperature (16–30 °C)

number:203

AC Room

Current room temperature

text:204

AC Status

Operating and communication status

boolean:205

AC Power

Air-conditioner on/off

Air-conditioner controls

Use these components together for basic air-conditioner control:

AC Power AC Mode AC Fan AC Setpoint 

This provides:

  • Switching the indoor unit on or off

  • Selecting heating, cooling, drying, or fan operation

  • Selecting fan speed

  • Setting the target room temperature

Temperature and status monitoring

Use these two components for monitoring:

AC Room AC Status 

AC Room shows the temperature reported by the Midea indoor unit. AC Status displays a summary of the current operating state and communication diagnostics.

Installing the Shelly Script

Download the Shelly Script

The complete Midea XYE integration script is available in the official Shelly GitHub repository:

Download Midea XYE RS485 Control for The Pill

Open the file on GitHub, select Raw, and copy the complete JavaScript code. Then paste it into a new script on The Pill by Shelly.

Open The Pill and go to:

Scripts → Create script

Create a new script, for example:

Midea XYE

Before starting it, check the configuration section:

JavaScript
let CFG = { ALLOW_WRITE: true, UNIT: 0, BASE: 200, POLL_MS: 10000, REPLY_MS: 400, SET_SETTLE_MS: 1200, TMIN: 16, TMAX: 30, DEBUG: true }; 

BASE determines the IDs used by the six Virtual Components. Check that these IDs are available on the Shelly device.

For the first test, change:

ALLOW_WRITE: false

This allows the communication to be tested without sending control commands to the air conditioner.

Then:

  1. Save the script.

  2. Start the script.

  3. Open the script logs.

  4. Confirm that the air conditioner responds with valid operating data.

  5. Enable ALLOW_WRITE after successful read-only testing.

  6. Enable Run on startup once the installation is verified.

First startup

The script first creates the required Virtual Components and initializes the serial connection.

The startup sequence is:

Start script ↓ Create / configure Virtual Components ↓ Open UART 0 ↓ Send XYE status request ↓ Read Midea operating state ↓ Update Virtual Components ↓ Accept supported control commands 

The script does not send an operating command to the real air conditioner before receiving the first valid status response. This prevents a command from being assembled using only initial default values.

A successful read updates the room temperature, mode, fan speed, setpoint, power state, and status component.

Command verification

When a supported value is changed from Shelly Smart Control, the script sends an XYE control frame to the air conditioner.

The sequence is:

User changes a Virtual Component ↓ Shelly sends XYE command ↓ Midea processes the command ↓ Shelly reads Midea again ↓ Virtual Components are updated 

The XYE write command includes operating mode, fan speed, and target temperature. When one value changes, the script uses the last reported values for the other fields.

After sending a command, the script waits 1.2 seconds and requests the current operating state again. Its verification log checks the returned operating mode and target temperature.

The script does not automatically repeat a command if the returned value differs, and fan-speed verification is not included in the current version. Send commands one at a time, particularly when using automations.

AUTO mode: Reading the AUTO operating state has been tested. The AUTO-mode write value is not yet confirmed on the tested hardware and should be verified on the specific unit before use.

Communication fault handling

If the indoor unit does not respond, the script records a missed reply and displays an offline message in the status component. Polling continues so that communication can resume when the connection is restored.

A communication problem may produce a status such as:

offline, misses 3

The count represents missed replies accumulated during the script run.

The current script retains the last received values in some Virtual Components during a communication outage. It does not automatically mark all values as unavailable or prevent every subsequent write after a previous successful read. For critical applications, add separate communication supervision before using these values in safety-related automation.

Shelly Smart Control

After successful communication, the six Virtual Components can be accessed through the Shelly ecosystem.

They can be used for:

  • Direct air-conditioner control

  • Operating mode and fan-speed selection

  • Temperature adjustment

  • Room-temperature monitoring

  • Operating-status monitoring

  • Scenes and schedules

  • Integration with other Shelly devices

The integration can also be used with the standard Shelly integration in Home Assistant. It exposes the supported components as individual switches, selectors, numbers, and status entities.

Home Assistant is not required for the communication between The Pill and the air conditioner. The script does not create a dedicated Home Assistant climate entity automatically.

Troubleshooting

No communication with the Midea air conditioner

Check:

  • The correct XYE connector on the indoor unit

  • RS485 A/B wiring

  • Communication reference connection, where specified

  • The Midea unit address

  • Baud rate and serial format

  • The Pill js_uart mode

  • Whether another script is using UART 0

  • RS485 termination and cable topology

Tested settings are:

4800 baud 8N1 Unit address 0 

These values must be checked for the specific Midea unit.

RX/TX activity but no valid response

Verify the RS485 A/B polarity, the selected unit address, and the physical connection. Check whether another controller on the bus may be communicating at the same time.

Room temperature is incorrect

The tested T1 temperature field uses:

(Raw value - 40) / 2 °C

For example:

84 → 22 °C

Confirm that the connected Midea model uses the same temperature encoding.

Reading works but control does not

Check that:

  • ALLOW_WRITE is enabled.

  • The first valid status response has been received.

  • The requested operating mode is supported by the unit.

  • The target temperature is between 16 and 30 °C.

  • Another control command is not already in progress.

  • The script logs show the write and subsequent verification.

The Midea controller may reject or change an unsupported request depending on its current operating state.

The script reports NO BUS

Check the Pill operating mode and availability of UART 0. The script can create Virtual Components even when the serial interface is unavailable. Visible controls alone do not confirm a working connection to the air conditioner.

Safety and limitations

This integration communicates with the Midea controller through its digital communication interface. It does not replace or bypass:

  • Compressor protection

  • Temperature protection

  • Equipment safety controls

  • Installer configuration

  • Electrical protection

Before enabling writes:

  1. Confirm XYE compatibility for the exact Midea model.

  2. Confirm the correct communication connector and wiring.

  3. Confirm the unit address and serial communication settings.

  4. Verify that the operating values are read correctly.

  5. Test the supported control commands on the real indoor unit.

The reference script controls one indoor unit address. Automatic control of multiple indoor units and a site-wide interlock allowing only one unit to operate are not implemented in this version.

Do not assume that a working XYE connection on one Midea series guarantees compatibility with another series.

Result

After completing the integration, a compatible Midea air conditioner can be monitored and controlled directly from Shelly Smart Control through a local RS485 connection using the XYE protocol.

The connection can be summarized as:

Midea Air Conditioner ↕ Midea XYE / RS485 ↕ Shelly RS485 Add-on ↕ The Pill by Shelly ↕ Shelly Smart Control 

No external automation server is required for the integration to operate.

The six Virtual Components provide local control of power, operating mode, fan speed, and target temperature, together with room-temperature and status monitoring. These values can also be used in Home Assistant and other compatible local automations.

The same approach may be adapted to other Midea units with compatible XYE communication, after verifying the electrical connection and supported commands for each model.

We Value Your Feedback!

Thank you for taking the time to read our article! Was it helpful or interesting?

Your insights can help us improve. We’d be grateful for any feedback. If you have a moment,

please share it with us at the following email:

Integration@shelly.com