Introduction: ESP Heater Relay

About: Linux System Administrator

Control your Heater with an ESP relay via Home Assistant.

The temperature is read from another Home Assistant sensor, if the remote sensor / HA is not available the internal sensor is used.

Step 1: Needed Components

  1. 220V to 5vdc transformer
  2. Wemos D1 mini ( / pro for better wireless range)
  3. DHT22
  4. 1 Channel relay
  5. Relay box

Step 2: Coonecting the Pieces

From the power source 5v output 3 wires will go to:

  • wemos d1 mini (5v and ground)
  • the relay (5v and ground)
  • dht22 (5v to pin1, gnd to pin 4)

Data pins

  1. relay (d1 mini pin D1 to the IN pin)
  2. dht22 (d1 mini pin D2 to pin 2)

Step 3: The ESPHome Code

esphome:
name: thermicstation-relay
on_boot:
priority: 500
then:
- climate.control:
id: ${location}_thermostat
mode: "HEAT"

esp8266:
board: d1_mini

# Enable logging
logger:


substitutions:
default_temp_low: "15.0"
room: Kitchen
location: "moon"
remote_sensor: "sensor.bme680_temperature"

climate:
- platform: thermostat
min_heating_off_time: 60s
min_heating_run_time: 60s
min_idle_time: 0s
visual:
min_temperature: 15 °C
name: "${location} ${room} Thermostat"
id: ${location}_thermostat
sensor: active_temp

default_mode: heat
default_target_temperature_low: ${default_temp_low}
heat_deadband: 0.3
heat_overrun: 0.3

heat_action:
- switch.turn_on: ${location}_thermicstation_relay

idle_action:
- switch.turn_off: ${location}_thermicstation_relay

switch:
- platform: gpio
name: "${location}-thermicstation-relay"
id: "${location}_thermicstation_relay"
pin:
number: D1

sensor:
- platform: dht
id: "${location}_internal_dht22"
pin: D2
model: DHT22
temperature:
name: "${location} Thermicstation Temperature"
id: "${location}_internal_dht22_temp"
humidity:
name: "${location} Thermicstation Humidity"
id: "internal_dht22_humidity"
update_interval: 60s

- platform: homeassistant
name: "Input Temp From Home Assistant"
id: remote_temp
entity_id: ${remote_sensor}

- platform: template
name: "Active Thermicstation Input Temp"
id: active_temp
lambda: |-
if (isnan(id(remote_temp).state)){
return id(${location}_internal_dht22_temp).state;
} else {
return id(remote_temp).state;
}
update_interval: 60s

# Enable Home Assistant API
api:

ota:
password: "<secret>"

wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
fast_connect: true

# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Thermicstation-Relay"
password: "<secret>"

captive_portal: