Some quick notes about this:
-
If you aren’t familiar with how breadboards work, the holes are electrically
bonded in different ways to make creating demo circuits easy. On this
breadboard, the two long rows on the outside (bounded by the blue and red
lines) are bonded. In the center part, the columns are bonded.
In my circuit here, I have the 3.3v and the ground on the outside rows (3.3v
on the red, ground on the blue.)
-
The reason for using the 2N2222 transistor as opposed to just wiring up the
ESP32 directly to the IR LED is that the ESP32 doesn’t have enough power to
drive the IR LED directly. Using the transistor amplifies that enough that it
has some reach (though in my testing it still needs to be within about 5 feet
for it to work.)
Configuring ESPHome
Next step is to install esphome:
And create a demo project.
$ esphome office_heater.yaml wizard
This will walk you through some basic steps getting ESPHome created and will
create a YAML file that will look something like this:
esphome:
name: office_heater
platform: ESP32
board: node32s
wifi:
ssid: "Your WIFI"
password: "Your WIFI password"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Office Heater Fallback Hotspot"
password: "kfrWiUnfT0JF"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
You can test this config by pushing it to your board that is connected by USB.
Be aware that on the MELIFE boards that I used I have to put them in firmware
upload mode by:
- Holding the boot button.
- Pushing the EN button.
- Letting go of the boot button after about 1 second.
You push it to your board by doing this:
$ esphome office_heater.yaml run
And you should see your board boot and connect to wifi. Even though it doesn’t
actually do anything right now, it’s up and running.
Reading the IR Signals From The Existing Remote
Next thing we need to do is to figure out what our current remote is sending.
And thankfully, esphome has some built-in functionality to do this. Add this to
your YAML file and re-deploy:
remote_receiver:
pin:
number: GPIO16
inverted: True
dump: all
Deploy it to the board:
$ esphome office_heater.yaml run
And now, point your remote at the receiver and press a button. If everything is
wired correctly, you should see it output the codes it received:
[16:49:49][D][remote.jvc:048]: Received JVC: data=0x007F
[16:49:49][D][remote.lg:053]: Received LG: data=0x007F00FF, nbits=32
[16:49:49][D][remote.nec:068]: Received NEC: address=0x007F, command=0x00FF
[16:49:49][D][remote.raw:041]: Received Raw: 9013, -2281, 610
This is what I recorded when I pushed the power button. So after all the buttons
were pressed, these were the codes I discovered. I am using the LG codes here,
by the way, and nbits
was 32 for all of them:
- Power On/Off:
0x007F00FF
- Frost Protection Mode:
0x007F807F
- Temperature Up:
0x007F40BF
- Temperature Down:
0x007FC03F
So, now that we know what codes we need to send, we just need to send them.
Sending IR Codes
Theoretically, you can use any of these various formats when sending.
Practically I only had luck using the LG ones (which kinda makes sense, LG does
make HVAC systems.) So if you don’t have luck with the first set, try another
code set.
Add the following to your configuration file:
remote_transmitter:
pin: GPIO17
carrier_duty_percent: 50%
switch:
- platform: template
name: Heater Power
optimistic: True
turn_on_action:
- remote_transmitter.transmit_lg:
data: 0x007F00FF
nbits: 32
turn_off_action:
- remote_transmitter.transmit_lg:
data: 0x007F00FF
nbits: 32
Deploy it to the board:
$ esphome office_heater.yaml run
Next, go over to your Home Assistant installation. You should hopefully already
see a notification of a new integration available so click through to that and
install the ESPHome integration. If not, go to the integrations menu in
configuration and manually install it. It should create a switch entity for you.