Projects / Sensor bridge to Home Assistant

Sensor bridge to Home Assistant

Intermediate3 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. ESP32433

    Wire the receiver

    Power, divider and antenna.

  2. ESP32

    Print the codes

    Trigger each sensor.

  3. ESP32433

    Fill in the list

    Code and a name.

  4. ESP32

    Publish to MQTT

    Check with a subscriber.

  5. ESP32

    Add the discovery messages

    Sensors appear in Home Assistant.

  6. ESP32433

    Handle repeats

    Two second window.

  7. ESP32

    Test range

    Walk to the far sensors.

In short

How do you build a sensor bridge to Home Assistant?

One ESP32 collects several cheap 433 MHz sensors and publishes them to Home Assistant. You need ESP32 DevKit V1, 433 MHz RF transmitter and receiver pair, 5 V 2 A USB adapter and Resistor 10 kΩ × 3. It takes 7 steps and about 180 minutes.

Level
Intermediate
Time
About 180 min
Parts
4

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
433 MHz receiver VCC and GNDESP32 3V3 and GNDPower (shorter range at 3.3 V)
Receiver DATA10 kΩ to ESP32 GPIO27, with 20 kΩ (two 10 kΩ) to groundDivider to protect the ESP32
Receiver antenna17 cm straight wireQuarter-wave antenna
ESP32 VIN5 V adapterPower the board

Code

Many cheap door sensors and motion detectors send a short 433 MHz burst when triggered, and a receiver can read it; first run the sketch with the list empty, trigger each sensor, and copy the numbers the Serial Monitor shows into the list with names. Each burst arrives several times in a row, so repeats of the same code within two seconds are ignored. The sketch publishes an MQTT message under home/rf, and also a Home Assistant discovery message, so each sensor appears automatically as a binary sensor that turns off 30 seconds after the last trigger. The receiver outputs about 3.3 V when powered from 3V3, but a divider on the data line keeps the ESP32 safe if you later power it from 5 V. These sensors are simple and unencrypted: anyone nearby could copy a code and send a false trigger, so use them for convenience, not for a serious alarm. Put your own Wi-Fi details and broker address in the placeholders and do not share them. Check your country's rules for 433 MHz devices; receiving only is fine. Arduino IDE with the ESP32 boards package 2.0.x, board "ESP32 Dev Module".

Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

// 433 MHz to MQTT bridge with Home Assistant discovery. Libraries: rc-switch, PubSubClient. Board: ESP32 Dev Module.
#include <WiFi.h>
#include <PubSubClient.h>
#include <RCSwitch.h>
const char* SSID = "YOUR_WIFI_NAME";
const char* PASS = "YOUR_WIFI_PASSWORD";
const char* BROKER = "192.168.1.10";
RCSwitch rf;
WiFiClient net;
PubSubClient mqtt(net);
struct Sensor { unsigned long code; const char* name; };
// Read each sensor's code from the Serial Monitor once, then fill in this list.
Sensor sensors[] = { {1234567UL, "front_door"}, {2345678UL, "back_door"}, {3456789UL, "garage_pir"} };
const int N = sizeof(sensors) / sizeof(sensors[0]);
unsigned long lastCode = 0, lastTime = 0;
void discovery() {                                  // tells Home Assistant each sensor exists
  for (int i = 0; i < N; i++) {
    String topic = String("homeassistant/binary_sensor/rf_") + sensors[i].name + "/config";
    String msg = String("{\"name\":\"") + sensors[i].name + "\",\"state_topic\":\"home/rf/" + sensors[i].name +
                 "\",\"payload_on\":\"ON\",\"unique_id\":\"rf_" + sensors[i].name + "\",\"off_delay\":30}";
    mqtt.publish(topic.c_str(), msg.c_str(), true);
  }
}
void connectMqtt() {
  while (!mqtt.connected()) { if (mqtt.connect("rf-bridge")) discovery(); else delay(2000); }
}
void setup() {
  Serial.begin(115200);
  rf.enableReceive(27);
  WiFi.begin(SSID, PASS);
  while (WiFi.status() != WL_CONNECTED) delay(300);
  mqtt.setServer(BROKER, 1883);
  mqtt.setBufferSize(512);
}
void loop() {
  connectMqtt(); mqtt.loop();
  if (rf.available()) {
    unsigned long code = rf.getReceivedValue();
    rf.resetAvailable();
    if (code == lastCode && millis() - lastTime < 2000) return;       // ignore repeats of the same burst
    lastCode = code; lastTime = millis();
    Serial.print("Code "); Serial.println(code);
    for (int i = 0; i < N; i++) if (sensors[i].code == code) {
      String topic = String("home/rf/") + sensors[i].name;
      mqtt.publish(topic.c_str(), "ON");
    }
  }
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Trigger a sensorMQTT message appears
Home AssistantLists the sensors automatically
Repeated burstsOne event only
Unknown codeIgnored

If it does not work

No codes

Check the antenna and wiring.

Short range

Use a longer wire antenna and power at 5 V through the divider.

Duplicate events

Lengthen the repeat window.

Sensors missing in Home Assistant

Check the broker and discovery topic.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the sensor bridge to Home Assistant?

ESP32 DevKit V1, 433 MHz RF transmitter and receiver pair, 5 V 2 A USB adapter and Resistor 10 kΩ × 3.

How long does the sensor bridge to Home Assistant take to build?

About 180 minutes for a intermediate maker, in 7 steps.

How do I know the sensor bridge to Home Assistant works?

Trigger a sensor: MQTT message appears. Home Assistant: Lists the sensors automatically. Repeated bursts: One event only.

No codes: what should I check?

Check the antenna and wiring.

Short range: what should I check?

Use a longer wire antenna and power at 5 V through the divider.

Duplicate events: what should I check?

Lengthen the repeat window.

Sensors missing in Home Assistant: what should I check?

Check the broker and discovery topic.