Can't create automation for sonoff RF bridge

I am trying to implement the sonoff rf-bridge with esphome. I have installed ESPhome with the followinf YAML file mainly taken from RF Bridge Component — ESPHome

esphome:
  name: rf-test

esp8266:
  board: esp01_1m

web_server:
  port: 80

# Enable Home Assistant API
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
ota:
  password: "827fc4cffc6c7a66aa3e225bb3393447"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Rf-Test Fallback Hotspot"
    password: "aLK1W7ethcjn"

captive_portal:

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

This is working as it has appeared in HA

Screenshot 2022-10-17 140734

but with no entities.

When i press an 433rf button i see it in the esphome logs, but i can see it anywhere in HA (developer tools, history or logbook)

but i can not work out how to create an automation within HA so i can do something with the the button.

Any Help would be great

You’ll want to listen for esphome.rf_code_received at developer tools > events and use the event data in an event trigger

do you want to see the remote control code directly in the interface? use the text sensor … tomorrow I will give the code

Thank you, that would be very useful.

I can see the data now. I am also trying node red for the first time and can see the data in there using esphome.rf_code_received

Thanks

2 Likes
rf_bridge:
  uart_id: txrx
  on_code_received:
    then:
      - homeassistant.event:
          event: esphome.rf_code_received
          
          data:
            sync: !lambda 'return data.sync;'
            low: !lambda 'return data.low;'
            high: !lambda 'return data.high;'
            code: !lambda 'return data.code;'


      - text_sensor.template.publish:
          id: sync_data
          state: !lambda 'char buffer [10];return itoa(data.sync,buffer,16);'
      - text_sensor.template.publish:
          id: low_data
          state: !lambda 'char buffer [10];return itoa(data.low,buffer,16);'
      - text_sensor.template.publish:
          id: high_data
          state: !lambda 'char buffer [10];return itoa(data.high,buffer,16);'
      - text_sensor.template.publish:
          id: code_data
          state: !lambda 'char buffer [10];return itoa(data.code,buffer,16);'      

      - text_sensor.template.publish:
          id: codedata_automation
          state: !lambda 'char buffer [10];return itoa(data.code,buffer,16);'      
      - delay: 1s
      - text_sensor.template.publish:
          id: codedata_automation
          state: "0"

          

# Звонок
      - if:
          condition:
            lambda: |-
              return data.code == 0xEB8E05;
          then:
            - binary_sensor.template.publish:
                id: doorbell
                state: ON
            - delay: 500ms
            - binary_sensor.template.publish:
                id: doorbell
                state: OFF  


# Датчик движения                
      - if:
          condition:
            lambda: |-
              return data.code == 0x06E75A;
          then:
            - binary_sensor.template.publish:
                id: pir
                state: ON
            - delay: 5 s
            - binary_sensor.template.publish:
                id: pir
                state: OFF  


binary_sensor:

  - platform: template
    name: 'Pir'
    id: pir
    device_class: motion
    filters:
      - delayed_off: 20s
      - delayed_on: 100ms
  
  - platform: template
    name: 'Doorbell'
    id: doorbell

text_sensor:

  - platform: template
    id: sync_data
    icon: "mdi:format-vertical-align-bottom"
    name: "sync 0x0000"
  - platform: template
    id: low_data
    icon: "mdi:format-vertical-align-bottom"
    name: "low 0x0000" 
  - platform: template
    id: high_data
    icon: "mdi:format-vertical-align-bottom"
    name: "high 0x0000"
  - platform: template
    id: code_data
    icon: "mdi:format-vertical-align-bottom"
    name: "code 0x000000"
  - platform: template
    id: codedata_automation
    icon: "mdi:lightbulb"
    name: "code automation"

Here is my code with text sensors where you can see the remote code.

for automating in HA you can use text sensor id: codedata_automation . This sensor shows a code for 1s and then resets the value to 0.

an example of automation in HA:

alias: ОСНОВНОЕ гидрофор
description: ""
trigger:
  - platform: state
    entity_id: sensor.code_automation
    to: 75af02
    id: 1 vkl
  - platform: state
    entity_id: sensor.code_automation
    to: 75af01
    id: 2 vkl
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: 1 vkl
        sequence:
          - type: turn_on
            device_id: 90b3ff2da6a55bf31220ad2fd66aacf6
            entity_id: switch.chuangmi_m3_9889_switch_2
            domain: switch
      - conditions:
          - condition: trigger
            id: 2 vkl
        sequence:
          - type: turn_off
            device_id: 90b3ff2da6a55bf31220ad2fd66aacf6
            entity_id: switch.chuangmi_m3_9889_switch_2
            domain: switch
    default: []
mode: restart

There are RF two button keys. One button turns on the xiaomi socket if the text sensor sensor.code_automation has a state of 75af02 and the second turns it off if the text sensor sensor.code_automation has a state of 75af01

excellent, Thank you for this, Loads of stuff to get going with.