2020-03-11 16:36:56 +00:00
# esphome-mitsubishiheatpump
2020-03-11 17:22:35 +00:00
2020-03-11 23:54:51 +00:00
Wirelessly control your Mitsubishi Comfort HVAC equipment with an ESP8266 or
ESP32 using the [ESPHome ](https://esphome.io ) framework.
2020-03-11 17:22:35 +00:00
## Features
* Instant feedback of command changes via RF Remote to HomeAssistant or MQTT.
* Direct control without the remote.
2020-03-11 23:51:01 +00:00
* Uses the [SwiCago/HeatPump ](https://github.com/SwiCago/HeatPump ) Arduino
libary to talk to the unit directly via the internal `CN105` connector.
2020-03-12 06:04:27 +00:00
## Requirements
2020-03-18 14:44:08 +00:00
* https://github.com/SwiCago/HeatPump
2021-06-23 11:53:51 +00:00
* ESPHome 1.19.1 or greater
2020-03-11 17:22:35 +00:00
2020-03-11 22:32:49 +00:00
## Supported Microcontrollers
2020-03-11 23:18:24 +00:00
This library should work on most ESP8266 or ESP32 platforms. It has been tested
with the following MCUs:
2020-03-11 22:32:49 +00:00
* Generic ESP-01S board (ESP8266)
* WeMos D1 Mini (ESP8266)
* Generic ESP32 Dev Kit (ESP32)
## Supported Mitsubishi Climate Units
2020-03-11 23:51:01 +00:00
The underlying HeatPump library works with a number of Mitsubishi HVAC
units. Basically, if the unit has a `CN105` header on the main board, it should
2020-03-11 23:25:00 +00:00
work with this library. The [HeatPump
wiki](https://github.com/SwiCago/HeatPump/wiki/Supported-models) has a more
2020-03-11 23:18:24 +00:00
exhaustive list.
2020-03-11 22:32:49 +00:00
2020-03-11 23:54:51 +00:00
The same `CN105` connector is used by the Mitsubishi KumoCloud remotes, which
have a
2020-03-11 23:51:01 +00:00
[compatibility list ](https://www.mitsubishicomfort.com/kumocloud/compatibility )
available.
2020-03-11 22:32:49 +00:00
The whole integration with this libary and the underlying HeatPump has been
tested by the author on the following units:
2020-03-11 23:25:00 +00:00
* `MSZ-GL06NA`
* `MFZ-KA09NA`
2020-03-11 22:32:49 +00:00
2020-03-11 17:22:35 +00:00
## Usage
2020-03-11 23:51:01 +00:00
### Step 1: Build a control circuit.
Build a control circuit with your MCU as detailed in the [SwiCago/HeatPump
2021-05-02 15:10:45 +00:00
README](https://github.com/SwiCago/HeatPump/blob/master/README.md#demo-circuit).
2020-03-11 22:32:49 +00:00
You can use either an ESP8266 or an ESP32 for this.
2020-03-11 17:22:35 +00:00
2020-03-11 23:54:51 +00:00
Note: several users have reported that they've been able to get away with
2020-03-11 23:51:01 +00:00
not using the pull-up resistors, and just [directly connecting a Wemos D1 mini
to the control
board](https://github.com/SwiCago/HeatPump/issues/13#issuecomment-457897457)
via CN105.
2021-05-26 05:50:57 +00:00
### Step 2: Use ESPHome 1.18.0 or higher
2020-03-12 06:04:27 +00:00
2021-05-26 05:50:57 +00:00
The code in this repository makes use of a number of features in the 1.18.0
2021-05-27 20:34:23 +00:00
version of ESPHome, including various Fan modes and
[external components ](https://esphome.io/components/external_components.html ).
2020-03-12 06:04:27 +00:00
2021-05-26 05:50:57 +00:00
### Step 3: Add this repository as an external component
2020-03-11 22:05:47 +00:00
2021-05-26 05:50:57 +00:00
Add this repository to your ESPHome config:
2020-03-11 22:05:47 +00:00
2021-05-26 05:50:57 +00:00
```yaml
external_components:
- source: github://geoffdavis/esphome-mitsubishiheatpump
```
2021-05-27 20:34:23 +00:00
#### Step 3a: Upgrading from 1.x releases
Version 2.0 and greater of this libary use the ESPHome `external_components`
feature, which is a huge step forward in terms of usability. In order to make
things compile correctly, you will need to:
1. Remove the `libraries` section that imports
`https://github.com/SwiCago/HeatPump` , as this is handled by the
`external_component` section of manifest.
2. Remove the `includes` section that imports `src/esphome-mitsubishiheatpump`
3. Delete the old checkout of this repository under
`src/esphome-mitsubishiheatpump` .
4. Clean your old ESPHome build directories out (3-dot menu, "Clean Build
Files")
5. You may also have to delete the _esphomenodename_ directory that
corresponds with your _esphomenodename.yaml_ configuration file
2022-01-31 03:51:39 +00:00
completely. This directory may exist in your base config directory,
or in `config/.esphome/build` . Testing with ESPHome 0.18.x showed this
to be necessary to get the cached copy of src/esphome-mitsubishiheatpump to
go away entirely, as the "Clean Build Files" isn't as thorough as one would like.
2021-05-27 20:34:23 +00:00
*Note:* Failure to delete the old source directory and remove the `includes`
and `libraries` lines will likely result in compilation errors complaining
about duplicate declarations of `MitsubishiHeatPump::traits()` .
##### Example error
```
Linking /data/bedroom_east_heatpump/.pioenvs/bedroom_east_heatpump/firmware.elf
/root/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /data/bedroom_east_heatpump/.pioenvs/bedroom_east_heatpump/src/esphome/components/mitsubishi_heatpump/espmhp.cpp.o: in function `MitsubishiHeatPump::traits()':
espmhp.cpp:(.text._ZN18MitsubishiHeatPump6traitsEv+0x4): multiple definition of `MitsubishiHeatPump::traits()'; /data/bedroom_east_heatpump/.pioenvs/bedroom_east_heatpump/src/esphome-mitsubishiheatpump/espmhp.cpp.o:espmhp.cpp:(.text._ZN18MitsubishiHeatPump6traitsEv+0x80): first defined here
```
2021-05-26 05:50:57 +00:00
### Step 4: Configure the heatpump
2020-03-11 22:05:47 +00:00
2021-05-26 05:50:57 +00:00
Add a `mitsubishi_heatpump` to your ESPHome config:
2020-03-11 22:05:47 +00:00
2021-05-26 05:50:57 +00:00
```yaml
2021-05-26 22:44:07 +00:00
climate:
- platform: mitsubishi_heatpump
name: "My Heat Pump"
2020-03-11 17:22:35 +00:00
2021-05-26 22:44:07 +00:00
# Optional
hardware_uart: UART0
2023-01-23 18:27:21 +00:00
baud_rate: 4800
2020-03-11 17:22:35 +00:00
2021-05-26 22:44:07 +00:00
# Optional
2021-05-27 17:40:22 +00:00
update_interval: 500ms
2021-05-26 05:50:57 +00:00
```
2020-03-11 23:51:01 +00:00
2023-01-21 19:03:04 +00:00
#### ESP8266 platforms
2021-05-26 05:50:57 +00:00
On ESP8266 you'll need to disable logging to serial because it conflicts with
the heatpump UART:
2020-03-11 23:51:01 +00:00
```yaml
2021-05-26 05:50:57 +00:00
logger:
baud_rate: 0
2020-03-11 23:51:01 +00:00
```
2023-01-21 19:03:04 +00:00
#### ESP32 platforms
2021-05-29 15:12:52 +00:00
On ESP32 you can change `hardware_uart` to `UART1` or `UART2` and keep logging
2023-06-16 00:08:19 +00:00
enabled on the main serial port. This may require specifying `baud_rate` on some
2023-01-23 18:27:21 +00:00
ESP32 boards.
2021-05-26 05:50:57 +00:00
2023-01-21 19:03:04 +00:00
#### UART Notes
2021-05-27 20:34:23 +00:00
*Note:* this component DOES NOT use the ESPHome `uart` component, as it
requires direct access to a hardware UART via the Arduino `HardwareSerial`
class. The Mitsubishi Heatpump units use an atypical serial port setting ("even
parity"). Parity bit support is not implemented in any of the existing
software serial libraries, including the one in ESPHome. There's currently no
way to guarantee access to a hardware UART nor retrieve the `HardwareSerial`
handle from the `uart` component within the ESPHome framework.
2020-03-11 23:54:51 +00:00
2023-01-21 19:03:04 +00:00
# Example configurations
2020-03-11 23:51:01 +00:00
Below is an example configuration which will include wireless strength
indicators and permit over the air updates. You'll need to create a
`secrets.yaml` file inside of your `esphome` directory with entries for the
various items prefixed with `!secret` .
2023-01-21 19:03:04 +00:00
## ESP8266 Example Configuration
2020-03-11 17:22:35 +00:00
```yaml
2021-05-28 20:52:10 +00:00
substitutions:
name: hptest
friendly_name: Test Heatpump
2020-03-11 17:22:35 +00:00
esphome:
2021-05-28 20:52:10 +00:00
name: ${name}
2020-03-11 22:32:49 +00:00
platform: ESP8266
board: esp01_1m
# Boards tested: ESP-01S (ESP8266), Wemos D1 Mini (ESP8266); ESP32 Wifi-DevKit2
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
2021-05-28 20:52:10 +00:00
ssid: "${friendly_name} Fallback Hotspot"
2020-03-11 22:32:49 +00:00
password: !secret fallback_password
2021-05-27 20:34:23 +00:00
# Note: if upgrading from 1.x releases of esphome-mitsubishiheatpump, be sure
# to remove any old entries from the `libraries` and `includes` section.
2021-05-28 20:34:16 +00:00
#libraries:
2021-05-27 20:34:23 +00:00
# Remove reference to SwiCago/HeatPump
2021-05-28 20:34:16 +00:00
#includes:
2021-05-27 20:34:23 +00:00
# Remove reference to src/esphome-mitsubishiheatpump
2020-03-11 22:32:49 +00:00
captive_portal:
2020-03-11 17:22:35 +00:00
# Enable logging
logger:
2020-03-11 22:05:47 +00:00
# ESP8266 only - disable serial port logging, as the HeatPump component
# needs the sole hardware UART on the ESP8266
baud_rate: 0
2020-03-11 17:22:35 +00:00
2020-03-11 22:32:49 +00:00
# Enable Home Assistant API
api:
ota:
# Enable Web server.
web_server:
port: 80
# Sync time with Home Assistant.
time:
- platform: homeassistant
id: homeassistant_time
# Text sensors with general information.
text_sensor:
# Expose ESPHome version as sensor.
- platform: version
2021-05-28 20:52:10 +00:00
name: ${name} ESPHome Version
2020-03-11 22:32:49 +00:00
# Expose WiFi information as sensors.
- platform: wifi_info
ip_address:
2021-05-28 20:52:10 +00:00
name: ${name} IP
2020-03-11 22:32:49 +00:00
ssid:
2021-05-28 20:52:10 +00:00
name: ${name} SSID
2020-03-11 22:32:49 +00:00
bssid:
2021-05-28 20:52:10 +00:00
name: ${name} BSSID
2020-03-11 22:32:49 +00:00
# Sensors with general information.
sensor:
# Uptime sensor.
- platform: uptime
2021-05-28 20:52:10 +00:00
name: ${name} Uptime
2020-03-11 22:32:49 +00:00
# WiFi Signal sensor.
- platform: wifi_signal
2021-05-28 20:52:10 +00:00
name: ${name} WiFi Signal
2020-03-11 22:32:49 +00:00
update_interval: 60s
2021-05-26 05:50:57 +00:00
external_components:
- source: github://geoffdavis/esphome-mitsubishiheatpump
2020-03-11 22:32:49 +00:00
2020-03-11 17:22:35 +00:00
climate:
2021-05-26 22:44:07 +00:00
- platform: mitsubishi_heatpump
2021-05-28 20:52:10 +00:00
name: "${friendly_name}"
2020-03-11 22:32:49 +00:00
2021-05-26 22:44:07 +00:00
# ESP32 only - change UART0 to UART1 or UART2 and remove the
2020-03-11 22:05:47 +00:00
# logging:baud_rate above to allow the built-in UART0 to function for
2023-01-23 18:27:21 +00:00
# logging.
# Some ESP32 boards will require the baud_rate setting if hardware_uart is specified.
2021-05-26 22:44:07 +00:00
hardware_uart: UART0
2023-01-23 18:27:21 +00:00
baud_rate: 4800
2020-03-11 17:22:35 +00:00
```
2020-03-11 22:32:49 +00:00
2023-01-21 19:03:04 +00:00
## ESP32 Example Configuration
```yaml
substitutions:
name: hptest
friendly_name: Test Heatpump
esphome:
name: ${name}
esp32:
board: lolin_s2_mini
variant: ESP32S2
framework:
type: arduino
version: 2.0.3
platform_version: 5.0.0
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "${friendly_name} Fallback Hotspot"
password: !secret fallback_password
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
# Enable Web server.
web_server:
port: 80
# Sync time with Home Assistant.
time:
- platform: homeassistant
id: homeassistant_time
# Text sensors with general information.
text_sensor:
# Expose ESPHome version as sensor.
- platform: version
name: ${name} ESPHome Version
# Expose WiFi information as sensors.
- platform: wifi_info
ip_address:
name: ${name} IP
ssid:
name: ${name} SSID
bssid:
name: ${name} BSSID
# Sensors with general information.
sensor:
# Uptime sensor.
- platform: uptime
name: ${name} Uptime
# WiFi Signal sensor.
- platform: wifi_signal
name: ${name} WiFi Signal
update_interval: 60s
external_components:
- source: github://geoffdavis/esphome-mitsubishiheatpump
climate:
- platform: mitsubishi_heatpump
name: "${friendly_name}"
# ESP32 only - change UART0 to UART1 or UART2 and remove the
# logging:baud_rate above to allow the built-in UART0 to function for
# logging.
hardware_uart: UART1
```
2021-05-27 20:34:23 +00:00
# Advanced configuration
2021-05-26 09:51:43 +00:00
Some models of heat pump require different baud rates or don't support all
2021-05-27 20:34:23 +00:00
possible modes of operation. You can configure mulitple climate "traits" in
YAML to match what your hardware supports. For example:
2021-05-26 09:51:43 +00:00
```yaml
2021-05-26 22:44:07 +00:00
climate:
- platform: mitsubishi_heatpump
name: "My heat pump"
hardware_uart: UART2
baud_rate: 9600
2023-02-11 09:35:37 +00:00
rx_pin: 9
tx_pin: 10
2021-05-26 22:44:07 +00:00
supports:
2023-02-17 22:25:07 +00:00
mode: ["HEAT_COOL", "COOL", "HEAT", "FAN_ONLY"]
fan_mode: ["AUTO", "LOW", "MEDIUM", "HIGH"]
swing_mode: ["OFF", "VERTICAL"]
2021-05-26 22:44:07 +00:00
visual:
min_temperature: 16
max_temperature: 31
temperature_step: 1.0
2020-03-11 17:22:35 +00:00
```
2020-03-11 22:32:49 +00:00
2021-05-27 20:34:23 +00:00
## Configuration variables that affect this library directly
* *hardware\_uart* (_Optional_): the hardware UART instance to use for
communcation with the heatpump. On ESP8266, only `UART0` is usable. On ESP32,
`UART0` , `UART1` , and `UART2` are all valid choices. Default: `UART0`
2023-07-15 22:03:59 +00:00
* *baud\_rate* (_Optional_): Serial baud rate used to communicate with the
2021-05-27 20:34:23 +00:00
HeatPump. Most systems use the default value of `4800` baud, but some use
2023-07-15 22:03:59 +00:00
`2400` or `9600` . Check [here ](https://github.com/SwiCago/HeatPump/issues/13 )
to find discussion of whether your particular model requires a non-default baud rate.
Some ESP32 boards will require the baud_rate setting if
2023-01-23 18:27:21 +00:00
hardware_uart is specified. Default: `4800` .
2023-02-11 09:35:37 +00:00
* *rx\_pin* (_Optional_): pin number to use as RX for the specified hardware
UART (ESP32 only - ESP8266 hardware UART's pins aren't configurable).
* *tx\_pin* (_Optional_): pin number to use as TX for the specified hardware
UART (ESP32 only - ESP8266 hardware UART's pins aren't configurable).
2021-05-27 20:34:23 +00:00
* *update\_interval* (_Optional_, range: 0ms to 9000ms): How often this
component polls the heatpump hardware, in milliseconds. Maximum usable value
is 9 seconds due to underlying issues with the HeatPump library. Default: 500ms
2023-02-17 22:25:07 +00:00
* *supports* (_Optional_): Supported features for the device.
* *mode* (_Optional_, list): Supported climate modes for the HeatPump. Default:
`['HEAT_COOL', 'COOL', 'HEAT', 'DRY', 'FAN_ONLY']`
* *fan_mode* (_Optional_, list): Supported fan speeds for the HeatPump.
Default: `['AUTO', 'DIFFUSE', 'LOW', 'MEDIUM', 'MIDDLE', 'HIGH']`
* *swing_mode* (_Optional_, list): Supported fan swing modes. Most Mitsubishi
units only support the default. Default: `['OFF', 'VERTICAL']`
2021-05-27 20:34:23 +00:00
## Other configuration
* *id* (_Optional_): used to identify multiple instances, e.g. "denheatpump"
* *name* (_Required_): The name of the climate component, e.g. "Den Heatpump"
* *visual* (_Optional_): The core `Climate` component has several *visual*
options that can be set. See the [Climate
Component](https://esphome.io/components/climate/index.html) documentation for
details.
2021-05-27 22:53:19 +00:00
## Remote temperature
It is possible to use an external temperature sensor to tell the heat pump what
the room temperature is, rather than relying on its internal temperature
2023-07-15 22:14:10 +00:00
sensor. This is helpful if you want to make sure that a particular room, or part
of the room, reaches the desired temperature—rather than just the area near the
heat pump or the thermostat. You can do this by calling `set_remote_temperature(float temp)`
on the `mitsubishi_heatpump` object in a lambda. (If needed, you can call
`set_remote_temperature(0)` to switch back to the internal temperature sensor.)
2021-05-27 22:53:19 +00:00
There are several ways you could make use of this functionality. One is to use
a sensor automation:
```yaml
climate:
- platform: mitsubishi_heatpump
name: "Lounge heat pump"
id: hp
sensor:
2023-07-15 22:14:10 +00:00
# You could use a Bluetooth temperature sensor as the source...
2021-05-27 22:53:19 +00:00
- platform: atc_mithermometer
mac_address: "XX:XX:XX:XX:XX:XX"
temperature:
name: "Lounge temperature"
on_value:
then:
- lambda: 'id(hp).set_remote_temperature(x);'
2023-07-15 22:14:10 +00:00
# ...or you could use a Home Assistant sensor as the source
2021-05-27 22:53:19 +00:00
- platform: homeassistant
name: "Temperature Sensor From Home Assistant"
entity_id: sensor.temperature_sensor
on_value:
then:
- lambda: 'id(hp).set_remote_temperature(x);'
```
2023-07-15 22:14:10 +00:00
One issue that you might have here is that, after some amount of time with no update from the
external temperature sensor, the heat pump will revert back to its internal temperature.
You can prevent this by [adding a `heartbeat` filter ](https://github.com/geoffdavis/esphome-mitsubishiheatpump/issues/31#issuecomment-1207115352 )
to the sensor, which will keep reminding the heat pump of the external sensor value.
2021-05-27 22:53:19 +00:00
2023-07-15 22:14:10 +00:00
Also, if your external sensor is in Fahrenheit, you will have to [convert the value to Celsius ](https://github.com/geoffdavis/esphome-mitsubishiheatpump/issues/31#issuecomment-1207115352 ).
Alternatively, you could define a
2021-05-27 22:53:19 +00:00
[service ](https://www.esphome.io/components/api.html#user-defined-services )
2023-07-15 22:14:10 +00:00
that Home Assistant can call:
2021-05-27 22:53:19 +00:00
```yaml
api:
services:
- service: set_remote_temperature
variables:
temperature: float
then:
- lambda: 'id(hp).set_remote_temperature(temperature);'
- service: use_internal_temperature
then:
- lambda: 'id(hp).set_remote_temperature(0);'
```
2020-03-11 22:32:49 +00:00
# See Also
2020-03-11 23:51:01 +00:00
## Other Implementations
2020-03-11 22:32:49 +00:00
The [gysmo38/mitsubishi2MQTT ](https://github.com/gysmo38/mitsubishi2MQTT )
2021-05-27 20:34:23 +00:00
Arduino sketch also uses the `SwiCago/HeatPump`
library, and works with MQTT directly. The author of this implementation found
`mitsubishi2MQTT` 's WiFi stack to not be particularly robust, but the controls
worked fine. Like this ESPHome repository, `mitsubishi2MQTT` will automatically
register the device in your HomeAssistant instance if you have HA configured to do so.
2020-03-11 22:32:49 +00:00
2020-03-11 23:18:24 +00:00
There's also the built-in to ESPHome
[Mitsubishi ](https://github.com/esphome/esphome/blob/dev/esphome/components/mitsubishi/mitsubishi.h )
2021-04-28 17:35:23 +00:00
climate component.
2020-03-11 22:32:49 +00:00
The big drawback with the built-in component is that it uses Infrared Remote
commands to talk to the Heat Pump. By contrast, the approach used by this
repository and it's underlying `HeatPump` library allows bi-directional
communication with the Mitsubishi system, and can detect when someone changes
the settings via an IR remote.
2020-03-11 23:51:01 +00:00
## Reference documentation
The author referred to the following documentation repeatedly:
2021-05-27 20:34:23 +00:00
* [ESPHome Custom Sensors Reference ](https://esphome.io/components/sensor/custom.html )
* [ESPHome Custom Climate Components Reference ](https://esphome.io/components/climate/custom.html )
* [ESPHome External Components Reference ](https://esphome.io/components/external_components.html )
* [Source for ESPHome's Climate Component ](https://github.com/esphome/esphome/tree/master/esphome/components/climate )