Sonoff RF Bridge with ESPHOME?

They only trigger when the magnet gets separated from the reed switch, but nothing when they are brought together again. This means that the system will be able to detect that the door was opened but… was it closed? No way to know, since there is no transmission on closing.

This renders them useless for anything else than an intrusion alert.

Hello again,

I figured this out.
I simply use the on_rc_switch event under the remote_receiver section as follows:

remote_receiver:
  pin: 
    number: 4
    inverted: false
  dump: rc_switch
  tolerance: 50
  filter: 4us
  idle: 4ms
  
  on_rc_switch:
    then: 
      text_sensor.template.publish:
        id: rf_code
        state: !lambda |- 
          char bin_buffer[33];
          itoa(x.code,bin_buffer,2);
          return bin_buffer;

And this works perfect.
I moved at the binary sensor code to automations in HA and the result is much more reliable.

Let me know if any body interested, I can share more details and code :slight_smile:

1 Like

it interests me very much. share))

Hi @lordzid ,

I’ll be happy to share and help you through your project as much as I can.

First, I’ll start by summarizing my case to align what background and intended outcome.

Usage:
I am using a Sonoff RF bridge with esphome and Portisch firmware.
I am using it to catch events from my open/Close, motion and smoke sensors and save the status in binary sensors. These sensors are available in HA and I use these to have an updated state of all my sensors and use it for automations etc. (I have more than 20 sensors)
I also use the RF bridge to send RF signals controlling my alarm system.

Problem
The logic was fine, but I guess due to the amount of code, the bridge lost often network connectivity and its binary sensors and switches got unavailable, events could then be missed while unavailable and the status of these in my HA was unreliable.

Solution
I wanted to move most of the logic out of the bridge and instead do the logic in HA which has mush more processing power.

These are the steps I did:

  1. in HA create Input_boolean for each of my sensors to hold the state of the sensor. Example: input_boolean.alarm_sensor_window_1

  2. In the bridge save the latest received rc RF code in at text sensor “Latest_Code” which is available from HA.
    Here is the relevant ESPHome code for the rf bridge

remote_receiver:
  pin: 
    number: 4
    inverted: false
  dump: rc_switch
  tolerance: 50
  filter: 4us
  idle: 4ms
  
  on_rc_switch:
    then: 
      text_sensor.template.publish:
        id: rf_code
        state: !lambda |- 
          char bin_buffer[33];
          itoa(x.code,bin_buffer,2);
          return bin_buffer;
...
text_sensor:
  - platform: template
    name: "Latest Code"
    id: rf_code

this is available in HA as sensor.latest_code

Note that this might change rapidly and for one senor can record various signals but no problem with that as it also catches the right code at least once, so we can do automations based on these codes we want to watch for.

  1. In HA define the RF codes representing your sensors and you are interested in doing automations when these are received by the bridge. I use home assistant variables ( HACS component) to store these constants. You could also use input_text, but the variables are more conveniant to maintain in one file.
sensor_openclose1_open:  #Window1
  initial_value: '100101011111001000001010' 
sensor_openclose1_close:
  initial_value: '100101011111001000001110' 

  1. Make automations based on changes in sensor.latest_code
    You need to create an automation for each code. If you have many of these it is recommended to create a blueprint with the common logic and this is what I did:
blueprint:
  name: update sensor state when rf code received
  domain: automation
  input:
    sensor_name:
      name: sensor name 
      selector:
        entity:
          domain: input_boolean
    on_code:
      name: on code 
      selector:
        entity:
          domain: var
    off_code:
      name: off code 
      selector:
        entity:
          domain: var
variables:
  sensor_on_code: !input on_code
  sensor_off_code: !input off_code
trigger: 
  - platform: state
    entity_id: sensor.latest_code
condition:
 - condition: or
   conditions:
    - condition: template
      value_template: '{{ is_state(''sensor.latest_code'', states(sensor_on_code)) }}'
    - condition: template
      value_template: '{{ is_state(''sensor.latest_code'', states(sensor_off_code)) }}'
action:
- choose:
  - conditions: 
    - condition: template
      value_template: '{{ is_state(''sensor.latest_code'', states(sensor_on_code)) }}'
    sequence:
    - service: input_boolean.turn_on
      target:
        entity_id: !input sensor_name
  - conditions: 
    - condition: template
      value_template: '{{ is_state(''sensor.latest_code'', states(sensor_off_code)) }}'
    sequence:
    - service: input_boolean.turn_off
      target:
        entity_id: !input sensor_name
  default: []
mode: single

Based on this blueprint I create an automation for each my sensors by simply selecting which code (Saved as a variable) will set my senor (represented by input_boolean) to on and off, as follows:

alias: alarm sensor window1 open
description: ''
use_blueprint:
  path: homeassistant/update_sensor_state_when_rf_code_received.yaml
  input:
    sensor_name: input_boolean.alarm_sensor_window_1
    on_code: var.sensor_openclose1_open
    off_code: var.sensor_openclose1_close

And that is it :slight_smile:

It is very stable, the bridge don’t loose network connectivity and catches all codes and that’s all what I need.

I hope this gives you an Idea of what I did, and please don’t hesitate to ask if you have any question, I’d love to help.

5 Likes

Can I please have some help from people who have flashed the Portisch firmware?

The Tasmota docs have a reasonable guide but I’d like to confirm:

  1. I have ESPHome on my Sonoff RF R2 V1.0. Do I need to re-flash with Tamota in order to flash the EFM8BB1 firmware, and when done flash back to ESPHome?
  2. During EFM8BB1 flashing I can power the Sonoff via the 3.3V header from a USB-to-serial adapter. Do I need to cut the USB power traces on the board, or is that only if powering via the USB plug?
  3. The wiring ( GPIO4 to C2D and GPIO5 to C2Ck) is only in place during EFM8BB1 flashing and must be removed afterwards, correct?

Thanks a lot for the help.

I did this a few weeks ago. Definitely use Tasmota to flash Portisch hex firmware file, THEN load ESPHome to work with it. Also, there are later patched/updated versions of the Portisch firmware, check for them. I cannot access GitHub from work, or I’d provide a link. I believe it’s titled “Alternative Firmware” on the Portisch GitHub page.

1 Like

Thanks @FredTheFrog. It seems I’ve successfully flashed Portisch.

Used the latest 20190220 firmware from Tasmota/tools/fw_SonoffRfBridge_efm8bb1 at master · arendst/Tasmota · GitHub . I couldn’t find any newer or alternate versions.

Followed the Tasmota wiki. In answer to my own questions:

  1. Yes, as @FredTheFrog said, you need Tasmota to flash Portisch.
  2. You don’t need to cut the USB power lines if you power via 3.3V header and not the USB port.
  3. Yes, the wiring is only needed during flashing and should be removed afterwards.

Still running Tasmota but can now read and send the commands from my curtain/blind controls which I couldn’t previously. They seem to be rebranded Dooya.

Next step is to re-flash upload ESPHome (OTA firmware update from the Tasmota interface) and get it all setup!

1 Like

Hie, I’m on the same setup (original fw on RF chip)
My DW2-RF’s aren’t sending codes to the Bridge with ESPhome flashed on it. All my other remotes/PIR’s are sending codes properly.

Did you get your DW2-RF’s working?

Hi, I am trying to set up motion sensors on my rf bridge with esphome. Can you share your config?

I am getting there.
I am using the rf_bridge component and trying to set up the motion sensors as template sensors. here is the relevant part of my yaml

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

  - platform: template
    name: "Motion Sensor"
    id: motion_1 #Received RFBridge Code: sync=0x3160 low=0x019A high=0x04CE code=0x91EE96
    device_class: motion


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 == 0x91EE96E;
          then:
            - binary_sensor.template.publish:
                id: motion_1
                state: ON

The motion sensor is showing up but it does not trigger when the code is received. Any ideas what I am doing wrong? Is there anyway that i can debug the code?

I found the problem with the code above. I added an E to the code. I deleted it and it works now.

So cool.

About 2 years later, and I could pretty much follow the process as it :slight_smile:

Two things tho :

First, the link to the code is broken. new link : Sonoff RF Bridge | ESPHome-Devices

Second I had to add a filters to make my button useful. Otherwise they would send 5 to 20 “on; off” messages.

So my sensor looks like :

- platform: remote_receiver
    name: "Gray 1"
    rc_switch_raw:
      code: 'code for the switch'
      protocol: 1
    filters: 
      - delayed_off: 1000ms

Works awesome.

2 Likes

did you manage to get the RAW codes? I get a lot of flood with my receiver and I have no clue which one represents the remote

So better get a decent superheterodyn receiver which have very little noise :signal_strength:

1 Like

I just bought a module for esp, do you have any link for that one?

1 Like

Probably the one nobody should buy?

As a reference for good receivers (includes the you can use this site here: RFLink Gateway - HomeAutomation (need to scroll down :point_down:)

Receivers and Transmitters:
Various receivers/transmitters/transceivers have been tested.
For best results use one of the following receivers:
Like “Aurel”, “Super Heterodyne”, “RXB6” and “SYN480R”
[…]

IMPORTANT NOTE about the well-known cheap Chinese set:
[…] The receiver is not working very well. In most cases it receives too much noise to give stable results. […]
image

1 Like

Yes, I bought the Chinese set LOL. I’ll check that link, thanks!

1 Like

What was the original code and what did you add/change? The pastebin link doesn’t work anymore…

@cs007 Did you resolve this?

It still seems to alternate between on/off/unavailable for me. Not sure if something changed in the meantime.