433MHz Alarm system, Sonoff RF bridge + KERUI D025 + Alarmo

Introduction:

  • An alarm panel controlling 6 window/door alarm sensors (433MHz) using a sonoff RF bridge R2.2 (with or without esphome). Sends custom notifications and is reliable.

  • KERUI D025 sensors that sends three unique signals: open, close, and low battery

Steps overview

OPTION 1: using original firmware and ewelink app

  1. Set up RF bridge with ewelink app
  2. Add each signal of the each sensor as a separate “remote” (ewelink app, limit 16 devices: 4 sensors x 3 signals each)
  3. Link RF bridge to HA (SonoffLAN integration)
  4. Combine the open/close signals into one binary sensor (YAML)
  5. set up Alarmo

OPTION 2: using esphome firmware (no portisch)

  1. Flash RF bridge with esphome
  2. Ask home assistant to monitor RF events broadcasted by the bridge
  3. Combine open/close events into one binary sensor
  4. Set up Alarmo

OPTION 1:Original firmware

  1. Set up RF bridge with ewelink app
  2. Ewelink app: add each signal of the each sensor as a separate “remote”. You have to push the learn button
  • Ewelink doesn’t let you set up a door sensor with unique signals for open/close/low battery, so you have to set them up as separate devices. This will eat storage space on the bridge because the bridge is limited to limit 16 devices: 4 sensors x 3 signals each or 8 sensors x 2 signals each (if you don’t care about low battery)
  1. Link RF bridge to HA (SonoffLAN integration): install it from HACS, you have to enter your ewelink credentials for the integration to get the encryption keys for the bridge.
  • Although the integration is local (I checked with wireshark), if internet access is banned for the bridge, the timestamp attribute for open/close events will be missing and the bridge will not report the state of sensors
  1. Combine the open/close signals into one binary sensor (YAML):
    In configuration.yaml add the following, repeat for each sensor:
sonoff:
  rfbridge:
    office_open:  # button/alarm name in eWeLink application (open signal)
      name: Office window sensor  # optional, you can change sensor name
      device_class: window  # e.g. door, window
      timeout: 0  # disable auto close timeout
      payload_off: office_close # button/alarm name in eWeLink application (close signal)
  
    kitchen_open:  # button/alarm name in eWeLink application (open signal)
      name: Kitchen window sensor  # optional, you can change sensor name
      device_class: window  # e.g. door, window
      timeout: 0  # disable auto close timeout
      payload_off: kitchen_close # button/alarm name in eWeLink application (close signal)
 

For whaver reason, the bridge goes unavailable 3 times a day for 5 seconds, no detection happens in that state. Thats why I recommend option 2. I tried both for 3 months
.

OPTION 2: using esphome firmware (no portisch/no direct hack mod)
Direct hack allows esphome to control the RF chip directly. Not needed for D025 sensors.

1) Flash RF bridge with esphome (using this guide)

  • Use the J2 pins to flash (its not mentioned in the guide)
  • I had success flashing with bridge powered by its own USB port. I was using a 8266 nodemcu as an FTDI.
  • I flashed using ESPhome addon to make the firmware.bin and used esp web tools to flash (windows PC)

Here’s my esphome yaml:

esphome:
  name: sonoff-rf-bridge
  friendly_name: Sonoff RF Bridge

esp8266:
  board: esp01_1m

# Enable logging
logger:
  baud_rate: 0

# Enable Home Assistant API
api:
  encryption:
    key: "use your own key mine was generated automatically with esphome"

  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: # report RF signal in Hexadecimal
          event: esphome.rf_code_received
          data:
            sync: !lambda 'return format_hex(data.sync);'
            low: !lambda 'return format_hex(data.low);'
            high: !lambda 'return format_hex(data.high);'
            code: !lambda 'return format_hex(data.code);'

      - homeassistant.event: #report RF signal in decimal. decimal values worked better for me
          event: esphome.rf_code_received
          data:
            sync: !lambda 'return int(data.sync);'
            low: !lambda 'return int(data.low);'
            high: !lambda 'return int(data.high);'
            code: !lambda 'return int(data.code);'

ota:
 - platform: esphome
   password: "se your own key mine was generated automatically with esphome"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Sonoff-Rf-Bridge"
    password: "xxxxxxxx"

captive_portal:
 
uart:
  tx_pin: 1
  rx_pin: 3
  baud_rate: 19200



button:
  # Restart the ESP
  - platform: restart
    name: "Restart"


# Sensors for ESP version and WIFI information
text_sensor:
  # ESPHome version
  - platform: version
    hide_timestamp: true
    name: "ESPHome Version"
  # IP address and connected SSID
  - platform: wifi_info
    ip_address:
      name: "IP Address"
      icon: mdi:wifi
    ssid:
      name: "Connected SSID"
      icon: mdi:wifi-strength-2
sensor:
  # WiFi signal
  - platform: wifi_signal
    name: "WiFi Signal"
    update_interval: 120s
  - platform: uptime
    name: Sonoff RF Bridge Uptime
binary_sensor:
  - platform: status
    name: Sonoff RF Bridge Status

light:
  - platform: status_led
    name: "Switch state"
    pin: 
      number: GPIO13
      inverted: true

#I have an LED strip with a remote, this switch template turns it on an off.
switch:
  - platform: template
    id: range
    name: "Hood light"
    optimistic: true
    turn_on_action: 
      - rf_bridge.send_code:
          sync: 24182
          low: 758
          high: 2396
          code: 49921    
    turn_off_action: 
      - rf_bridge.send_code:
          sync: 22466
          low: 768
          high: 2386
          code: 49923

2. Ask home assistant to monitor RF events broadcasted by the bridge
Instead of the bridge learning and storing each signal, we’ll just have home assistant monitor the RF signals:
In HASS, Go to Developer tools>Events> start listening.
Write down the signal events for each sensor and each signal (open/close/low battery).

  • For the D025 sensors, the sync/low/high keeps changing but the “code” value is always the same. I only use the “code” value for automations/templating.
  • I also found out that low battery code = open signal code + 1 (decimal values)

3) Combine open/close events into one binary sensor

In Home assistant configuration.yaml

template:
####Office window#####
- trigger:
    - platform: event 
      event_type: esphome.rf_code_received
      event_data: #replace with your own
        device_id: c893ffef7e1816adeb244f4e138f7840
        code: "12345678" 
      id: "on"
    - platform: event
      event_type: esphome.rf_code_received
      event_data: #replace with your own
        device_id: c893ffef7e1816adeb244f4e138f7840
        code: "12345678"
      id: "off"
  binary_sensor:
    - name: Office window
      device_class: window
      state: "{{ trigger.id }}"

Integration with Alarmo
Alarmo has a lot of options. Install it via HACS and read the docs but I want to share a custom scripts for mobile notifications:

Notify phone when triggered. Alarmo>Actions>New Notification

service: notify.mobile_app_poco_f3
data:
  message: Alarm triggered! {{open_sensors|format=short}}.
  title: Alarmo
  data:
    ttl: 0
    importance: max
    channel: alarm_stream
    notification_icon: mdi:shield-home
    color: red
    actions:
      - action: ALARMO_DISARM
        title: Disarm
      - action: URI
        title: Call 911
        uri: >-
          intent://scan/#Intent;scheme=tel:911;action=android.intent.action.DIAL;end

1 Like

Excellent guide!

Thanks very much for sharing. Very useful.