Sonoff RF Bridge with ESPHOME?

@filippos, I managed with the Discord group staff to solve our problem follow the code ready you now just rename your variables

https://hastebin.com/raw/qogupijexi

1 Like

Awesome.
Your code works great when sensors send two codes, one for ON and one for OFF.
If sensor sends only one code then the delayed_on_off doesn’t have a real meaning and status remains in a constant ON mode.
Therefore, for one code sensors i changed the code slightly into this:

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);'
      - if:
          condition:
            lambda: |-
              return data.code == 0xCCFFAA;
          then:
            - binary_sensor.template.publish:
                id: door
                state: ON
            - delay: 5s
            - binary_sensor.template.publish:
                id: door
                state: OFF

binary_sensor:
  platform: template
  name: 'Door1'
  id: door
  device_class: door

and it works like a charm. It goes OFF after 5seconds.

4 Likes

@filippos, I used your change for my motion sensor because it sends a single code

1 Like

Hi, i’m looking for a way to trigger an automation in HA when a specific code is read on Sonoff rf bridge with esphome. Tried this but don’t work… Why?

automation:
  trigger:
    platform: event
    event_type: esphome.rf_code_received
      event_data:
      data: 8S24C3  # code read by RF bridge

@gt4020

try this one, just substitute data to code

    trigger:
      - platform: event
        event_type: esphome.rf_code_received
        event_data:
          code: 8S24C3
2 Likes

Works like a charm for me to! Now I am struggling what to do if you have multiple binary sensors? Any suggestions? Can’t seem to get the if statement right: I have 6 doorsensors which all return a code to the sonoff device.

Hi,

I have Sonoff RF-bridge running with ESP Home and Portisch firmware.

I want to monitor/persist the Open/Close state of my door/window sensors and the state of my alarm in HA to add some automation rules and intelligence to my alarm.

The sensors and rf codes are set properly and I do receive event changes in HA some of the time. But these sensors (Binary switches) goes unavailable most of the time. And I loose state changes and I am left with wrong states in HA.

Here are some examples from my esp home code:

  - platform: remote_receiver
    name: Motion Family
    id: motion_family
    device_class: motion
    rc_switch_raw:
      code: '000111101010010101011100'  #1EA55C
      protocol: 2
    filters:
      delayed_off: 400s

  - platform: remote_receiver
    name: "OpenClose5_Opened"
    id: open_close_5_opened
    rc_switch_raw:
      code: '111000001001001100001010'  #E0930A
      protocol: 2
    filters:
      - delayed_off: 5s

  - platform: remote_receiver
    name: "OpenClose5_Closed"
    id: open_close_5_closed
    rc_switch_raw:
      code: '111000001001001100001110'  #E0930E
      protocol: 2
    filters:
      - delayed_off: 5s

I have about 40 of these code blocks (sensors).

I guess I read somewhere the issue is caused by the large amount of code in the RF bridge Esp code. I reduced this to the minimum but no significant difference.

Any idea what I can do?

1 Like

I wanted to share my implementation of this hardware/firmware combo as it appears to be a novel one. Not that I take any credit as it’s a combination of two other ideas. First, I program the rf bridge to trigger HA events whenever it receives a RF code. This is the example code given on the esphome website.

esphome:
  name: rf_bridge_1
  platform: ESP8266 
  board: esp01_1m

wifi:
  ssid: XXXX
  password: XXXX
  
captive_portal:
  
web_server:
  port: 80

ota:

api:
  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

uart:
  tx_pin: 1
  rx_pin: 3
  baud_rate: 19200

logger:
  baud_rate: 0

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);'

sensor:
  - platform: wifi_signal
    name: rf_bridge_1_wifi_signal
    update_interval: 60s
    
switch:
  - platform: restart
    name: rf_bridge_1_restart
    
text_sensor:
  - platform: wifi_info
    ip_address:
      name: rf_bridge_1_ip

Then I use node-red to read these events when they trigger and determine if the code matches any of my sensors. If so, publish to a mqtt topic that HA can read. I do this with three nodes:

  • Home-assistant:events:all - configured to watch for esphome.rf_code_received events
  • Function:python function - configured as per the following code
  • Network:mqtt out - no special configuration; just connected to my broker

The python code does most of the work and is easily updated:

codes = {
    '000X0X':['backdoor','ON'],
    '000X0X':['backdoor','OFF'],
    '0X000X':['garagedoor','ON'],
    '0X000X':['garagedoor','OFF'],
    '00000X':['garagemotion01','ON'],
}

data = msg['payload']['event']['code']

if data in codes.keys():
    msg = {}
    msg['topic'] = 'home/{}/status'.format(codes[data][0])
    msg['payload'] = codes[data][1]
    return msg

Then I configure sensors in home-assistant to listen to the appropriate mqtt topics (ex. home/garagedoor/status)

  - platform: mqtt
    state_topic: "home/backdoor/status"
    name: "Back Door"
    payload_on: 'ON'
    payload_off: 'OFF'
    device_class: door

  - platform: mqtt
    state_topic: "home/garagedoor/status"
    name: "Garage Door"
    payload_on: 'ON'
    payload_off: 'OFF'
    device_class: door

  - platform: mqtt
    state_topic: "home/garagemotion01/status"
    name: "Motion Sensor Garage Indoor"
    payload_on: 'ON'
    payload_off: 'OFF'
    device_class: motion
    off_delay: 2
1 Like

Hey. I did everything according to your instructions. I can accept codes from the remote control. but it doesn’t work. can you help?

esphome:
   name: rf_bridge
   platform: ESP8266
   board: esp01_1m

wifi:
  ssid: "pass"
  password: "pass"
  use_address: 192.168.0.237
  manual_ip:
    static_ip: 192.168.0.237
    gateway: 192.168.0.1
    subnet: 255.255.255.0 

# Enable logging
logger:

web_server:
  port: 80

# Enable Home Assistant API
api:
  password: "apipassword"

ota:
  password: "otapassword"

remote_receiver:
   pin:
     number: 4
   dump:
   - rc_switch
   filter: 50us
   idle: 2ms

remote_transmitter:
  pin: GPIO5
  carrier_duty_percent: 50%


switch:
  - platform: template
    name: RF Power Button
    turn_on_action:
      - remote_transmitter.transmit_rc_switch_raw:
          code: '111111110101111101110001'
          protocol: 1  
  

Same here. Receiver works but not the transmitter.

I have rf bridge hacked.
Finally I managed to transmit protocol 1 rf code.
My settings:

switch:
  - platform: template
    name: "gtstat_01"
    id: "gtstat_01"
    optimistic: true
    assumed_state: true
    turn_on_action:
      remote_transmitter.transmit_rc_switch_raw:
        code: '100010001010101000000001'
        protocol: 
          pulse_length: 320
        repeat:
          times: 10
          wait_time: 0s

Please try it and check if it works.

1 Like

Interesting. I think @andreaslindner 's config work around (Here)
which has been solid for me broke with updating Esphome to 1.16.0, potentially relating to this issue:

Replacing with your settings have fixed it for me.

Thanks!

Been trying to get my sonoff rf bridge to receive and send codes from Zemismart blind remote AC123-06.

Began with Tasmota and portisch but with no success. I could se the binary but did not succeed in keeping the setup, and after reboot of the RF bridge, the “raw.mode” reverted to “standard”

Progressed to ESPhome with this setup:

esphome:
  name: sonoff_rf_bridge
  platform: ESP8266
  board: esp01_1m

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

# Enable logging
logger:
  baud_rate: 0

uart:
  tx_pin: GPIO01
  rx_pin: GPIO03
  baud_rate: 19200

# Enable Home Assistant API
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);'

ota:
  password: !secret ota_password

web_server:
  port: 80

sensor:
  - platform: wifi_signal
    name: Sonoff RF Bridge Wifi Signal
    update_interval: 10s
  - platform: uptime
    name: Sonoff RF Bridge Uptime

binary_sensor:
  - platform: status
    name: Sonoff RF Bridge Status

 
remote_receiver:
  pin: 4
  dump: rc_switch
  tolerance: 50
  filter: 4us
  idle: 4ms

remote_transmitter:
  pin: 5
  carrier_duty_percent: 100%

status_led:
  pin:
    number: GPIO13
    inverted: yes

Have done all the hardware mods, it still receives al the old known signals but now in biniry and not the hex codes so far so good.

But my Zemismart remote omly reads as “00000000”
No matter which button I press I get the same result in the logs:
[remote.rc_switch:256]: Received RCSwitch Raw: protocol=1 data=‘00000000’

Any solution to get the RF bridge to read the Zemismart?

I can’t recall where/when I saw it, but I recall the Sonoff can’t do all rf codecs even with the hardware hack. I ended getting and using a broadlink to learn/send codes for my blinds. I had similar symptoms of “incomplete looking” codes being logged/received. Sonoff RF Bridge with ESPHOME?

Perfect! Thanx a lot
my old settings :

- platform: template
    name: Remote Front Gate Control
    turn_on_action:
      remote_transmitter.transmit_rc_switch_raw:
        code: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
        protocol: 1
        repeat:
          times: 10
          wait_time: 10ms 

Hi guys,

Sorry if it’s a nood question, I’m pretty new to rf433.

i’ve got a sonoff rf bridge modified (cut on the lines, etc …)
I’ve flashed esphome and dumping rf_switch.

Then I’m testing my brand new RM433 remote.
My issue is that the top left button and second line right button give me exactly the same code :

#Press on top-left button
[21:22:51][D][remote.rc_switch:256]: Received RCSwitch Raw: protocol=1 data='011110000100000001001000'
[21:22:51][D][remote.rc_switch:256]: Received RCSwitch Raw: protocol=1 data='011110000100000001001000'

#press on second-right button. 
[21:22:53][D][remote.rc_switch:256]: Received RCSwitch Raw: protocol=1 data='011110000100000001001000'
[21:22:53][D][remote.rc_switch:256]: Received RCSwitch Raw: protocol=1 data='011110000100000001001000'

then I don’t know how to distinguish them on config.
All other buttons have differents codes.

Do you know id I did something wrong ?

Have you tried dumping “all” or “raw” just to make sure ?

As a side node: I don’t understand why by default people assume you have to do the hardware “hack” on the RF Bridge for ESPHome… I use it with Portisch firmware, but I don’t know if I even had to flash that, 'cause all my devices seem to work out of the box.
My recommendation with the RF Bridge would be:

  1. Try it with ESPHome without any modifications
  2. If you have devices that don’t work: try using Portisch firmware for the second chip
  3. If all else fails, do the hardware “hack”, but know you essentially now have an ESP8285 with a generic receiver/transmitter duo.
1 Like

The hardware hack is a bit of an abomination

I’m just getting into this pretty late I guess.

I purchased 11 RF 433 MHz door sensors, and 3 water leak sensors. I put Tasmota on my RF Bridge. Water leak sensors work great, but the door sensors often don’t see when the door goes from open to close (probably once ever 5 times on some doors). I would love for the to work 100% of the time. I often get alerts a door is left open when it is in fact close.

it seems if I put ESPHome on my bridge it would work better, but I kept reading how you have to solder two connections and cut three lines. Not the end of the world, but I would love to test ESPhome first. If I can test it out without doing a hardware hack that would be great.

Could you point me to where I put ESPhome on the RF Bridge without a hack? Thanks.

I don’t think ESPHome will make your RF Bridge work better than with Tasmota.
The reason your door sensors don’t work all the time is probably because if you have 11 a lot of them are probably on the edge of the reach of the RF Bridge. My advice would be to either get 1 or 2 extra RF Bridges or maybe build a custom RF solution with better chips and/or antenna’s…

If you still want to try ESPHome just to try it:

Just make the .bin file and upload it through Tasmota, it supports writing ESPHome firmware directly.