My story with Sonoff RF Bridge and ESPHome.
Intro.
I have a lot of different Sonoff switches (all flashed with ESPHome) and use Home Assistant to control everything. Lights are controlled by Sonoff switches, 1ch, 2ch, 4ch PRO. I tried to use Sonoff Touch to control lights (and as the wall switch), but I don’t have enough wiring going to light switches in the walls to be able to use Sonoff Touch everywhere. My solution was is to use cheap Chinise RF433 wall switches and Sonoff 4ch PRO (with RF). It work perfect! Next goal was to add more wall switches to control bathroom fan (with Sonoff TH10) and to be able to use two or more RF wall switches for one light. I tried to add RF receiver module manually to Sonoff, but without luck - I saw some codes but there was a lot of noise and nothing works (maybe later I will dig in this direction more).
So that is how I got Sonoff RF bridge (R2 v1.0). I did not try it with default firmware, it make no sense for me at all, as I need direct connection to Home Assistant, and I saw, that ESPHome is not fully supports Sonoff RF bridge and some hardware hacking needed, so I started with TASMOTA firmware.
Well, it works with TASMOTA. I connected it through MQTT to Home Assistant, read the codes from RF wall switch, make automation script to turn the lights on switch press. But, it works… slow. There is big delay between button press and HA script reaction after and sometimes it lost fast button pushes. I tried to play with TASMOTA configuration after to reduce this delay but without luck.
I decided to go back and try it with ESPHome, as it never fail. I used this guide to modify RF Bridge: https://github.com/xoseperez/espurna/wiki/Hardware-Itead-Sonoff-RF-Bridge---Direct-Hack
Actually, it was pretty easy to do, even with my poor soldering skills - only add two resistors (I took 200 Ohms 1/8W) and cut three tracks on the board.
Next the firmware and YAML configuration. Short description is here: https://esphome.io/components/binary_sensor/remote_receiver.html
- so I flash ESPHome with proper remote_receiver (& remote_transmitter) setup. Also I used dump: rc_switch in remote_receiver to hide garbage signals in the logs
- read the logs
- press the RF button, got RF signal binary number (and it was exactly the same code as I read with TASMOTA, just not in HEX but in BIN format, ‘1011 1110 1011 1101 0001?’ instead of ‘0BEBD1’)
- write received RF signal number into RF Bridge config to create “remote_receiver” binary sensor
- flash RF Bridge with new config
- add RF Bridge to HA
- make automation script to turn lights when RF Bridge binary sensor become active (receive the signal from button)
- done!
Now it works as any other ESPHome device, RF button turn the lights fast and without fails. The only thing, I had to increase filter value to avoid ghost button presses (cheap button, I know).
Also, I tried to send RF signals with the bridge and no problems:
- read the logs
- press the RF button, got RF signal binary number
- write received RF signal number into RF Bridge config to create “remote_transmitter” switch
- flash RF Bridge with new config
- make automation script to turn on RF Bridge switch, and RF signal will be sent
And final config for Sonoff RF Bridge looks like this:
esphome:
name: sonoff_rf_bridge01
platform: ESP8266
board: esp01_1m
wifi:
ssid: 'xxxxxxxxxx'
password: 'xxxxxxxxxx'
manual_ip:
static_ip: xxx.xxx.xxx.xxx
gateway: xxx.xxx.xxx.xxx
subnet: xxx.xxx.xxx.xxx
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
web_server:
port: 80
binary_sensor:
- platform: status
name: "RF Bridge Status"
- platform: remote_receiver
name: "Remote Input Test L"
rc_switch_raw:
code: '000010111110101111010100'
protocol: 1
- platform: remote_receiver
name: "Remote Input Test R"
rc_switch_raw:
code: '000010111110101111010001'
protocol: 1
- platform: remote_receiver
name: "Remote Input Door Sensor"
rc_switch_raw:
code: '000001101001110011000110'
protocol: 4
remote_receiver:
pin: 4
dump: rc_switch
#filter: 200us
# I found, that smaller values works much better, so...
filter: 4us
idle: 4ms
remote_transmitter:
pin: 5
carrier_duty_percent: 100%
status_led:
pin:
number: GPIO13
inverted: yes
switch:
- platform: remote_transmitter
name: "Remote Fan Control"
rc_switch_raw:
code: '100000000001010000000010'
protocol: 1
repeat: 3