Merge branch 'develop' into patch-1

This commit is contained in:
Geoff Davis 2023-06-15 17:08:19 -07:00 committed by GitHub
commit 430817ee3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 159 additions and 34 deletions

125
README.md
View File

@ -113,6 +113,8 @@ climate:
update_interval: 500ms
```
#### ESP8266 platforms
On ESP8266 you'll need to disable logging to serial because it conflicts with
the heatpump UART:
@ -121,10 +123,14 @@ logger:
baud_rate: 0
```
#### ESP32 platforms
On ESP32 you can change `hardware_uart` to `UART1` or `UART2` and keep logging
enabled on the main serial port. This may require specifying baud_rate on some
enabled on the main serial port. This may require specifying `baud_rate` on some
ESP32 boards.
#### UART Notes
*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
@ -133,13 +139,15 @@ 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.
# Example configuration
# Example configurations
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`.
## ESP8266 Example Configuration
```yaml
substitutions:
name: hptest
@ -231,6 +239,91 @@ climate:
baud_rate: 4800
```
## 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
```
# Advanced configuration
Some models of heat pump require different baud rates or don't support all
@ -243,10 +336,13 @@ climate:
name: "My heat pump"
hardware_uart: UART2
baud_rate: 9600
rx_pin: 9
tx_pin: 10
supports:
mode: [HEAT_COOL, COOL, HEAT, FAN_ONLY]
fan_mode: [AUTO, LOW, MEDIUM, HIGH]
swing_mode: [OFF, VERTICAL]
mode: ["HEAT_COOL", "COOL", "HEAT", "FAN_ONLY"]
fan_mode: ["AUTO", "LOW", "MEDIUM", "HIGH"]
swing_mode: ["OFF", "VERTICAL"]
visual:
min_temperature: 16
max_temperature: 31
@ -262,17 +358,20 @@ climate:
HeatPump. Most systems use the default value of `4800` baud, but some use
`2400` or `9600`. Some ESP32 boards will require the baud_rate setting if
hardware_uart is specified. Default: `4800`.
* *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).
* *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
* *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']`
* *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']`
## Other configuration

View File

@ -6,6 +6,8 @@ from esphome.const import (
CONF_ID,
CONF_HARDWARE_UART,
CONF_BAUD_RATE,
CONF_RX_PIN,
CONF_TX_PIN,
CONF_UPDATE_INTERVAL,
CONF_MODE,
CONF_FAN_MODE,
@ -41,6 +43,8 @@ CONFIG_SCHEMA = climate.CLIMATE_SCHEMA.extend(
cv.GenerateID(): cv.declare_id(MitsubishiHeatPump),
cv.Optional(CONF_HARDWARE_UART, default="UART0"): valid_uart,
cv.Optional(CONF_BAUD_RATE): cv.positive_int,
cv.Optional(CONF_RX_PIN): cv.positive_int,
cv.Optional(CONF_TX_PIN): cv.positive_int,
# If polling interval is greater than 9 seconds, the HeatPump library
# reconnects, but doesn't then follow up with our data request.
cv.Optional(CONF_UPDATE_INTERVAL, default="500ms"): cv.All(
@ -69,6 +73,12 @@ def to_code(config):
if CONF_BAUD_RATE in config:
cg.add(var.set_baud_rate(config[CONF_BAUD_RATE]))
if CONF_RX_PIN in config:
cg.add(var.set_rx_pin(config[CONF_RX_PIN]))
if CONF_TX_PIN in config:
cg.add(var.set_tx_pin(config[CONF_TX_PIN]))
supports = config[CONF_SUPPORTS]
traits = var.config_traits()

View File

@ -53,6 +53,11 @@ void MitsubishiHeatPump::check_logger_conflict_() {
#endif
}
void MitsubishiHeatPump::banner() {
ESP_LOGI(TAG, "ESPHome MitsubishiHeatPump version %s",
ESPMHP_VERSION);
}
void MitsubishiHeatPump::update() {
// This will be called every "update_interval" milliseconds.
//this->dump_config();
@ -68,6 +73,14 @@ void MitsubishiHeatPump::set_baud_rate(int baud) {
this->baud_ = baud;
}
void MitsubishiHeatPump::set_rx_pin(int rx_pin) {
this->rx_pin_ = rx_pin;
}
void MitsubishiHeatPump::set_tx_pin(int tx_pin) {
this->tx_pin_ = tx_pin;
}
/**
* Get our supported traits.
*
@ -451,12 +464,11 @@ void MitsubishiHeatPump::setup() {
"hw_serial(%p) is &Serial(%p)? %s",
this->get_hw_serial_(),
&Serial,
YESNO(this->get_hw_serial_() == &Serial)
YESNO((void *)this->get_hw_serial_() == (void *)&Serial)
);
ESP_LOGCONFIG(TAG, "Calling hp->connect(%p)", this->get_hw_serial_());
if (hp->connect(this->get_hw_serial_(), this->baud_, -1, -1)) {
if (hp->connect(this->get_hw_serial_(), this->baud_, this->rx_pin_, this->tx_pin_)) {
hp->sync();
}
else {

View File

@ -21,7 +21,6 @@
#include "esphome/core/preferences.h"
#include "HeatPump.h"
using namespace esphome;
#ifndef ESPMHP_H
#define ESPMHP_H
@ -41,7 +40,7 @@ static const uint8_t ESPMHP_MAX_TEMPERATURE = 31; // degrees C,
static const float ESPMHP_TEMPERATURE_STEP = 0.5; // temperature setting step,
// in degrees C
class MitsubishiHeatPump : public PollingComponent, public climate::Climate {
class MitsubishiHeatPump : public esphome::PollingComponent, public esphome::climate::Climate {
public:
@ -58,14 +57,17 @@ class MitsubishiHeatPump : public PollingComponent, public climate::Climate {
);
// Print a banner with library information.
void banner() {
ESP_LOGI(TAG, "ESPHome MitsubishiHeatPump version %s",
ESPMHP_VERSION);
}
void banner();
// Set the baud rate. Must be called before setup() to have any effect.
void set_baud_rate(int);
// Set the RX pin. Must be called before setup() to have any effect.
void set_rx_pin(int);
// Set the TX pin. Must be called before setup() to have any effect.
void set_tx_pin(int);
// print the current configuration
void dump_config() override;
@ -82,16 +84,16 @@ class MitsubishiHeatPump : public PollingComponent, public climate::Climate {
void update() override;
// Configure the climate object with traits that we support.
climate::ClimateTraits traits() override;
esphome::climate::ClimateTraits traits() override;
// Get a mutable reference to the traits that we support.
climate::ClimateTraits& config_traits();
esphome::climate::ClimateTraits& config_traits();
// Debugging function to print the object's state.
void dump_state();
// Handle a request from the user to change settings.
void control(const climate::ClimateCall &call) override;
void control(const esphome::climate::ClimateCall &call) override;
// Use the temperature from an external sensor. Use
// set_remote_temp(0) to switch back to the internal sensor.
@ -102,7 +104,7 @@ class MitsubishiHeatPump : public PollingComponent, public climate::Climate {
HeatPump* hp;
// The ClimateTraits supported by this HeatPump.
climate::ClimateTraits traits_;
esphome::climate::ClimateTraits traits_;
// Allow the HeatPump class to use get_hw_serial_
friend class HeatPump;
@ -118,21 +120,23 @@ class MitsubishiHeatPump : public PollingComponent, public climate::Climate {
// various prefs to save mode-specific temperatures, akin to how the IR
// remote works.
ESPPreferenceObject cool_storage;
ESPPreferenceObject heat_storage;
ESPPreferenceObject auto_storage;
esphome::ESPPreferenceObject cool_storage;
esphome::ESPPreferenceObject heat_storage;
esphome::ESPPreferenceObject auto_storage;
optional<float> cool_setpoint;
optional<float> heat_setpoint;
optional<float> auto_setpoint;
esphome::optional<float> cool_setpoint;
esphome::optional<float> heat_setpoint;
esphome::optional<float> auto_setpoint;
static void save(float value, ESPPreferenceObject& storage);
static optional<float> load(ESPPreferenceObject& storage);
static void save(float value, esphome::ESPPreferenceObject& storage);
static esphome::optional<float> load(esphome::ESPPreferenceObject& storage);
private:
// Retrieve the HardwareSerial pointer from friend and subclasses.
HardwareSerial *hw_serial_;
int baud_ = 0;
int rx_pin_ = -1;
int tx_pin_ = -1;
};
#endif