ESPHome YAML

esphome:

  name: ac-dev

  friendly_name: AC Dev

 

esp8266:

  board: d1_mini

  early_pin_init: false

  restore_from_flash: true

 

# Enable logging

logger:

 

# Enable Home Assistant API

api:

  encryption:

    key: "xxx"

 

ota:

  password: "xxx"

 

wifi:

  ssid: !secret wifi_ssid

  password: !secret wifi_password

 

  # Enable fallback hotspot (captive portal) in case wifi connection fails

  ap:

    ssid: "Ac-Dev Fallback Hotspot"

    password: "xxx"

 

captive_portal:

 

status_led:

  pin:

    number: D4

    inverted: true

 

# importing a Home Assistant temp sensor - in my case it's a helper sensor averaging a bunch of other temp sensors together

sensor:

  - platform: homeassistant

    id: temp_sensor

    entity_id: sensor.inside_average_temp

    unit_of_measurement: "°F"

    filters:

      - lambda: return (x-32) * 5/9; #convert to C - all temps seem to be dealt with in C in espHome

 

output:

  - platform: esp8266_pwm #using esp8266 here, be sure to change to "ledc" for esp32

    pin: D2

    id: blower_pwm

    # clamp fan values between 40% and 90% per UndermountAC

    min_power: 0.40

    max_power: 0.90

    zero_means_zero: true # set fan all the way to 0 when off

 

switch:

  # compressor on/off

  - platform: gpio

    id: air_cond

    pin: D1

    internal: true

 

  # compressor high speed on/off

  - platform: gpio

    pin: D3

    id: compressor_speed_high

    inverted: false

    internal: true

    restore_mode: RESTORE_DEFAULT_OFF

 

 

fan:

  - platform: speed

    name: "AC Blower"

    output: blower_pwm

    id: blower_fan

    # using a Speed Fan here so Climate Thermostat can set fan speeds

    # if you set "internal" to "true", the fan is only used internally and will not be exposed to Home Assistant

    # you may want it exposed to HA if you want more granular control of the fan speed

    # (for safety it is already clamped to UndermountAC recommended speeds in the Output)

    internal: false

 

climate:

  - platform: thermostat

    name: "Air Conditioning"

    id: this_thermostat

    sensor: temp_sensor

    visual:

      temperature_step: 1.0

      min_temperature: 65 °F

      max_temperature: 80 °F

 

    # these are short for testing purposes, but should probably be higher

    min_cooling_off_time: 5s # should be "2min" according to UndermountAC

    min_cooling_run_time: 5s # should probably also be "2min" to avoid short cycling

    min_idle_time: 5s # may not really be necessary in a cooling only thermostat and the above settings

   

    # actions for each thermostat state - manage the call for ac, compressor speed, and fan on/of

    cool_action:

      - switch.turn_on: air_cond

      - fan.turn_on: blower_fan

    idle_action:

      - switch.turn_off: air_cond

      - switch.turn_off: compressor_speed_high

      - delay: 10s # delay before turning fan off to push out any final cold air

      - fan.turn_off: blower_fan

    off_mode:

      - switch.turn_off: air_cond

      - switch.turn_off: compressor_speed_high

      - delay: 10s # delay before turning fan off to push out any final cold air

      - fan.turn_off: blower_fan

   

    # turn the compressor to HIGH under these conditions:

    max_cooling_run_time: 20s # when cooling has been running for this long - should probably be a much longer time https://esphome.io/guides/configuration-types#config-time

    supplemental_cooling_delta: 5 # when the delta between target temp and current temp is > than this value (appears to only work in °C)

    supplemental_cooling_action:

      - switch.turn_on: compressor_speed_high

 

    # define presets here to use within HA

    on_boot_restore_from: memory

    # if no memory exists, will default to Standby preset

    default_preset: Standby

    preset:

      - name: Home

        default_target_temperature_high: 75 °F

        fan_mode: AUTO

        mode: cool

      - name: Standby

        default_target_temperature_high: 75 °F

        fan_mode: AUTO

        mode: "OFF"

      - name: Sleep

        default_target_temperature_high: 71 °F

        fan_mode: low

        mode: cool

   

    # fan modes are available in the Climate card in HA Frontend and can be called with "climate.set_fan_mode" in automations

    # these speeds are mapped to the above clamped PWM output values so the fan will never go too low

    min_fan_mode_switching_time: 5s # probably not needed - delays before changing fan speed

    fan_mode_low_action:

      - lambda: |-

          auto call = id(blower_fan).make_call();

          call.set_speed(1);

          call.perform();

         

    fan_mode_medium_action:

      - lambda: |-

          auto call = id(blower_fan).make_call();

          call.set_speed(50);

          call.perform();

 

    fan_mode_high_action:

      - lambda: |-

          auto call = id(blower_fan).make_call();

          call.set_speed(100);

          call.perform();

 

    fan_mode_auto_action:

      # placeholder action - as the fan is dealt with in the "on_state" block below

      - logger.log: "Fan is in Auto"

 

    # when any state change occurs on the Thermostat and the fan is in AUTO, set speed based on delta between target temp and current temp

    on_state:

      lambda: |-

        if (id(this_thermostat).fan_mode == CLIMATE_FAN_AUTO) {

          if ( id(this_thermostat).current_temperature > id(this_thermostat).target_temperature +3 ) {

            auto call = id(blower_fan).make_call();

            call.set_speed(100);

            call.perform();

          }

        else if ( id(this_thermostat).current_temperature > id(this_thermostat).target_temperature +1 ) {

          auto call = id(blower_fan).make_call();

          call.set_speed(50);

          call.perform();

        }

          else {

            auto call = id(blower_fan).make_call();

            call.set_speed(1);

            call.perform();        

          }

        }

 

# there are a ton more config options - https://esphome.io/components/climate/thermostat