Hampton Bay + ESP32 + CC1101

Hi everyone,
I’m feeling a bit stuck with my project and could really use some help. My goal is to use Home Assistant to control my ceiling fan. I want the fan to automatically turn on when the temperature rises above a certain threshold.

To start, I created a basic setup with one button to test communication with the fan. I used an EvilCrow device to record the RF signal, which generates a Flipper SubGHz RAW file. I then used Universal Radio Hacker to convert the signal to bits. Both the RAW file and the converted binary work perfectly in the EvilCrow UI to control the fan’s light.

My raw data:

-394 619 -728 299 -360 659 -688 333 -336 657 -700 326 -700 333 -699 296 -715 299 -703 301 -735 296 -368 625 -11983 301 -392 652 -667 327 -398 622 -694 323 -363 668 -654 336 -719 287 -712 335 -692 331 -695 293 -702 264 -461 597 -11980 294 -414 617 -698 297 -377 647 -701 338 -333 689 -661 325 -714 290 -731 293 -723 301 -692 333 -736 269 -395 587 -12016 298 -355 688 -682 303 -360 649 -681 362 -334 647 -697 356 -689 322 -676 318 -652 331 -683 337 -732 264 -397 630 -11967 291 -518 524 -686 296 -423 587 -712 328 -367 614 -732 293 -724 290 -749 290 -720 298 -717 285 -1749 293 -12091 162 -555 496 -853 130 -427 621 -1767 194 -1955 128 -722 336 -656 365 -636 361 -669 355 -626 392 -11856 360 -335 679 -666 352 -326 667 -685 336 -316 684 -680 368 -646 362 -643 357 -637 386 -665 349 -653 360 -652 0

My bin bit raw data:

0000111111000000011100001111111000000011100011111110000000111000000011100000001110000000111000000011100000001110000111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111000011111110000000111000011111100000001110000111111100000001110000000111000000011100000001110000000111000000011100000111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111000011111100000001110000111111000000011100011111110000000111000000011100000001110000000111000000011100000001110000111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111000011111110000000111000011111100000001111000111111000000011110000000111000000011100000001110000000111000000011100001111110000000000000000000

However, when I try to use the RAW signal with ESPHome and configure a button to send the signal, it doesn’t work. I’m unsure how to extract the correct preamble and command from the code. Any advice would be greatly appreciated!

My ESPHome testing config:

esphome:
  name: cc1101-light-control
  friendly_name: CC1101 Light Control
  includes:
    - cc1101.h
  libraries:
    - SPI
    - "SmartRC-CC1101-Driver-Lib"

esp32:
  board: esp32dev  # Use the correct board type for your ESP32

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: true
  power_save_mode: none  # ESP32 has better power management

  # Optional manual IP
  manual_ip:
    static_ip: 192.168.1.15
    gateway: 192.168.1.1
    subnet: 255.255.255.0

# Enable logging
logger:
   level: VERBOSE  # Set the logging level to VERBOSE for detailed logs

# Enable OTA (Over-the-Air updates)
ota:
  platform: esphome

# Define the remote transmitter and the sensor for RSSI
remote_transmitter:
  pin: GPIO5  # CSN connected to GPIO5
  carrier_duty_percent: 50%
  id: rf_transmitter

# Define the RSSI sensor using the custom CC1101 component
sensor:
  - platform: custom
    lambda: |-
      auto cc1101 = new CC1101(18, 19, 23, 5, 16, 58.0, 303.875, rf_transmitter, new Sensor());
      
      // Log that the CC1101 was initialized
      ESP_LOGD("cc1101", "CC1101 initialized successfully 😎");

      App.register_component(cc1101);
      return {cc1101->get_rssi_sensor()}; 

    sensors:
      name: "CC1101 RSSI"

# Button to trigger the RF transmission
button:
  - platform: template
    name: "Light Switch"
    on_press:
      then:
        - lambda: ESP_LOGI("Button", "Light Switch button pressed 🛎️, sending RF signal...");
        - remote_transmitter.transmit_raw:
            carrier_frequency: 303875kHz  # Adjust the frequency if needed
            code: [ raw code..]
        - lambda: ESP_LOGI("Button", "RF transmission completed 📡.");
        - delay: 500ms  # Add a small delay after transmission
        
# Optional Web server for monitoring
web_server:
  port: 80

Shouldn’t carrier duty cycle be 100% for RF devices?

Why but use esphome to record the code?

What do you mean to record the code by ESPHome?

As far as I know, carrier frequency is for infrared.
Where is the code? [ raw code… ]

Also, I think raw data should start with positive, is your inverse?

It’s in the docs Setting up IR Devices — ESPHome

I’ve updated my config to include a function that listens for signals on the same frequency.
When I press the button on my remote, I receive the following in the logs:
[I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=6 data='010101111110'.

I tried using that same raw code for my button configuration, but it’s not working.

EPSHome config:
esphome:
  name: cc1101-light-control
  friendly_name: CC1101 Light Control
  includes:
    - cc1101.h
  libraries:
    - SPI
    - "SmartRC-CC1101-Driver-Lib"

esp32:
  board: esp32dev  # Use the correct board type for your ESP32

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: true
  power_save_mode: none  # ESP32 has better power management

  # Optional manual IP
  manual_ip:
    static_ip: 192.168.1.15
    gateway: 192.168.1.1
    subnet: 255.255.255.0

# Enable logging
logger:
   level: VERBOSE  # Set the logging level to VERBOSE for detailed logs

# Enable OTA (Over-the-Air updates)
ota:
  platform: esphome

# Define the remote transmitter
remote_transmitter:
  pin: GPIO5  # CSN connected to GPIO5
  carrier_duty_percent: 50%
  id: rf_transmitter

# Define the remote receiver with rc_switch for bit reception
remote_receiver:
  id: rf_receiver
  pin: 
    number: GPIO16  # GDO0 pin connected to GPIO16
    inverted: false
  tolerance: 50%
  filter: 4us
  idle: 4ms
  buffer_size: 2kb
  dump: 
    - rc_switch  # This will decode signals using the rc_switch protocol

# Define the RSSI sensor using the custom CC1101 component
sensor:
  - platform: custom
    lambda: |-
      auto cc1101 = new CC1101(18, 19, 23, 5, 16, 58.0, 303.875, rf_transmitter, new Sensor());
      
      // Log that the CC1101 was initialized
      ESP_LOGD("cc1101", "CC1101 initialized successfully 😎");

      App.register_component(cc1101);
      return {cc1101->get_rssi_sensor()}; 

    sensors:
      name: "CC1101 RSSI"

# Button to trigger the RF transmission
button:
  - platform: template
    name: "Light Switch"
    on_press:
      then:
        - lambda: ESP_LOGI("Button", "Light Switch button pressed 🛎️, sending RF signal...");
        - remote_transmitter.transmit_rc_switch_raw:
            protocol: 6           # Use the same protocol you received
            code: '010101111110'  # Binary code received ('010101111110')
            repeat: 5             # You can adjust the number of repetitions as needed
        - lambda: ESP_LOGI("Button", "RF transmission completed 📡.");

# Optional Web server for monitoring
web_server:
  port: 80

You should try to understand the difference of IR and RF transmitting. Or at least read the answers to your posts.

Yes this thread is frustrating. @canadank0 clearly can’t be bothered even reading the responses, or the docs, which say exactly what you are telling him.

Apologies if it seemed like I was ignoring you. I’ve now updated the settings for the RF devices.

Regarding the raw code: I initially used the EvilCrow to capture the signal and successfully tested transmitting it back with the EvilCrow, which worked fine. The code I shared earlier is an exact copy, without any modifications. Honestly, I’m not sure how the code should look in its proper form.

Then @nickrout suggested why not record the code with the ESP, which I didn’t realize was possible. So, I started looking into how to capture the codes. I managed to get raw codes from my remote (UC7078T at 303.875 MHz frequency), but the remote keeps sending inconsistent signals. The same button sometimes sends: 10101111110, or 010101111110, or even 11010111. It’s strange.