RF 433MHz Wireless Smart Switch

Has anyone tried building esp32 receiver for this switch https://www.aliexpress.com/item/1005006297456850.html
using RF receiver like https://www.aliexpress.com/item/1005008341679708.html

You need just cheap superheterodyne receiver module.

ps. interesting frequency, 433 PetaHerz :joy:

OP needs a transmitter to be able to action the switch.
Having a transmitter hooked up through, e.g., ESPHome is the easy part.

The difficult one is to know what software protocol that device is using above 433MHz, which is just the infrastructure part…

OP was asking receiver, so I expect he/she want’s to detect the transmitter switches with Esphome.

Yes, I’m talking about receiver
The manufacturer of the switch requires it to be receiver-switch pairs where receiver is meant to physically connect to lightbulbs
I don’t want to physically connect lightbulbs through their receivers as that would require rebuilding my electricity grid
What I imagine is buying just switches and controlling lightbulbs other ways, maybe with something like this https://www.aliexpress.com/item/1005006512623289.html

The switch itself is not powered by battery, it self generates power by moving magnet near coils
I don’t think it can generate enough power for some complex interactions/protocols with receiver
I’d expected something like transmitting ID of the switch

Not sure what you’re trying to achieve, actually.

So just buy Tuya wifi bulbs, then. They are actually cheaper than that smart socket…

Never had any luck with no-battery 433Mhz switches, not with Sonoff Rfbridge, not with RFlink, not with DIY Tasmota/OpenMQTTGateway/ESPHome, not with a RTL-SDR dongle. YMMV.

But the link in the first post of this topic shows switches powered by CR2023 ?

Then you have to post link to that switch.
The one you linked is battery powered:
Coding way: EV1527 learning code
Modulation: ASK

Which supposed to be ok for common 433 remote receiver like RXB6.

Ah, you want physical control and replace the receivers with something else? Misunderstood that.

If it’s actually simple EV1527 coding, then superheterodyne is the way to go, as Karosm suggested.
For decoding, I’m using RTL433 component over ESPHome (GitHub - juanboro/esphome-rtl_433-decoder: RTL_433 Decoder Component for ESPHome), which uses GitHub - juanboro/rtl_433_Decoder_ESP: RTL_433 Decoder for ESP32

For my actual decoding, I added a specific EV1527 RTL433 decoder, YMMV

Might be over-engineered, and easier solution might be available, though

tl;dr, my esphome YAML

substitutions:
  device_name: "esp32-rx500-receiver"

###########################################

esphome:
  name: "${device_name}"
  friendly_name: ESP32 RX500 receiver


esp32:
  board: esp32doit-devkit-v1
  framework:
    # type: arduino
    type: esp-idf

packages:
  base: !include common/base_nomq.yaml

external_components:
  - source: github://koying/esphome-rtl_433-decoder
    components: [ rtl_433 ]
    refresh: always

logger:
#  level: VERBOSE

mqtt:
    broker: mqtt.lan
    username: !secret mqtt_user
    password: !secret mqtt_pwd
substitutions:
  device_name: "esp32-rx500-receiver"

###########################################

esphome:
  name: "${device_name}"
  friendly_name: ESP32 RX500 receiver


esp32:
  board: esp32doit-devkit-v1
  framework:
    # type: arduino
    type: esp-idf

packages:
  base: !include common/base_nomq.yaml

external_components:
  - source: github://koying/esphome-rtl_433-decoder
    components: [ rtl_433 ]
    refresh: always

logger:
#  level: VERBOSE

mqtt:
    broker: mqtt.lan
    username: !secret mqtt_user
    password: !secret mqtt_pwd
    discovery: false

time:
  - platform: sntp
    id: rtc_time
    timezone: Europe/Brussels

sensor:
  - platform: template
    id: esp_memory
    icon: mdi:memory
    name: Free Memory
    lambda: return heap_caps_get_free_size(MALLOC_CAP_INTERNAL) / 1024;
    unit_of_measurement: 'kB'
    state_class: measurement
    entity_category: "diagnostic"
    state_topic:
  - platform: uptime
    name: Uptime
    id: sys_uptime
    state_topic:
  - platform: wifi_signal 
    name: RSSI
    id: wifi_signal_db
    entity_category: "diagnostic"
    state_topic:

binary_sensor:    
  - platform: status
    name: Status
    state_topic:

light:
  - platform: status_led
    name: "led"
    pin: GPIO2
    state_topic:
    command_topic:

button:
  - platform: restart
    name: "Restart"
    state_topic:
    command_topic:

text_sensor:
  - platform: wifi_info
    ip_address:
      name: "IP Address"
      icon: mdi:wifi
      state_topic:
    ssid:
      name: "Connected SSID"
      icon: mdi:wifi-strength-2
      state_topic:

  # ESPHome version
  - platform: version
    hide_timestamp: true
    name: "ESPHome Version"
    state_topic:

  - platform: template
    name: REMOTE_WHITE_ABCD_01 sensor
    id: REMOTE_WHITE_ABCD_01_sensor
    icon: "mdi:remote"
  - platform: template
    name: REMOTE_BLACK_ABCD_02 sensor
    id: REMOTE_BLACK_ABCD_02_sensor
    icon: "mdi:remote"
  - platform: template
    name: REMOTE_TINY_ABCD_03 sensor
    id: REMOTE_TINY_ABCD_03_sensor
    icon: "mdi:remote"
  - platform: template
    name: DOORBELL sensor
    id: DOORBELL_sensor
    icon: "mdi:remote"
  - platform: template
    name: BUTTON_01 sensor
    id: BUTTON_01_sensor
    icon: "mdi:remote"
  - platform: template
    name: SIMPLE_DOOR_CONTACT_01 sensor
    id: SIMPLE_DOOR_CONTACT_01_sensor
    icon: "mdi:remote"
  - platform: template
    name: SIMPLE_DOOR_CONTACT_02 sensor
    id: SIMPLE_DOOR_CONTACT_02_sensor
    icon: "mdi:remote"
  - platform: template
    name: DOOR_CONTACT_01 sensor
    id: DOOR_CONTACT_01_sensor
    icon: "mdi:fence-electric"
  - platform: template
    name: DOOR_CONTACT_04 sensor
    id: DOOR_CONTACT_04_sensor
    icon: "mdi:fence-electric"

interval:
  - interval: 1min
    then:
      - lambda: |-
          id(DOORBELL_sensor).publish_state("unknown");
          id(REMOTE_WHITE_ABCD_01_sensor).publish_state("unknown");
          id(REMOTE_BLACK_ABCD_02_sensor).publish_state("unknown");
          id(REMOTE_TINY_ABCD_03_sensor).publish_state("unknown");
          id(REMOTE_TINY_ABCD_03_sensor).publish_state("unknown");
          id(DOORBELL_sensor).publish_state("unknown");
          id(DOOR_CONTACT_04_sensor).publish_state("unknown");
          id(DOOR_CONTACT_01_sensor).publish_state("unknown");

remote_receiver:
  - id: rf_receiver
    pin:
      number: GPIO13
    tolerance: 60%
    filter: 4us
    idle: 4ms
    buffer_size: 2048 # This value is pretty large... default 10k is way too large

    on_drayton :
      then:
        - lambda: |-
            uint32_t device = x.address;
            uint32_t button = x.channel;
            ESP_LOGD("drayton", "Received code: %d / %d", device, button);
            std::string sButton;
            switch(device) {
              case [retracted]:
                switch(button) {
                  case 0x018:
                    sButton = "GATE";
                    break;
                  case 0x01f:
                    sButton = "DOOR";
                    break;
                }
                id(DOORBELL).trigger(sButton);
                id(DOORBELL_sensor).publish_state(sButton);
                break;
            }

###############################################
## rtl_433 decoder example
###############################################
# How to use: 
# 1.  Configure the rtl_433 component to receive ESPhome remote data (receiver_id)
# 2.  Use the on_json_message trigger from the rtl_433 component to receive the json messages and process

# this example processes pulses from the remote receiver component and then sends decoded
# data via MQTT similar to how rtl_433 would.  It also generates home-assistant event bus messages
# via the API (if HA is connected and listening)
rtl_433:
  id: my_rtl433_id
  receiver_id: rf_receiver
  on_json_message: 
    then:
      - lambda: |-
          if (x["model"] == "Generic EV1527") {
            auto now = id(rtc_time).now();
            char dateStr[25] = {0};
            // check valid time
            if (now.is_valid()) {
              sprintf(dateStr, "%s", now.strftime("%Y-%m-%d %H:%M:%S").c_str());
            }

            uint32_t device = x["id"].as<int>();
            uint32_t button = x["data"].as<int>();
            ESP_LOGD("rtl_433", "Received event: %s", x);
            std::string sButton;
            switch(device) {
              case [retracted]:
                switch(button) {
                  case 1:
                    sButton = "A";
                    break;
                  case 2:
                    sButton = "B";
                    break;
                  case 4:
                    sButton = "C";
                    break;
                  case 8:
                    sButton = "D";
                    break;
                }
                id(REMOTE_WHITE_ABCD_01).trigger(sButton);
                id(REMOTE_WHITE_ABCD_01_sensor).publish_state(sButton);
                break;
              case [retracted]:
              case [retracted]:
                switch(button) {
                  case 8:
                    sButton = "A";
                    break;
                  case 4:
                    sButton = "B";
                    break;
                  case 1:
                    sButton = "C";
                    break;
                  case 2:
                    sButton = "D";
                    break;
                }
                id(REMOTE_BLACK_ABCD_02).trigger(sButton);
                id(REMOTE_BLACK_ABCD_02_sensor).publish_state(sButton);
                break;
              case [retracted]:
                switch(button) {
                  case 2:
                    sButton = "B";
                    break;
                  case 1:
                    sButton = "C";
                    break;
                }
                id(REMOTE_TINY_ABCD_03).trigger(sButton);
                id(REMOTE_TINY_ABCD_03_sensor).publish_state(sButton);
                break;
              case [retracted]:
                switch(button) {
                  case 1:
                    sButton = "A";
                    break;
                  case 2:
                    sButton = "C";
                    break;
                  case 8:
                    sButton = "D";
                    break;
                }
                id(REMOTE_TINY_ABCD_03).trigger(sButton);
                id(REMOTE_TINY_ABCD_03_sensor).publish_state(sButton);
                break;
              case [retracted]:
                switch(button) {
                  case 40202:
                    sButton = "GATE";
                    break;
                  case 40193:
                    sButton = "DOOR";
                    break;
                }
                id(DOORBELL).trigger(sButton);
                id(DOORBELL_sensor).publish_state(sButton);
                break;
              case [retracted]:
                sButton = "SINGLE";
                id(BUTTON_01).trigger(sButton);
                if (strlen(dateStr))
                  id(BUTTON_01_sensor).publish_state(dateStr);
                break;
              case [retracted]:  // Mail door
                sButton = "SINGLE";
                id(SIMPLE_DOOR_CONTACT_01).trigger(sButton);
                if (strlen(dateStr))
                  id(SIMPLE_DOOR_CONTACT_01_sensor).publish_state(dateStr);
                break;
              case [retracted]:  // Flap
                sButton = "SINGLE";
                id(SIMPLE_DOOR_CONTACT_02).trigger(sButton);
                if (strlen(dateStr))
                  id(SIMPLE_DOOR_CONTACT_02_sensor).publish_state(dateStr);
                break;
              case [retracted]:  // Grille
                switch(button) {
                  case 10:
                    sButton = "OPEN";
                    break;
                  case 14:
                    sButton = "CLOSE";
                    break;
                }
                id(DOOR_CONTACT_04).trigger(sButton);
                id(DOOR_CONTACT_04_sensor).publish_state(sButton);
                break;
              case [retracted]:  // Portail
                switch(button) {
                  case 10:
                    sButton = "OPEN";
                    break;
                  case 14:
                    sButton = "CLOSE";
                    break;
                }
                id(DOOR_CONTACT_01).trigger(sButton);
                id(DOOR_CONTACT_01_sensor).publish_state(sButton);
                break;
            }
          }

      # MQTT publish similar to how rtl_433 would...
      # todo: add in the timestamp to the json message
      - mqtt.publish_json:
          topic: !lambda |-
            ESP_LOGD("rtl_433", "MQTT publish: %s", x);
            std::string topic=str_sprintf("rtl_433/%s/events",App.get_name().c_str());
            if (x["model"]) {
              if (x["id"])
                topic+=str_sprintf("/%s/%d",x["model"].as<const char*>(),x["id"].as<int>());
              else               
                topic+=str_sprintf("/%s",x["model"].as<const char*>());
            }
            return(topic);            
          payload: 
            root.set(x);
      # Also generate a home assistant event (you can then do all kinds of things with this data in home-assistant)
      # Note that HA will also receive all the event data above - so really only one of these is necessary...
      # HA event API is better, but MQTT is more universal.   The choice is yours.
      # - homeassistant.event:
      #     event: esphome.rtl_433
      #     data:
      #       hostname: !lambda |-
      #           return App.get_name();
      #       message: !lambda |-
      #         return json::build_json([x](JsonObject root) {
      #           root.set(x);
      #         });
      #       frequency: !lambda |-
      #         return id(mycc1101)._freq;
      #       rssi: !lambda |-
      #         return id(mycc1101).last_rx_rssi;



remote_transmitter:
  - id: rf_transmitter
    pin:
      number: GPIO12
    carrier_duty_percent: 100%

event:
  - platform: template
    name: REMOTE_WHITE_ABCD_01
    id: REMOTE_WHITE_ABCD_01
    icon: "mdi:remote"
    device_class: "button"
    event_types:
      - "A"
      - "B"  
      - "C"  
      - "D"  
  - platform: template
    name: REMOTE_BLACK_ABCD_02
    id: REMOTE_BLACK_ABCD_02
    icon: "mdi:remote"
    device_class: "button"
    event_types:
      - "A"
      - "B"  
      - "C"  
      - "D"  
  - platform: template
    name: REMOTE_TINY_ABCD_03
    id: REMOTE_TINY_ABCD_03
    icon: "mdi:remote"
    device_class: "button"
    event_types:
      - "A"
      - "B"  
      - "C"  
      - "D"  
  - platform: template
    name: DOORBELL
    id: DOORBELL
    icon: "mdi:remote"
    device_class: "doorbell"
    event_types:
      - "DOOR"
      - "GATE"  
  - platform: template
    name: BUTTON_01
    id: BUTTON_01
    icon: "mdi:remote"
    device_class: "button"
    event_types:
      - "SINGLE"
  - platform: template
    name: SIMPLE_DOOR_CONTACT_01
    id: SIMPLE_DOOR_CONTACT_01
    icon: "mdi:remote"
    device_class: "button"
    event_types:
      - "SINGLE"
  - platform: template
    name: SIMPLE_DOOR_CONTACT_02
    id: SIMPLE_DOOR_CONTACT_02
    icon: "mdi:remote"
    device_class: "button"
    event_types:
      - "SINGLE"
  - platform: template
    name: DOOR_CONTACT_01
    id: DOOR_CONTACT_01
    icon: "mdi:fence-electric"
    device_class: "button"
    event_types:
      - "OPEN"
      - "CLOSE"
  - platform: template
    name: DOOR_CONTACT_04
    id: DOOR_CONTACT_04
    icon: "mdi:fence-electric"
    device_class: "button"
    event_types:
      - "OPEN"
      - "CLOSE"

Hhmmm… This is a very interesting repo that I’ve never seen. Could you summarize whats different between this and the native Esphome rf_reciever?

Sorry my bad, the link I posted is what I first thought to buy but I actually ordered this one https://www.aliexpress.com/item/1005006309609881.html where the switch is powered by Faraday law, no battery required

Exactly, I have multiple things to control so I need multiple switches but I’d like to not buy multiple receivers if I can have one receiver that takes signals from all switches

It seems to require esp32 with multiple cores :thinking:
Will try it a bit later when I get one
Thanks

Let us know if you get somewhere with those switches.

I see quite pointless to try to decode the signal as a first step.
Just connect your receiver module to esp and give remote_receiver a go with dump: raw.
Your AE description says it’s ASK modulation, but doesn’t specify what kind of.
I would expect the signal being pretty short for obvious reasons.

Tried the component you suggested
Unfortunately it didn’t work
I was able to catch some random signals from nearby apartments but not from the switch
The remote_receiver itself catches switching every single time, I can see array of random numbers using dump: all, but is not able to decode anything

post the array of “random numbers” for few switch presses.

Don’t understand how to upload logs here, shared on dropbox instead https://www.dropbox.com/scl/fi/140an69slx0kwabtqo2n3/logs_esphome-web-5a4240_logs.txt?rlkey=e6sack13jets2jcokhmod3st8&st=r0toznpa&dl=0

I’ve noticed when I press the switch button I usually get something like this
[remote.beo4:086]: Beo4: n_sym=94 with a different number each time followed by [remote.pronto:229]: Received Pronto: data= with long list of numbers around 100 of then for one switch and around 300 for the other switch

You can upload logs the same way as you post code.

I’d like to see dump: raw to understand what your transmitter really sends.