Wi-Fi, MQTT, BME280/BME680 Integration & Power Management
The Smart IoT Sensor is a power-efficient device built using the XIAO ESP32C6 tiny board. It integrates Wi-Fi connectivity, MQTT messaging, environmental sensing with BME280/BME680 sensors, and robust power management, making it an ideal solution for smart home and IoT applications.
The Smart IoT Sensor can be easily integrated with Home Assistant for real-time monitoring and automation.
The sensor publishes data to an MQTT broker in the following JSON format:
{
"ID": "7i29r9k9ltaxmbev",
"RSSI": -54,
"battery_voltage": 4.13,
"temperature": "24.28",
"humidity": "29.32",
"pressure": "999.54",
"connection_duration_ms": 1672
}
A battery connection schematic.
Voltage divider schematic (if battery voltage monitoring is required).
Note: This solution continuously consumes some current from the battery but is functional for voltage monitoring.
This build was developed and tested with ESP-IDF v5.3.1 Follow this instruction to install it. It is required.
Configure the sensor using the following steps:
idf.py menuconfig
Then go to XIAO Sensor Configuration
Wi-Fi Configuration: Set up your Wi-Fi credentials to enable network connectivity.
MQTT Configuration: Connect the sensor to your MQTT server by providing the necessary broker details.
Battery Check (Optional): Enable battery voltage monitoring if power management insights are needed.
BME Sensor Configuration (Optional): Choose between BME280 and BME680 sensors based on your requirements.
Power Management Configuration: Set up wakeup duration, which is the duration in seconds that the device will remain in deep sleep before waking up.
The sensor is housed in a customizable 3D-printed enclosure. STL files are available for download and 3D printing. To customize a model use a FreeCAD project. A 3D preview is available here.
When printing, it is recommended to orient the parts on the hotbed as shown in the picture:
Enclosure assembly steps:
Pull down until it can't go any farther
Integrate the Smart IoT Sensor with Home Assistant by following these steps:
configuration.yaml
: Add the following configuration to your configuration.yaml
file to define the sensor entities.---
mqtt:
sensor:
- name: "Sensor RSSI 7i29r9k9ltaxmbev"
device_class: signal_strength
state_topic: "xiao/sensor/7i29r9k9ltaxmbev/data"
unit_of_measurement: "dBm"
value_template: "{{ value_json.RSSI }}"
- name: "Sensor Temperature 7i29r9k9ltaxmbev"
device_class: temperature
state_topic: "xiao/sensor/7i29r9k9ltaxmbev/data"
unit_of_measurement: "°C"
value_template: "{{ value_json.temperature }}"
- name: "Sensor Humidity 7i29r9k9ltaxmbev"
device_class: humidity
state_topic: "xiao/sensor/7i29r9k9ltaxmbev/data"
unit_of_measurement: "%"
value_template: "{{ value_json.humidity }}"
- name: "Sensor Pressure 7i29r9k9ltaxmbev"
device_class: pressure
state_topic: "xiao/sensor/7i29r9k9ltaxmbev/data"
unit_of_measurement: "hPa"
value_template: "{{ value_json.pressure }}"
- name: "Sensor Battery Voltage 7i29r9k9ltaxmbev"
device_class: voltage
state_topic: "xiao/sensor/7i29r9k9ltaxmbev/data"
unit_of_measurement: "V"
value_template: "{{ value_json.battery_voltage }}"
- name: "Sensor Connection Duration 7i29r9k9ltaxmbev"
device_class: duration
state_topic: "xiao/sensor/7i29r9k9ltaxmbev/data"
unit_of_measurement: "ms"
value_template: "{{ value_json.connection_duration_ms }}"
---
type: entities
entities:
- entity: sensor.sensor_temperature_7i29r9k9ltaxmbev
icon: mdi:thermometer-low
secondary_info: last-changed
name: Temperature
- entity: sensor.sensor_humidity_7i29r9k9ltaxmbev
name: Humidity
- entity: sensor.sensor_pressure_7i29r9k9ltaxmbev
name: Pressure
- entity: sensor.sensor_rssi_7i29r9k9ltaxmbev
icon: mdi:wifi-strength-3
secondary_info: none
name: RSSI
- entity: sensor.sensor_battery_voltage_7i29r9k9ltaxmbev
icon: mdi:battery-80
secondary_info: none
name: Battery
- entity: sensor.sensor_connection_duration_7i29r9k9ltaxmbev
name: Connection Duration
title: Sensor 7i29r9k9ltaxmbev
Follow these steps to set up your Smart IoT Sensor:
Clone the Repository
git clone https://github.com/BegoonLab/xiao-esp32c6-wifi-sensor
cd xiao-esp32c6-wifi-sensor
git submodule update --init --recursive
Install Dependencies
Ensure you have the necessary tools and libraries installed. Refer to the Software section for more details.
Configure the Sensor
Edit the configuration files to set your Wi-Fi and MQTT credentials.
Build and Flash
Compile the firmware and flash it to your XIAO ESP32C6 board.
Assemble the Hardware
Connect the BME sensor and battery as per the schematics. 3D print the enclosure and assemble the components.
Deploy and Monitor
Power on the sensor and monitor the data through your MQTT broker and Home Assistant.
Install ESP-IDF
Follow the ESP-IDF Getting Started Guide to set up the development environment.
Configure the Project
idf.py menuconfig
Build and Flash
idf.py build
idf.py -p <TARGET_PORT> flash
ZigBee can be activated in the menu:
idf.py menuconfig
Navigate to XIAO Sensor Configuration
→ Select Sensor Connection Type
→ ZigBee
.
Next, go to Component config
→ Zigbee
→ Zigbee Enable
and set it to ON. Then, go to XIAO Sensor Configuration
→ ZigBee Configuration
and set a Sensor ID
.
Build and flash the firmware. After that, the sensor will be ready and will begin commissioning.
To add the sensor to Home Assistant: go to Settings
→ Devices & Services
→ Devices
→ Add Device
→ Add Zigbee device
. Once completed, your sensor will appear on the Devices page:
Contributions are welcome! Please follow these steps:
Fork the Repository
Create a Feature Branch
git checkout -b feature/YourFeature
Commit Your Changes
Push to the Branch
git push origin feature/YourFeature
Open a Pull Request
This project is licensed under the MIT License. All rights reserved.