This articles demonstrates a configuration for use with ESPHome and a HUZZAH ESP8266 board that can be used to send commands using RF433Mhz as well as a IR blaster.
Table of Contents
Hardware used:
- HUZZAH ESP8266 Breakout board (underutilised here but at the time I had a few of these laying around from a previous project)
- M5Stack RF UNIT*
- M5Stack IR Blaster UNIT*
- Energenie 4x socket extension (this is what we are automating)
* Note that doesn’t have to be a M5Stack unit specially; but you can often find them very cheap and they are enclosed.
Wiring summary
RF 433Mhz
Connect the M5Stack RF UNIT to the HUZZAH ESP8266 as follows:
- VCC of the RF UNIT to the 3V3 pin on the HUZZAH
- GND of the RF UNIT to GND on the HUZZAH
- DATA (or TX) of the RF UNIT to a GPIO pin (GPIO2 used in this configuration) on the HUZZAH board
IR Blaster
Connect the M5Stack Ir Blaster UNIT to the HUZZAH ESP8266 as follows:
- VCC of the Ir UNIT to the 3V3 pin on the HUZZAH
- GND of the Ir UNIT to GND on the HUZZAH
- TX of the Ir UNIT to a GPIO pin (GPIO4 used in this configuration) on the HUZZAH board
- RX of the Ir UNIT to a GPIO pin (GPIO5 used in this configuration) on the HUZZAH board
Note: you can wire both the RF and IR units to the same 3v3 and ground pins; however this assumes that both units are not intended for use at the same time otherwise you may require additional power. As this is intended as a remote; this is unlikely.
Customisation
In the configuration you will need to change/provide values for:
- Device name, replace
<device-name>
- Secret:
api_key
- Secret:
ota_password
- Secret:
wifi_ssid
- Secret:
wifi_password
- Secret:
ap_password
Preparations for flashing
Compile with ESPHome and the initial deployment will require flashing with a TTL cable rough guide below.
Connect the TTL cable to the Huzzah:
- GND to GND
- TX to RX
- RX to TX
- VCC to 3.3V (if needed)
Flashing the firmware
Put the ESP8266 in to flash mode
- Press and hold GPIO0 button
- Press and release RESET button
- Release GPIO0 button to enter flash mode
Identify the TTL device
Typically dev/ttyACM0 or sometimes /dev/ttyUSB0
ls /dev/tty*
Accessing a tty device may require additional permissions add with (check this appropriate before blindly running):
sudo usermod -a -G dialout $USER
Flash with esptool.py
For example, note the HUZZAH ESP8266
flash size is 4MB:
esptool.py --port /dev/ttyACM0 --baud 115200 write_flash -fm dio -fs 4MB 0x0 /path/yo/your/firmware.bin
YAML Source
substitutions:
id:
name:
friendly_name: Remote
rf_transmit_pin: GPIO2
ir_transmit_pin: GPIO4
ir_receive_pin: GPIO5
esphome:
project:
name: "oddineers.remotes"
version: "0.2.0"
name: ${name}
friendly_name: ${friendly_name}
esp8266:
board: huzzah
# Enable logging
logger:
# Debug require here to view RF receiver codes in logs.
level: DEBUG
# Enable Home Assistant API
api:
encryption:
key: !secret api_key
ota:
- platform: esphome
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# If you don't use .local for your IOT devices change that here
#domain: .local
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: " Fallback Hotspot"
password: !secret ap_password
captive_portal:
remote_transmitter:
- id: rf_mod_tx
pin: ${rf_transmit_pin}
carrier_duty_percent: 100%
- id: ir_mod_tx
pin: ${ir_transmit_pin}
carrier_duty_percent: 50%
remote_receiver:
- id: ir_mod_rx
pin:
number: ${ir_receive_pin}
inverted: true
dump: all
buffer_size: 2kb
switch:
- platform: template
name: "Energenie Combined Socket 3+4"
optimistic: true
assumed_state: true
restore_mode: DISABLED
turn_on_action:
- switch.turn_on: ES0x78b2d_3
#- delay: 400ms
- switch.turn_on: ES0x78b2d_4
turn_off_action:
- switch.turn_off: ES0x78b2d_3
#- delay: 400ms
- switch.turn_off: ES0x78b2d_4
- platform: template
id: ES0x78b2d_1
name: 'Energenie Socket 0x78b2d_1'
optimistic: true
assumed_state: true
restore_mode: DISABLED
turn_on_action:
- remote_transmitter.transmit_rc_switch_raw:
transmitter_id: rf_mod_tx
code: '111100010110010110111110'
protocol:
pulse_length: 200
sync: [1,3]
repeat: 5
turn_off_action:
- remote_transmitter.transmit_rc_switch_raw:
transmitter_id: rf_mod_tx
code: '111100010110010110111100'
protocol:
pulse_length: 200
sync: [1,3]
repeat: 5
- platform: template
id: ES0x78b2d_2
name: 'Energenie Socket 0x78b2d_2'
optimistic: true
assumed_state: true
restore_mode: DISABLED
turn_on_action:
- remote_transmitter.transmit_rc_switch_raw:
transmitter_id: rf_mod_tx
code: '111100010110010110101110'
protocol:
pulse_length: 200
sync: [1,3]
repeat: 5
turn_off_action:
- remote_transmitter.transmit_rc_switch_raw:
transmitter_id: rf_mod_tx
code: '111100010110010110101100'
protocol:
pulse_length: 200
sync: [1,3]
repeat: 5
- platform: template
id: ES0x78b2d_3
name: 'Energenie Socket 0x78b2d_3'
optimistic: true
assumed_state: true
restore_mode: DISABLED
turn_on_action:
- remote_transmitter.transmit_rc_switch_raw:
transmitter_id: rf_mod_tx
code: '111100010110010110110110'
protocol:
pulse_length: 200
sync: [1,3]
repeat: 5
turn_off_action:
- remote_transmitter.transmit_rc_switch_raw:
transmitter_id: rf_mod_tx
code: '111100010110010110110100'
protocol:
pulse_length: 200
sync: [1,3]
repeat: 5
- platform: template
id: ES0x78b2d_4
name: 'Energenie Socket 0x78b2d_4'
optimistic: true
assumed_state: true
restore_mode: DISABLED
turn_on_action:
- remote_transmitter.transmit_rc_switch_raw:
transmitter_id: rf_mod_tx
code: '111100010110010110100110'
protocol:
pulse_length: 200
sync: [1,3]
repeat: 5
turn_off_action:
- remote_transmitter.transmit_rc_switch_raw:
transmitter_id: rf_mod_tx
code: '111100010110010110100100'
protocol:
pulse_length: 200
sync: [1,3]
repeat: 5
- platform: template
id: ES0x78b2d_5
name: 'Energenie Socket 0x78b2d_5 (All)'
optimistic: true
assumed_state: true
restore_mode: DISABLED
turn_on_action:
- remote_transmitter.transmit_rc_switch_raw:
transmitter_id: rf_mod_tx
code: '111100000101100111000110'
protocol:
pulse_length: 200
sync: [1,3]
repeat: 5
turn_off_action:
- remote_transmitter.transmit_rc_switch_raw:
transmitter_id: rf_mod_tx
code: '111100000101100111000100'
protocol:
pulse_length: 200
sync: [1,3]
repeat: 5
button:
- platform: restart
name: ${friendly_name} + " Restart"
- platform: template
name: Example IR Remote Power Button
on_press:
- remote_transmitter.transmit_pronto:
transmitter_id: ir_mod_tx
data: ""