Sonoff RF Bridge with ESPHOME?

Tente assim:

      repeat:
          times: 3
          wait_time: 50ms

Tried the component but it doesnt recognize the rf_bridge within the esphome configuration file.
Maybe they havent implemented it yet into the core code?
Fails validation atm.

Correct, as I mentioned it is intended for release in the next release of ESPHome, however if you use the use ESPHome DEV addon for Home Assistant then you should be able to test the component (note it’s a developer preview so it’s potentially buggy).

ufff… i was busting my brain for hours to figure this out.
Got my second rf bridge today and wanted to test esphome withouth the hardware hack.
I’ll try the dev addon and see how it goes…
thank you.

Ok, my rf modules are arrived. I already have an esp32. I will try this combination as soon as possible next day’s.

Good afternoon, I dont know how to do the indentation for the rf_bridge component, if anyone can help me, I am already using ESPHome (dev)

Sorry, forgot to write that I already tried it a few days ago and the behavior is exactly the same. Now I believe that the other firmware just captures the signal more accurately in the training phase.

Maybe we need to accept that our devices simply have another timing that is actually not captured in the esphome “rc_switch protocol 1”. In this case the only fix is to add an appropriate protocol or fix it using a measurement and appropriate ad-hoc protocol definition. This is the only explanation I see why it works for the initiator of the thread and all the others but not really for us :).

But maybe you have some other insights after you played with it. I’m looking forward. Meanwhile my custom setup works quite reliably (considering the quality of these old RF power plugs I have). Honestly they have a hard time to correctly switch from the original remote (maybe because of switch bouncing effects and poor receivers or whatever). With the rf bridge setup it seems more reliable. Simply cheap stuff, I guess.

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.