=====Rf Control===== Flash and use the [[https://sonoff.tech/product/accessories/433-rf-bridge|Sonoff RF Bridge R2 V1.0]] to control RF devices ====Setup==== Using a [[https://www.aliexpress.com/item/32634246159.html|serial-to-USB converter (FT232RL FTDI USB to TTL)]] and some dupont wires flash the R2 V1.0 RF bridge ESP with Tasmota, flash the RF chip with the custom Portisch firmware, then reflash the ESP with ESPHome. ===Downloads=== * Download [[https://github.com/esphome/esphome-flasher/releases|ESPHome-Flasher]] * Download ''tasmota.bin'' from [[https://github.com/arendst/Tasmota/releases|Tasmota releases]] * Download the entire contents of the [[https://github.com/arendst/Tasmota/tree/master/|Tasmota GitHub project]] via the green Clone or Download button to ensure that the firmware hex files are downloaded properly. The firmware files are located in the ./tools/fw_SonoffRfBridge_efm8bb1/ folder. Select the newest available hex file. Otherwise you may get error "Magic byte is not 0xE9". ===Prepare the RF Bridge=== * Remove the rubber feet from the Sonoff RF Bridge, optionally placing them just next to the screw holes * Pull out the circuit board from the casing * Lift up the led panel from the circuit board, carefully unsticking it * Locate the 5-pin header under near the bottom of the bent up led panel * Move the switch position towards the 5-pin header (to the off position) ===Flash ESP=== * Make sure the serial-to-USB converter is set to 3.3V mode * Attach the female to male dupont wires to the serial-to-USB converter * Place the male ends of the dupont wires in the RF bridge in the following order, making sure there is good contact: * Serial -> RF Bridge: * VCC -> 3V3 * TX -> RX * RX -> TX * GND -> GND * Connect the serial-to-USB adapter to the computer while pressing the button on the edge in order to put the ESP8285 into programming mode to upload the Tasmota firmware * If the green led panel lights up and there is no blue flashing light then it is in programming mode * Release the button on the RF bridge * Open ESPHome-Flasher on the PC * Make sure the correct serial port appears and is selected * Select the ''tasmota.bin'' firmware file * Click ''Flash ESP'' and wait for it to finish uploading, fiddling with the pins and retrying if needed ===Configure Tasmota=== * Using a Wi-Fi device search for a wifi AP named tasmota_XXXXXX-#### (where XXXXXX is a string derived from the device's MAC address and #### is a number) and connect to it * It should take you to the Tasmota configuration page automatically * Configure your network details in ''AP1'', the hostname doesn't matter at this stage, and ''Save'' * It should connect to your wifi network, use your router to find its IP address * Connect to that address: * ''Configuration'' > ''Configure Module'' > ''Module Type'' > ''Sonoff Bridge (25)'' * ''Save'' (It should restart and act as a Sonoff RF Bridge) * ''Console'': * Enter the command: ''SerialLog 0'' ===Flash RF firmware=== * Disconnect the RF Bridge from the PC * Keep the switch on the RF Bridge in the ''OFF'' position * On the RF Bridge, connect two wires from GPIO4 to C2D and GPIO5 to C2Ck * Plug the serial adaptor back into the PC * Reconnect to the RF Bridge web UI: * ''Firmware Upgrade'': * ''Upgrade by File Upload'' > Pick the previously downloaded Portisch firmware hex file * ''Start Upgrade'' (This should complete within 60 seconds) * Disconnect the serial adaptor from the PC and remove all the wiring * Switch the ON/OFF switch on the board back to ''ON'' to enable the RF again * Carefully bend the led panel back into place and optionally cut one of the wires to it to disable the relatively bright led * Fit the board into the case again, screwing it in ===Create and upload ESPHome firmware=== * Give the RF bridge a static IP address in your router * Using the ESPHome addon in Home Assistant: * Create a new device with the name ''sonoff_rf_bridge'' and any placeholder text for the network info * Enter the code from the [[#Notes]] section below into the config of the device * ''Save'' * Three dot menu on the device > ''Compile'' * ''Download Binary'' * Power up the RF bridge and load its web UI: * ''Firmware Upgrade'': * ''Upgrade by File Upload'' > Pick the just downloaded ESPHome firmware * ''Start Upgrade'' (This should complete within 60 seconds) * You should get a new device discovered notification in Home Assistant * Agree to add the RF bridge to Home Assistant ===Learn Codes=== * FIXME: learn new RF codes ====Update==== * Describe update Process * Include in the [[page>update_everything|Update Everything]] page using ''%%{{page>home:rf_control#Update&noheader}}%%'' ====Sources==== * [[https://tasmota.github.io/docs/devices/Sonoff-RF-Bridge-433/]] * [[https://next.esphome.io/components/rf_bridge.html]] * [[https://next.esphome.io/components/cover/time_based.html]] * [[https://next.esphome.io/components/cover/template.html]] ====Notes==== ESPHome firmware definition to allow discovery of new RF codes: substitutions: devicename: sonoff_rf_bridge upper_devicename: Sonoff RF Bridge device_platform: ESP8266 device_board: esp01_1m device_ip: 10.0.0.108 # Enable Web Server (optional) # web_server: # port: 80 <<: !include common/base.yaml logger: baud_rate: 0 uart: tx_pin: 1 rx_pin: 3 baud_rate: 19200 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 - service: send_advanced_rf_code variables: length: int protocol: int code: string then: - rf_bridge.send_advanced_code: length: !lambda 'return length;' protocol: !lambda 'return protocol;' code: !lambda 'return code;' - service: start_advanced_sniffing then: - rf_bridge.start_advanced_sniffing - service: stop_advanced_sniffing then: - rf_bridge.stop_advanced_sniffing 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);' on_advanced_code_received: then: - homeassistant.event: event: esphome.rf_advanced_code_received data: length: !lambda 'char buffer [10];return itoa(data.length,buffer,16);' protocol: !lambda 'char buffer [10];return itoa(data.protocol,buffer,16);' code: !lambda 'return data.code;' # Turn the Wifi led on for 2 seconds when the button is pressed to show that it's working output: - platform: gpio pin: number: GPIO13 inverted: True id: output_wifi_led light: - platform: binary id: wifi_led output: output_wifi_led binary_sensor: - platform: gpio pin: GPIO00 id: pairing_button on_press: then: - light.turn_on: wifi_led - delay: 2s - light.turn_off: wifi_led