Integrating RF devices with sonoff rf bridge on Tasmota Firmware

I use the Tasmota code on a Sonoff RF gateway with good success. Here’s an example that might be helpful for you. I have a 433MHz wireless doorbell, and I’ve defined a switch that toggles when someone presses the doorbell button.

This doorbell button doesn’t have an “off”, just a code when it’s pressed. I have similar things in place for PIR motion detectors that just send a code upon motion detection; their configuration is similar to this example.

input_boolean:
  doorbell_button:
    initial: off

automation:
#  {"RfReceived":{"Sync":6060,"Low":210,"High":610,"Data":"739853","RfKey":"None"}}
  - alias: doorbell button pressed
    initial_state: true
    trigger:
      - platform: mqtt
        topic: "19916/tele/rfbridge/RESULT"
    condition:
      condition: and
      conditions:
        - condition: template
          value_template: '{{ trigger.payload_json.RfReceived.Data == "AC0AC3" }}'
    action:
      - service: input_boolean.turn_on
        data:
          entity_id: input_boolean.doorbell_button
      - delay: '00:00:10'
      - service: input_boolean.turn_off
        data:
          entity_id: input_boolean.doorbell_button

The input_boolean entity is turned on for 10 seconds and then turned off. Note that only the Data element in the JSON payload is significant; the other numbers will vary a little bit as the RF gateway tries to measure the RF signaling, and it doesn’t always get quite the same answer each time. This is why I used the template condition and the specified value_template expression to test just that one field.

Of course, you can then trigger an automation based on the state change of the input_boolean entity. Or even just do stuff in this automation and not bother with the input_boolean at all. My preference is to have this other input_boolean entity around because I can then easily look at the history of that entity and see the times when it’s state has changed recently.

Hi - did you get this working? I believe I’m stuck in the same place.

Hi - I did find a way to send all the command to the Sonoff as a single payload. Instead of sending individual commands, use the BACKLOG command as below:

  - platform: mqtt
      name: "Zap3"
      state_topic: "tele/sonoffrfbr/RESULT"
      command_topic: "cmnd/sonoffrfbr/Backlog"
      qos: 1
      payload_on: "RfSync 5520; RfLow 190; RfHigh 520; RfCode 5265155"
      payload_off: "RfSync 5520; RfLow 190; RfHigh 520; RfCode 5265164"
     retain: false

I was new so hadn’t RTFM properly :stuck_out_tongue:

My current problem is that while I can send all the relvant commands into the backlog, the RF Bridge doesn’t trigger the switch with the code, even though the code and associated data has been learned and assigned to a key that works with a corresponding RfKey command. Still under investigation…

Hi lmamakos, I am using a bit simplier way to restore the state, off state on MQTT sensor is virtual one, payload_off: “1005F0off”"

- alias: Gate bell sensor restart
  trigger:
    - platform: state
      entity_id: binary_sensor.gate_bell
      from: 'off'
      to: 'on'
      for:
        seconds: 1
  action:
    service: mqtt.publish
      data:
        topic: "tele/sonoff/RESULT"
        payload: "1005F0off"

You generate an extra message and network traffic to your MQTT broker, and other received message to process by Home Assistant. You still have a timer running in there, same as me, but mine is inside the action: of the automation, rather than part of the trigger. I’m not sure its necessarily simpler since the logic to control the entity is split in a couple of different places.

In my case, I have one automation to manipulation the state of an input_boolean entity; in your case, you have a template sensor that responds to an MQTT message and an auxiliary automation and traffic to also poke the template sensor again. I think my approach is more “efficient”, though probably doesn’t matter very much in practice…

But potato / potatoe, both get the job done…

I went through this entire thread thinking, “there has got to be a more elegant solution than this ‘off’ MQTT message,” and there is. See this thread here and my code reference at the end.

No automation needed. Simply reset after a timeout. So simple.

Yes, you are right, both get job done. My approach is to simulate standard behavior of switch (On / Off) in case any other control system (not only HA) will require visibility of switch status.

It is good example of HA flexibility…number of ways how you can achieve same results :wink:

Yes, lots of ways to skin the cat.

I just received from Banggood a 433MHz learning remote keyfob device, with 4 buttons. It doesn’t seem to have anything useful programmed into it, so I think I’ll need to poke at the sonoff rf bridge to get it to transmit some random codes for the keyfob to learn.

Then, I’ll have another small device to do… well, I’m not sure what at this point! For $8.00, it seemed like something interesting to try.

I had bought a couple of Z-Wave 4-button remotes that have been handy, but they were cheap at the time, I think, because they were very old inventory with LiPo batteries that didn’t hold a charge real well. It wasn’t hard to desolder the old batteries and replace them with some small batteries I found on ebay, but it’s not really a reproducible solution.

I’m hoping that the little 433MHz keyfob will have enough range to work from the car as its sitting outside the house… That might be a fun application for a more immediate action before the WiFi presence thing sniffs that my phone has come home.

this is exactly my user case. Big house many places with little recepotion, and some non critical switches (I don’t care if somebody sniffs my 433 signal)

Just received my sonoff rf bridge and I flashed it with Tasmota. Tried with a PIR sensor and worked at first try!

Now I am trying to fix the transmitting part. I can program the Bridge for up to 16 433 signals correct? Didn’t find a way to put it in learn mode yet, will investigate.

Just to make sure I understood correctly, a way to integrate it with HASS is the following

For receiving signals (PIR, door sensors and so on)

binary_sensor:
  - platform: mqtt
    name: "Motion sensor"
    payload_on: "FFFFF"   # the code that you see in the Tasmota log when the sensor is activated
    payload_off: "FFFFFoff"
    device_class: motion
    state_topic: "tele/sonoff_bridge/RESULT"
    value_template: '{{ value_json.RfReceived.Data }}'  # Data here?

While for the SENDING part, I am a bit more confused. Did I understand correctly the following:
I can use, for example, a 433 Key, put the Bridge in learn mode and associate the number 1 (for example) to that code. So now if I click the number 1 in tasmota interface or click the switch switch.rf_bridge_key_1_pressed
it will send the 433 signal learned. But that signal is also received? I mean if I want to press the 433 remote key 1, the Bridge will RECEIVE that signal (like it does with a PIR sensor activated), correct?

binary_sensor:
  - platform: mqtt
    name: "RF bridge key 1 pressed"
    payload_on: "1"
    payload_off: "key1_off"
    device_class: switch #?
    state_topic: "tele/sonoff_bridge/RESULT"
    value_template: '{{ value_json.RfReceived.RfKey }}'  # Rfkey here?

Correct?

Or is the other way around: the RF Bridge HAS already the 16 codes, and you put to learn the RF remote with the code from the Sonoff Bridge?

For Pir this is what i have working:

- platform: mqtt
  name: "pir8_mastertoilet"
  state_topic: 'tele/sonoff/rfbridge/RESULT'
  value_template: '{{ value_json["RfReceived"].Data if value_json else "825888OFF" }}' 
  payload_on: "825888"
  payload_off: "825888OFF"
  device_class: motion
  scan_interval: 5
  retain: true 

For sending using the memories what you need to do is bring the device you want to control close to the gateway, put that device in learning mode and then press 1 in the sonoff rfbridge. Test it. if it works go to the console and get the code for your switch

I think I got it.

You can use the default codes by just pressing the number on the Tasmota webui, if you put the remote key on learning mode it will learn that code.
Or you can make the RF Bridge in learn mode and then press a remote key (that is already programmed) next to the RF Bridge (in this case the default code will be lost)

You put the Sonoff RF Bridge in learn mode writing in console
RFkeyx 2 (x can vary from 1 to 16)

Pretty powerful little device

1 Like

If I understand correctly your problem, maybe the issue is that the Bridge does not listen to itself when he is the one sending the RF code

Hello,

For me this is all a kind of new.
I achieved already a lot.
The switches at home are working good but now i am testing with the sonoff bridge with tasmota on it.
What i now want to do os to turn on and off the light what is already working and can be switched on and off by the handy.
I don’t believe i have to create a new switch or not?
Is it a line what needs to be added to this switch so it listen also to the commands from the bridge with the correct data what belongs to the bridge?

This solution is much cleaner than spoofing mqtt messages:

 - platform: mqtt
    name: "Lounge Window"
    payload_on: "5D4533"
    device_class: window
    state_topic: "rf_bridge/tele/RESULT"
    value_template: "{{ value_json.RfReceived.Data }}"
    off_delay: 180

rather than what most people propose in this thread:

- platform: mqtt
    name: "Lounge Window"
    payload_on: "5D4533"
    payload_off: "5D4533off"
    device_class: window
    state_topic: "rf_bridge/tele/RESULT"
    value_template: "{{ value_json.RfReceived.Data }}"

  - alias: Reset Lounge Window
    hide_entity: true
    trigger:
      platform: state
      entity_id: binary_sensor.lounge_window
      to: 'on'
      for:
        seconds: 300
    action:
      service: mqtt.publish
      data:
        topic: "rf_bridge/tele/RESULT"
        payload: ' {“RfReceived”:{“Data”:"5D4533off"}} '
        retain: 'true'
4 Likes

Instead of the reset automation you can also do this:

off_delay: 5

This resets it after 5 seconds. No need for another automation.

- platform: mqtt
  state_topic: "tele/rfbridge/RESULT"
  name: 'Kitchen Leak'
  value_template: '{{value_json.RfReceived.Data}}'
  payload_on: '578B11'
  off_delay: 5
  device_class: moisture
  optimistic: false
  qos: 1
  retain: false

Thanks for the tips, got it to work!

5 Likes

Thanks for that code snippet @eh50 I have been looking for a clean way to turn of a binary_sensor that I have setup for an RF Motion Sensor.

Glad to help, I had a whole yaml file full of reset automations, got rid of it with just that code.

This save’d me from a lot of work