Skip to content

Instantly share code, notes, and snippets.

@heggi
Last active July 8, 2023 15:32
Show Gist options
  • Select an option

  • Save heggi/32dd4edfd4ea3f737f9399094a2fdd3d to your computer and use it in GitHub Desktop.

Select an option

Save heggi/32dd4edfd4ea3f737f9399094a2fdd3d to your computer and use it in GitHub Desktop.
ESPHome Airgreen Climate IR Remote
#include "esphome.h"
#include "IRremoteESP8266.h"
#include "IRsend.h"
#include "ir_Mirage.h"
const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 0 (D3).
IRMirageAc ac(kIrLed);
class AirgreenClimate : public Component, public Climate {
public:
void setup() override {
ac.begin();
ac.setModel(mirage_ac_remote_model_t::KKG29AC1);
ac.setTemp(27);
ac.setFan(kMirageAcKKG29AC1FanLow);
ac.setSwingH(false);
ac.setSwingV(false);
ac.setOnTimer(0);
ac.setOffTimer(0);
ac.setMode(kMirageAcCool);
ac.setTurbo(false);
ac.setSensorTemp(0);
ac.off();
this->mode = CLIMATE_MODE_OFF;
this->fan_mode = CLIMATE_FAN_LOW;
this->swing_mode = CLIMATE_SWING_OFF;
this->target_temperature = 27;
this->publish_state();
}
void control(const ClimateCall &call) override {
if (call.get_mode().has_value()) {
// User requested mode change
ClimateMode mode = *call.get_mode();
// Send mode to hardware
switch(mode) {
case CLIMATE_MODE_HEAT:
ac.on();
ac.setMode(kMirageAcHeat);
break;
case CLIMATE_MODE_COOL:
ac.on();
ac.setMode(kMirageAcCool);
break;
case CLIMATE_MODE_FAN_ONLY:
ac.on();
ac.setMode(kMirageAcFan);
break;
case CLIMATE_MODE_DRY:
ac.on();
ac.setMode(kMirageAcDry);
break;
case CLIMATE_MODE_OFF:
ac.off();
break;
default:
break;
}
// Publish updated state
this->mode = mode;
this->publish_state();
}
//Code for what to do when the fan speed / mode is changed on the dashboard
if (call.get_fan_mode().has_value()) {
// User requested fan mode change
ClimateFanMode fan_mode = *call.get_fan_mode();
// Send fan mode to hardware
switch(fan_mode) {
case CLIMATE_FAN_AUTO:
ac.setFan(kMirageAcKKG29AC1FanAuto);
break;
case CLIMATE_FAN_LOW:
ac.setFan(kMirageAcKKG29AC1FanLow);
break;
case CLIMATE_FAN_MEDIUM:
ac.setFan(kMirageAcKKG29AC1FanMed);
break;
case CLIMATE_FAN_HIGH:
ac.setFan(kMirageAcKKG29AC1FanHigh);
break;
default:
break;
}
this->fan_mode = fan_mode;
this->publish_state();
}
//Code for what to do when the swing mode is changed on the dashboard
//Check what function is available in the relevant .h file. For example, .setSwingV is the relevant function in ir_Hitachi.h, but it is .setSwingVertical in some others
if (call.get_swing_mode().has_value()) {
// User requested fan mode change
ClimateSwingMode swing_mode = *call.get_swing_mode();
// Send fan mode to hardware
switch (swing_mode) {
case CLIMATE_SWING_OFF:
ac.setSwingV(false);
ac.setSwingH(false);
break;
case CLIMATE_SWING_VERTICAL:
ac.setSwingV(true);
ac.setSwingH(false);
break;
case CLIMATE_SWING_HORIZONTAL:
ac.setSwingV(false);
ac.setSwingH(true);
break;
case CLIMATE_SWING_BOTH:
ac.setSwingV(true);
ac.setSwingH(true);
break;
default:
break;
}
this->swing_mode = swing_mode;
this->publish_state();
}
if (call.get_target_temperature().has_value()) {
// User requested target temperature change
float temp = *call.get_target_temperature();
// Send target temp to climate
ac.setTemp(temp);
this->target_temperature = temp;
this->publish_state();
}
ac.send();
ESP_LOGD("DEBUG", "Home A/C remote is in the following state:");
ESP_LOGD("DEBUG", "%s\n", ac.toString().c_str());
}
ClimateTraits traits() override {
// The capabilities of the climate device
auto traits = climate::ClimateTraits();
traits.set_supports_current_temperature(false);
traits.set_supports_two_point_target_temperature(false);
traits.set_visual_min_temperature(16);
traits.set_visual_max_temperature(30);
traits.set_visual_temperature_step(1);
traits.set_supported_modes({
climate::CLIMATE_MODE_OFF,
climate::CLIMATE_MODE_HEAT,
climate::CLIMATE_MODE_DRY,
climate::CLIMATE_MODE_COOL,
climate::CLIMATE_MODE_FAN_ONLY,
});
traits.set_supported_fan_modes({
climate::CLIMATE_FAN_AUTO,
climate::CLIMATE_FAN_LOW,
climate::CLIMATE_FAN_MEDIUM,
climate::CLIMATE_FAN_HIGH,
});
traits.set_supported_swing_modes({
climate::CLIMATE_SWING_OFF,
climate::CLIMATE_SWING_VERTICAL,
climate::CLIMATE_SWING_HORIZONTAL,
climate::CLIMATE_SWING_BOTH,
});
return traits;
}
};
esphome:
name: esphome-web-xxxxxx
friendly_name: ESPHome AirGreen AC
includes:
- airgreen_climate.h
libraries:
- IRremoteESP8266@^2.8.5
esp8266:
board: d1_mini
# Enable Home Assistant API
api:
encryption:
key: "xxxxxxx"
ota:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esphome-Web-xxxxxxx"
password: "xxxxx"
captive_portal:
### IR TRANSMIT
remote_transmitter:
pin: D2
carrier_duty_percent: 50%
climate:
- platform: custom
lambda: |-
auto airgreen_climate = new AirgreenClimate();
App.register_component(airgreen_climate);
return {airgreen_climate};
climates:
- name: "Living Room AC"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment