Sonoff RF Bridge with ESPHOME?

I’ve just copied the example from here RF Bridge Component — ESPHome with the same indentation.

I have now been trying the new rf_bridge integration for a couple of days and wanted to share my experience:

The Sonoff RF Bridge is located in the living room with a RF controlled ceiling fan - approx. 4 metres apart. I have flashed ESPHome using the suggested configuration and I have not modified the hardware. In the log I can see entries like the following when pressing buttons on the remote control:

[D][rf_bridge:041]: Received RFBridge Code: sync=0x4830 low=0x0258 high=0x06E0 code=0xADAF05

I recorded the data for all buttons on the remote control. For the same button I can see that sync, low and high values slightly change, but code is always the same value.

In Home Assistant I have a new service esphome.my_rf_controller_living_room_send_rf_code. I then created the service data payload from the above log entry:

{
  "sync": 0x4830,
  "low": 0x0258,
  "high": 0x06E0,
  "code": 0xADAF05
}

When calling the service I can see in the ESP’s log that the command is received on the RF Bridge, but the ceiling fan doesn’t appear to receive it.

[D][rf_bridge:077]: Sending code: sync=0x4830 low=0x0258 high=0x06E0 code=0xADAF05

Does anyone have this working successfully? Is there any conversion or normalisation of the RF code required?

Looks like the bridge is correctly sending the codes correctly based on what you entered. Is the code the same as what you used before? Potentially try different sync, low, high values, these have some level of variability. Tasmota actually uses default values for this, they are as follows,

  • Sync: 8470
  • Low: 270
  • High: 840

Its not important but these are in decimal microseconds.

1 Like

I tried my codes with the Tasmota sync/low/high values, but still get no response at my ceiling fan.

This is the first time I’m using the RF Bridge - I haven’t used the default firmware nor Tasmota on it.

What config are you guys using to create the first esphome firmware for the device (using the new integration)? I am trying to flash the firmware from Tasmota and I keep getting an error that it’s incompatible

If your ESPHome code otherwise compiles fine and you only get an “ERROR - Not compatible” when trying to flash, then this may help: Migrating to ESPHome from Tasmota - #2 by ab0tj

1 Like

Thanks so much @exxamalte that did the trick and the device is now running ESPHome

My RF bridge (V2 without the hardware hack) is now running ESPHome and I can see RF responses in the console. I copied the same config from the ESPHome site and I’m running ESPHome dev add-on in Home Assistant. My codes appear in the following format:

Received RFBridge Code: sync=0x30E8 low=0x01B8 high=0x04D8 code=0xF4D35E

But I can’t get automations to work at all. I don’t have an esphome service in HA and when I try listening to events I get nothing. What am I missing?

Ok, here is my configuration which gives me 2 services in Home Assistant - learn and send_rf_code. I’m receiving codes, and can use the service to send codes, but either they’re not sent and or not received by my ceiling fan controller.

esphome:
  name: rf_controller
  platform: ESP8266
  board: esp8285

logger:
  baud_rate: 0

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  power_save_mode: none

ota:
  password: !secret ota_password

web_server:

uart:
  tx_pin: GPIO01
  rx_pin: GPIO03
  baud_rate: 19200

api:
  password: !secret api_password
  services:
    - service: send_rf_code
      variables:
        sync: int
        low: int
        high: int
        code: int
      then:
        - rf_bridge.send_code:
            sync: !lambda 'return sync;'
            low: !lambda 'return low;'
            high: !lambda 'return high;'
            code: !lambda 'return code;'
    - service: learn
      then:
        - rf_bridge.learn

rf_bridge:
  on_code_received:
    then:
      - homeassistant.event:
          event: esphome.rf_code_received
          data:
            sync: !lambda 'char buffer [10];return itoa(data.sync,buffer,16);'
            low: !lambda 'char buffer [10];return itoa(data.low,buffer,16);'
            high: !lambda 'char buffer [10];return itoa(data.high,buffer,16);'
            code: !lambda 'char buffer [10];return itoa(data.code,buffer,16);'

binary_sensor:
  - platform: status
    name: "RF Controller Status"
    on_state:
      then:
        - light.toggle: wifi_led
  - platform: gpio
    pin: GPIO00
    name: "RF Controller Pairing Button"

light:
  - platform: binary
    name: "RF Controller WiFi LED"
    id: wifi_led
    output: output_wifi_led
    internal: True

output:
  - platform: gpio
    pin:
      number: GPIO13
      inverted: True
    id: output_wifi_led
1 Like

This is a huge help. Thanks so much @exxamalte

Hi exxamalte, I can confirm that the codes are not even sent.

I want to use my Sonoff RF Bridge (R2 v1.0) with ESPHome to replace a breadboard setup with OpenMQTTGateway. So I can use that setup to verify if any codes are sent by ESPHome and it’s not the case.

I’ve been looking into the code and I see the problem. There is a bug in function send_code which does not correctly transmit all data to the efm8bb1 MCU. If you replace the function with following, it works.

void RFBridgeComponent::send_code(RFBridgeData data) {
  ESP_LOGD(TAG, "Sending code: sync=0x%04X low=0x%04X high=0x%04X code=0x%06X", data.sync, data.low, data.high,
           data.code);
  this->write(RF_CODE_START);
  this->write(RF_CODE_RFOUT);
  this->write((data.sync >> 8) & 0xFF);
  this->write(data.sync & 0xFF);
  this->write((data.low >> 8) & 0xFF);
  this->write(data.low & 0xFF);
  this->write((data.high >> 8) & 0xFF);
  this->write(data.high & 0xFF);
  this->write((data.code >> 16) & 0xFF);
  this->write((data.code >> 8) & 0xFF);
  this->write(data.code & 0xFF);
  this->write(RF_CODE_STOP);
  this->flush();
}

And in the log, you can actually see that the efm8bb1 MCU actually acknowledges a correct action, which wasn’t the case before:

[18:26:06][D][rf_bridge:079]: Sending code: sync=0x125C low=0x0092 high=0x01E0 code=0xFFC554
[18:26:06][D][rf_bridge:024]: Action OK

However, for some reason, my transmit range is super low, about 3-4m line of sight…
Can you or someone else try this as well and see if their range is the same?

I created an issue on Github.

1 Like

Fantastic, that fix worked for me, too. Thanks very much for your help.

I tested this at about 4 metres distance as well as about 12 metres between the RF Bridge and my ceiling fan, and all commands are received fine.

Great to hear! Thanks for checking the range as well.

Good afternoon, sorry for my ignorance but I put this code inside the EspHome code? If so, could you show me how?

I have installed my ESPHome dev environment on macOS and run it from the command line in a virtual environment. If you are doing it in the same way, then here is what you need to do to add the fixed code:

  • In the virtual environment find file lib/python3.7/site-packages/esphome/components/rf_bridge/rf_bridge.cpp
  • In that file find the line void RFBridgeComponent::send_code(RFBridgeData data) {
  • Remove this line and the next 10 lines up until and including the line that contains }
  • Copy above code fix into that file.
  • Clean build directory: esphome your_config.yaml clean
  • Build and upload OTA: esphome your_config.yaml run

Thanks, I will do this

Hi, do you have any idea why the RM433 remote from Sonoff does not work well with Sonoff bridge?
It always generate very different codes, so it’s difficult to create automations.


This is the event automation, and this is the event generated:


But I can’t use reliably sync, low, high.
Is this how it is supposed to work?

sync, low, high are nor reliable to use. That’s inherent to RF433.

Thanks, so I can reliably use just “code”? This was not mentioned anywere, it looked strange to me.

Code is reliable. sync, low, high are dependent on a number of things, including how good the reception was, interference of other RF433 devices that were transmitting at the same time, etc, etc…