I have been running 2 separate esp32 units for some time, but advice I received in this post on the forum has made me think it might be time to go from 2 to 1 unit.
Here’s the board I am considering using…
The KC868-A4 board seems to have most of the options I need, so should be a good candidate to combine the code below.
Air-Conditioner code…
esphome:
name: esp5-studio-ac
platform: ESP32
board: esp32doit-devkit-v1
on_boot:
- wait_until:
condition: api.connected
- delay: 2s
- script.stop: ac_timer
- climate.control:
id: ac_climate_id
mode: 'off'
- mqtt.publish:
topic: HomeAssistant/Studio/Aircon/Status
payload: "OFF"
# Enable logging
logger:
# level: VERBOSE
# Enable Home Assistant API
api:
reboot_timeout: 0s
ota:
password: !secret esp5-studio-ac-ota
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esp32-Ir-Test Fallback Hotspot"
password: "<REDACTED>"
captive_portal:
status_led:
pin: GPIO2
#Temperature Sensor Pin
dallas:
- pin: 23
update_interval: 30s
mqtt:
# broker: !secret mqtt_broker
broker: !secret mqtt_broker_new
username: !secret mqtt_login
password: !secret mqtt_passwd
port: 1883
reboot_timeout: 0s
keepalive: 60s
discovery: false
# IR TRansmitter entry
remote_transmitter:
pin: GPIO5
id: ir_transmit
carrier_duty_percent: 50%
climate:
- platform: daikin
name: "Aircon Studio"
id: ac_climate_id
supports_heat: false
transmitter_id: ir_transmit
script:
- id: ac_timer
then:
- binary_sensor.template.publish:
id: timer_status
state: ON
- logger.log: "AC Timer is ON"
- delay: 20min
- binary_sensor.template.publish:
id: timer_status
state: OFF
- logger.log: "AC Timer is OFF"
binary_sensor:
- platform: template
id: ac_climate_mgmt
name: "Studio AC Climate"
on_press:
then:
- climate.control:
id: ac_climate_id
mode: COOL
fan_mode: AUTO
target_temperature: 23°C
- mqtt.publish:
topic: HomeAssistant/Studio/Aircon/Status
payload: "ON"
- logger.log: "AC is ON"
on_release:
then:
- climate.control:
id: ac_climate_id
mode: 'off'
- mqtt.publish:
topic: HomeAssistant/Studio/Aircon/Status
payload: "OFF"
- logger.log: "AC is OFF"
- platform: template
id: out_ac_temp_status
- platform: template
id: timer_status
sensor:
# Studio Inside temperature sensor
- platform: dallas
id: in_ac_dallas
resolution: 12
address: 0x2401204FD9433118
name: "Studio AC Inside Temperature"
on_value:
then:
- if:
condition:
# Is the inside temp higher than 24
- lambda: 'return id(in_ac_dallas).state > 24;'
then:
# Open the damper
- binary_sensor.template.publish:
id: ac_climate_mgmt
state: on
- script.execute: ac_timer
- logger.log: "Telling Climate to START"
- if:
condition:
and:
# Is the Outside temp under 18
- lambda: 'return id(out_temp_studio).state < 18;'
# Is the inside temp lower than 23
- lambda: 'return id(in_ac_dallas).state < 23;'
- binary_sensor.is_off: timer_status
then:
- binary_sensor.template.publish:
id: ac_climate_mgmt
state: off
- script.stop: ac_timer
- logger.log: "Telling Climate to STOP"
# Studio Outside Temperature from HA
- platform: homeassistant
id: out_temp_studio
name: "Studio Outside Temperature"
entity_id: sensor.studio_temp_out
And the fresh air cooling code…
esphome:
name: "esp1-studio-climate"
platform: esp32
board: az-delivery-devkit-v4
on_boot:
- lambda: 'id(studio_fan_climate).mode = climate::CLIMATE_MODE_COOL;'
# Enable logging
logger:
# level: VERBOSE
# Enable Home Assistant API
api:
encryption:
key: "<REDACTED>"
ota:
password: "<REDACTED>"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "esp1-studio-climate hot spot"
password: "<REDACTED>"
captive_portal:
# MQTT Interface
mqtt:
# broker: !secret mqtt_broker
broker: !secret mqtt_broker_new
username: !secret mqtt_login
password: !secret mqtt_passwd
port: 1883
reboot_timeout: 0s
keepalive: 60s
discovery: false
on_message:
- topic: esp5-studio-ac/binary_sensor/studio_ac_climate/state
payload: "OFF"
qos: 0
then:
- binary_sensor.template.publish:
id: ac_status
state: off
- logger.log: "The AC is OFF"
- topic: esp5-studio-ac/binary_sensor/studio_ac_climate/state
payload: "ON"
qos: 0
then:
- binary_sensor.template.publish:
id: ac_status
state: on
- logger.log: "The AC is ON"
#Temperature Sensor Pin
dallas:
- pin: 18
update_interval: 30s
#Relay switches
switch:
- platform: gpio
pin:
number: 25
inverted: True
id: studio_damper_sw
name: "Studio Damper Switch"
restore_mode: RESTORE_DEFAULT_OFF
- platform: gpio
pin:
number: 26
inverted: True
id: studio_fan_sw
name: "Studio Fan Switch"
restore_mode: RESTORE_DEFAULT_OFF
# Binary Sensors
binary_sensor:
# AC status
- platform: template
id: ac_status
on_press:
- binary_sensor.template.publish:
id: climate_status
state: off
on_release:
- binary_sensor.template.publish:
id: climate_status
state: on
- platform: template
id: climate_status
on_press:
- climate.control:
id: studio_fan_climate
mode: 'cool'
- switch.turn_on: studio_damper_sw
on_release:
- climate.control:
id: studio_fan_climate
mode: 'off'
- switch.turn_off: studio_damper_sw
# Studio Air Conditioner Status from HA
- platform: homeassistant
id: studio_ac_climate
name: "Studio AC Status from HA"
entity_id: binary_sensor.studio_ac_climate
# Studio Temperature Sensors
sensor:
# Studio DHT Inside Temperature
- platform: dht
pin: 17
model: DHT11
temperature:
name: studio_dht_temp_in
id: studio_dht_temp_in
humidity:
name: studio_dht_hum_in
id: studio_dht_hum_in
update_interval: 30s
# Studio Dallas Inside Temperature
- platform: dallas
name: studio_temp_in
id: studio_temp_in
resolution: 12
address: 0x1101143025227D28
# Studio Outside Temperature
- platform: dallas
name: studio_temp_out
id: studio_temp_out
resolution: 12
address: 0xE602131B13F9AA28
on_value:
then:
- if:
condition:
and:
# Is the outside temp below 18 and the AC off
- binary_sensor.is_off: studio_ac_climate
- lambda: 'return id(studio_temp_out).state < 18;'
then:
# Open the damper
- binary_sensor.template.publish:
id: climate_status
state: on
- mqtt.publish:
topic: HomeAssistant/Studio/Damper/Status
payload: "1"
- logger.log: "The damper and climate is active"
- if:
condition:
or:
# Is the outside temp above 18 or the AC on
- binary_sensor.is_on: ac_status
- lambda: 'return id(studio_temp_out).state > 18;'
then:
- binary_sensor.template.publish:
id: climate_status
state: off
- mqtt.publish:
topic: HomeAssistant/Studio/Damper/Status
payload: "0"
- logger.log: "The damper and climate is off"
climate:
- platform: thermostat
name: "Studio Climate Controller"
sensor: studio_temp_in
min_cooling_off_time: 120s
min_cooling_run_time: 120s
min_idle_time: 30s
id: studio_fan_climate
cool_action:
- switch.turn_on: studio_fan_sw
- logger.log: "The fan is now on"
- mqtt.publish:
topic: HomeAssistant/Studio/Fan/Status
payload: "1"
idle_action:
- switch.turn_off: studio_fan_sw
- logger.log: "The fan is now off"
- mqtt.publish:
topic: HomeAssistant/Studio/Fan/Status
payload: "0"
default_preset: Studio
preset:
- name: Studio
default_target_temperature_high: 22 °C
mode: COOL
My plan was to combine the code in both yaml files, excluding all the unnecessary portions. Please excuse my yaml code… I know it is less than good quality.
I wondered… might there be a better approach… a better way… perhaps using a thermostat, or some other way of combining the two cooling types?
Would be very interested in thinking from the guru’s here… if there’s an easier way to build a single unit that handles climate control via two sources… AC and free cooling.