First of all, I wanted to thank all of you guys for this great walk-through on setting up a custom ESPHome’s RF Transmitter! Your work helped me to kick-start my own journey.
However, as things are not as easy as they should be, I faced some challenges to make my setup work with ESPHome. So, I wanted to share it with you and everyone else who may stumble upon this topic with a similar problem.
I have a Hampton Bay RF controlled ceiling fan that I wanted to automate using Home Assistant, so I got one of those generic 315 Mhz RF transmitters/receivers from Amazon for hooking it up to an ESP device.
My fan controller is 303.875 Mhz, therefore converting the 315 Mhz RF Transmitter by replacing its “SAW resonator” with the correct one from a spare fan remote would be easier, as all other supporting components on the RF Transmitter board (capacitors, resistors, inductors) would be within the working range for that frequency.
I know I could adapt that spare fan remote and use it directly attached to an ESP to control the fan, but I wanted something compact that would fit inside the junction box behind my control panel tablet. Besides, I wanted to leverage an existing Sonoff Mini R2 which already controls that tablet’s charging outlet. Therefore, I wouldn’t have enough GPIOs to interact with all 5 buttons from the spare fan remote.
Following this topic’s guidance, I used Tasmota to find out each of the remote’s button codes and then converted the Data value to a 12 bits binary (as specified in the Bits value). That was the easy part:
• Light (on/off toggle)
RSL: RESULT = {"Time":"1970-01-01T00:03:09","RfReceived":{"Data":"0x7E","Bits":12,"Protocol":8,"Pulse":350}}
12 Bits binary Data: '000001111110'
• Fan Low
RSL: RESULT = {"Time":"1970-01-01T00:04:41","RfReceived":{"Data":"0x77","Bits":12,"Protocol":8,"Pulse":350}}
12 Bits binary Data: '000001110111
• Fan Med
RSL: RESULT = {"Time":"1970-01-01T00:06:32","RfReceived":{"Data":"0x6F","Bits":12,"Protocol":8,"Pulse":350}}
12 Bits binary Data: '000001101111'
• Fan High
RSL: RESULT = {"Time":"1970-01-01T00:07:32","RfReceived":{"Data":"0x5F","Bits":12,"Protocol":8,"Pulse":350}}
12 Bits binary Data: '000001011111'
• Fan OFF
RSL: RESULT = {"Time":"1970-01-01T00:09:24","RfReceived":{"Data":"0x7D","Bits":12,"Protocol":8,"Pulse":350}}
12 Bits binary Data: '000001111101'
Although Tasmota’s RFSend command worked flawlessly with all of those codes/protocol/pulses using the exact same string between curly braces (after the “RfReceived” tag), ESPHome didn’t work with the binary equivalent Data, Protocol and Pulse.
I tried several combinations of protocol numbers, pulse values and such, but no go… I even tried hooking up the RF Receiver board to an ESP32 with ESPHome this time, to check the remote’s codes again and I was puzzled to see that ESPHome identified the protocol as # 6, instead of # 8 (as Tasmota did):
I also tried using protocol 6, but that obviously didn’t work. Then I decided to take a look at Tasmota’s RCSwitch.cpp source code in a try to figure out what’s their “secret sauce”, as Tasmota, like Steve Jobs used to say during Apple’s golden age, “It just works”.
The magic line number for me in the code was 123, which lists the values for protocol 8.
Apart from that, between lines 57 and 109 you can find a detailed description of protocols format, which was key for making ESPhome work for me.
You can find the pertinent bits summarized below for protocol # 8:
Tasmota RCSwitch.cpp - Protocol description format:
{ Pulse length, PreambleFactor, Preamble {high,low}, HeaderFactor, Header {high,low}, "0" bit {high,low}, "1" bit {high,low}, Inverted Signal, Guard time }
{ 320, 0, { 0, 0 }, 1, { 36, 1 }, { 1, 2 }, { 2, 1 }, true, 0 } // Protocol 08 (Came 12bit, HT12E)
Based on that info, I was able to craft the correct ESPHome configuration for my use case.
In a nutshell, apart from the correct 12 Bit binary Data and Pulse, I also had to add sync, zero, one and inverted parameters into ESPHome’s protocol section to match the values used in Tasmota for protocol 8:
protocol:
pulse_length: 320 # Pulse Length
sync: [36, 1] # Header {high,low}
zero: [1, 2] # "0" bit {high,low}
one: [2, 1] # "1" bit {high,low}
inverted: true # Inverted Signal
repeat:
times: 5
wait_time: 0ms # Guard Time
Further looking into Tasmota’s RCSwitch.cpp source code, I noticed that they retry the transmission 5 times, using the defined Guard time value between transmissions. That resulted in the repeat block as you can see above.
So, if your setup is not working in ESPHome but works with Tasmota, check the protocol details for the correct parameters to be configured in ESPHome. Those are of utmost importance for your success!
I’m sharing below the config for the Hampton Bay 303.875 Mhz Ceiling Fan Controller/Remote (all dip switches on). It’s working flawlessly for me - Hopefully that can be useful for someone else using a similar setup:
switch:
- platform: template
name: "Fan Light"
icon: "mdi:ceiling-fan-light"
optimistic: true
turn_on_action:
remote_transmitter.transmit_rc_switch_raw: # {"Data":"0x7E","Bits":12,"Protocol":8,"Pulse":320}
code: '000001111110' # 07E
protocol:
pulse_length: 320
sync: [36, 1]
zero: [1, 2]
one: [2, 1]
inverted: true
repeat:
times: 5
wait_time: 0ms
turn_off_action:
remote_transmitter.transmit_rc_switch_raw: # {"Data":"0x7E","Bits":12,"Protocol":8,"Pulse":320}
code: '000001111110' # 07E
protocol:
pulse_length: 320
sync: [36, 1]
zero: [1, 2]
one: [2, 1]
inverted: true
repeat:
times: 5
wait_time: 0ms
button:
- platform: template
name: "Fan OFF"
icon: "mdi:fan-off"
on_press:
remote_transmitter.transmit_rc_switch_raw: # {"Data":"0x7D","Bits":12,"Protocol":8,"Pulse":320}
code: '000001111101' # 07D
protocol:
pulse_length: 320
sync: [36, 1]
zero: [1, 2]
one: [2, 1]
inverted: true
repeat:
times: 5
wait_time: 0ms
- platform: template
name: "Fan LOW"
icon: "mdi:fan-speed-1"
on_press:
remote_transmitter.transmit_rc_switch_raw: # {"Data":"0x77","Bits":12,"Protocol":8,"Pulse":320}
code: '000001110111' # 077
protocol:
pulse_length: 320
sync: [36, 1]
zero: [1, 2]
one: [2, 1]
inverted: true
repeat:
times: 5
wait_time: 0ms
- platform: template
name: "Fan MED"
icon: "mdi:fan-speed-2"
on_press:
remote_transmitter.transmit_rc_switch_raw: # {"Data":"0x6F","Bits":12,"Protocol":8,"Pulse":320}
code: '000001101111' # 06F
protocol:
pulse_length: 320
sync: [36, 1]
zero: [1, 2]
one: [2, 1]
inverted: true
repeat:
times: 5
wait_time: 0ms
- platform: template
name: "Fan HIGH"
icon: "mdi:fan-speed-3"
on_press:
remote_transmitter.transmit_rc_switch_raw: # {"Data":"0x5F","Bits":12,"Protocol":8,"Pulse":320}
code: '000001011111' # 05F
protocol:
pulse_length: 320
sync: [36, 1]
zero: [1, 2]
one: [2, 1]
inverted: true
repeat:
times: 5
wait_time: 0ms
Regards,
MCMLXXVII
