SHT41 ESPHome¶
A simple ESPHome configuration for reading temperature and humidity from an SHT41 sensor and publishing the data over MQTT.
What you need for this specific project¶
- an SHT41 sensor (and extra wires depending on your model)
Pin layout¶
Note
ESP32 boards allow flexible I2C pin assignment. My pin layout isn't set in stone, you can change it.
| ESP32 Pin | SHT41 Pin | Description |
|---|---|---|
| 3V3 | VIN | Power |
| GND | GND | Ground |
| GPIO3 | SCL | I2C Clock |
| GPIO2 | SDA | I2C Data |
ESPHome¶
ESPHome supports OTA (Over the air) updates, so I don't need to touch it at all to update the code.
However, it uses YAML not .ino code so that changes.
This code publishes to the MQTT topic sensors/sht41/humidity and sensors/sht41/temperature. Adjust it according to your needs.
This code takes readings from the SHT41 sensor every 2 seconds continuously.
Variables
To change the topic it publishes to, change topic_prefix under mqtt: and the two state_topic: under sensor:
If you have a different model, change the board to match.
Replace ssid and password with your WiFi SSID and password.
Replace server_lan_ip with your servers local IP address.
If you deviated from my pin layout, change scl and sda here too.
esphome:
name: sht41-c3
friendly_name: SHT41 ESP32-C3
esp32:
board: nologo_esp32c3_super_mini
framework:
type: esp-idf
logger:
#api:
# encryption:
# key: !secret api_encryption_key
ota:
- platform: esphome
password: ""
wifi:
ssid: "ssid"
password: "pass"
ap:
ssid: "SHT41-C3 Fallback"
password: "esp32c3test"
captive_portal:
mqtt:
broker: server_lan_ip
port: 1883
topic_prefix: sensors
client_id: sht41-c3
i2c:
sda: 2
scl: 3
scan: true
sensor:
- platform: sht4x
temperature:
name: "temperature"
id: sht41_temp
state_topic: sensors/sht41/temperature
humidity:
name: "humidity"
id: sht41_hum
state_topic: sensors/sht41/humidity
address: 0x44
update_interval: 2s
After editing the YAML, use esphome run <filename>.yaml to push the updates.
Expected output¶
My bad, I did not record data over Serial. So your only point of reference is live data over MQTT.
Monitoring & Troubleshooting¶
If something isn't going according to plan, you can open up the Serial Monitor in Arduino IDE and see what may cause the issue.
Also, you can view the Mosquitto and Telegraf containers logs to check there too.