A complete LoRa to MQTT gateway system for Home Assistant. This repository includes both the Raspberry Pi gateway add-on and a production-ready ESP32 water sensor bridge application demonstrating deep sleep power management, button wake, and seamless Home Assistant integration.
A universal LoRa receiver that runs on your Raspberry Pi with a Waveshare SX1262 HAT. Receives LoRa packets from any ESP32/Arduino device and publishes them to MQTT with automatic JSON parsing.
π Location: sx1262_lora_gateway/
A complete, production-ready application for reading Tuya ME201W water sensors via serial and transmitting via LoRa. Features advanced power management with deep sleep, button wake for display, and complete Home Assistant integration.
π Location: esp32_tuya_me201ws_serial_reader/
Simple test applications for validating LoRa communication during initial setup.
π Location: esp32_tests/
- π― Universal Compatibility: Works with any SX126x LoRa device (SX1261, SX1262, SX1268)
- π‘ Flexible Configuration: Full control over LoRa parameters (frequency, SF, BW, CR, sync word)
- π Auto JSON Parsing: Automatically creates MQTT topics from nested JSON structures
- π Signal Monitoring: RSSI and SNR reporting for every packet
- π Home Assistant Native: Seamless MQTT integration with auto-discovery support
- οΏ½ Low Power: ESP32 deep sleep with wake-on-serial and button wake
- π§ Production Ready: Complete working example with the ME201W water sensor
Gateway (Receiver):
- Raspberry Pi (3/4/5 or Zero 2 W)
- Waveshare SX1262 LoRaWAN HAT (915MHz for US)
- Home Assistant OS or Supervised installation
Transmitter (Example):
- Heltec WiFi LoRa 32 V3 (ESP32-S3 + SX1262)
- Tuya ME201W water sensor (optional, for full water sensor bridge)
Transmitter (Example):
- Heltec WiFi LoRa 32 V3 (ESP32-S3 + SX1262)
- Tuya ME201W water sensor (optional, for full water sensor bridge)
-
Install the Gateway Add-on
Click the button at the top of this page or manually add this repository:
- Go to Settings β Add-ons β Add-on Store (three dots menu) β Repositories
- Add:
https://github.com/DShaeffer/homeassistant-addon-sx1262 - Find SX1262 LoRa Gateway and click Install
-
Configure LoRa Parameters
Set your region-specific frequency and LoRa parameters (must match ESP32 settings):
lora_frequency: 915.0 # US: 915, EU: 868 lora_spreading_factor: 7 # SF7-SF12 lora_bandwidth: 125000 # 125kHz lora_sync_word: 0x12 # Must match ESP32
-
Start the Gateway
Click Start and check the logs for "LoRa receiver initialized"
-
Program Your ESP32
- For testing: Use Heltec_Gateway_Test
- For production: Use ME201W Water Sensor Bridge
-
Add Sensors to Home Assistant
The gateway auto-creates MQTT topics. Add them to your
configuration.yaml(see examples below)
The gateway automatically creates MQTT topics from JSON payloads.
Example: ESP32 sends this JSON:
{
"water": {
"level": 85.2,
"percent": 76,
"state": 0
},
"batt": {
"voltage": 4.15,
"unit": 95
}
}Gateway creates these topics:
lora/gateway/water/levelβ85.2lora/gateway/water/percentβ76lora/gateway/water/stateβ0lora/gateway/batt/voltageβ4.15lora/gateway/batt/unitβ95lora/gateway/rssiβ-35.2(signal strength)lora/gateway/snrβ9.75(signal quality)
Add these sensors to your configuration.yaml:
mqtt:
sensor:
# Water Level Sensors
- name: "Water Tank Level"
state_topic: "lora/gateway/water/level"
unit_of_measurement: "cm"
device_class: distance
icon: mdi:water-well
- name: "Water Tank Percent"
state_topic: "lora/gateway/water/percent"
unit_of_measurement: "%"
icon: mdi:water-percent
# Battery Sensors
- name: "Water Sensor Battery"
state_topic: "lora/gateway/batt/voltage"
unit_of_measurement: "V"
device_class: voltage
- name: "Water Sensor Battery Level"
state_topic: "lora/gateway/batt/unit"
unit_of_measurement: "%"
device_class: battery
# Signal Quality
- name: "Water Sensor RSSI"
state_topic: "lora/gateway/rssi"
unit_of_measurement: "dBm"
device_class: signal_strength
- name: "Water Sensor SNR"
state_topic: "lora/gateway/snr"
unit_of_measurement: "dB"
icon: mdi:signal-variant
binary_sensor:
# Water Level Alarm
- name: "Water Tank Alarm"
state_topic: "lora/gateway/water/state"
payload_off: "0"
payload_on: "1"
device_class: problemAfter restarting Home Assistant, your sensors will appear and can be added to your dashboard.
- Gateway Add-on Documentation - Complete gateway configuration and troubleshooting
- ME201W Water Sensor Bridge - Production ESP32 application with deep sleep
- ESP32 Test Sketches - Simple examples for testing LoRa communication
- Changelog - Version history
- Check Frequency: US=915MHz, EU=868MHz - must match exactly between gateway and ESP32
- Verify Sync Word: Must be identical on both devices (default:
0x12) - Check Distance: Start with devices < 10 meters apart for initial testing
- Monitor Logs: Gateway logs show RSSI even when packets fail to decode
- Check Antennas: Ensure properly connected on both devices
- Increase TX Power: Try 22 dBm on ESP32 (within legal limits)
- Increase Spreading Factor: SF9 or SF10 for longer range (slower data rate)
- Line of Sight: Obstacles significantly reduce range
- Check Serial Monitor: Verify LoRa initialization succeeded
- Verify Pin Configuration: Heltec V3 uses specific pins (see code)
- Check Power: Low battery can prevent LoRa transmission
See the complete troubleshooting guide for more details.
This system is perfect for:
- π° Water Tank Monitoring - Track levels remotely with low power consumption
- π‘οΈ Environmental Sensors - Temperature, humidity, soil moisture
- π Battery-Powered IoT - Deep sleep enables months of battery life
- π‘ Smart Home Sensors - Door/window sensors, motion detectors
- π Agricultural Monitoring - Soil conditions, weather stations
- π Alarm Systems - Remote notifications without WiFi/cellular
Anything that needs wireless sensing beyond WiFi range with low power consumption!
homeassistant-addon-sx1262/
βββ README.md # This file
βββ repository.json # HA add-on repository config
β
βββ sx1262_lora_gateway/ # Raspberry Pi Gateway Add-on
β βββ README.md # Complete gateway documentation
β βββ CHANGELOG.md # Version history
β βββ config.yaml # Add-on configuration schema
β βββ Dockerfile # Container build
β βββ lora_gateway.py # Main gateway application
β βββ LoRaRF/ # LoRa radio library
β
βββ esp32_tuya_me201ws_serial_reader/ # Production Water Sensor Bridge
β βββ README.md # Complete bridge documentation
β βββ esp32_tuya_me201ws_serial_reader.ino # Main application (~1100 lines)
β
βββ esp32_tests/ # Test & Development Sketches
βββ README.md # Testing guide
βββ Heltec_Gateway_Test/ # Simple LoRa test (recommended)
βββ LoRa_TX_Test_Simple/ # Basic transmission test
βββ [other test sketches]/ # Various diagnostic tools
The included ESP32 application demonstrates production-level code:
- β Deep Sleep Power Management - Wake on UART activity from sensor
- β Button Wake - Press PRG button to view stats on OLED display
- β Reboot-to-Sleep Strategy - Eliminates deep sleep crashes
- β Complete Data Validation - Only transmits when full sensor data received
- β LoRa Transmission - Reliable 915MHz SF7 communication
- β OLED Display - Shows sensor data and statistics on demand
- β JSON Payload - Structured data for easy Home Assistant integration
- β Signal Reporting - RSSI and SNR visible in Home Assistant
Typical power consumption:
- Deep sleep: ~2-5mA
- Active transmission: ~100-120mA for <1 second
- Display active: ~50-80mA for 30 seconds
With solar charging and 18650 battery, this system can run indefinitely!
Contributions welcome! Please open an issue or pull request.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
MIT License - Free to use and modify
- Built with LoRaRF Python Library
- Designed for Waveshare SX1262 LoRa HAT
- Compatible with Heltec, TTGO, and generic SX126x boards
- Tested with Tuya ME201W ultrasonic water sensors
## Features