Welcome to Raspberry Pi 5 repository
4. Temperature and Humidity Sensor
OpenClaw Temperature and Humidity Sensor Tutorial
Before starting, please complete [01-Peripheral Hardware Configuration], [02-OpenClaw API-KEY Configuration], [03-OpenClaw Model Switching], [04-AI Voice Interaction Configuration], and [05-Three Dialogue Configuration Tests] in the
Preparation Before Usedirectory. If you are only using TUI/WhatsApp, you can skip04. This article assumes the basic environment is ready and only covers DHT-related content.
1. Tutorial Objectives
This article demonstrates OpenClaw's natural language control capability through DHT temperature and humidity sensors. After completing this tutorial, readers will be able to:
- Understand the basic approach to reading temperature and humidity with OpenClaw
- Communicate with OpenClaw via WhatsApp, TUI, and voice commands
- Complete four DHT cases: single reading, comfort judgment, threshold alert, OLED display
- Understand the complete chain from "user question" to "sensor reading" and "result feedback"
2. Hardware Preparation
- OpenClaw main control board
- DHT temperature and humidity sensor
[default DHT11] [Optional] OLED display screen[Optional] Microphone module- Wiring diagram

3. Software Preparation
Code entry points used in this tutorial:
- Low-level driver code:
/home/pi/hardware_hal_demo/ - Temperature and humidity reading command:
/home/pi/hardware_hal_demo/dht - Temperature and humidity display with OLED:
/home/pi/hardware_hal_demo/dht_oled - Voice entry:
/home/pi/voice_to_openclaw/src/main.py
The dht tool already supports the following capabilities:
- Read current temperature and humidity
- Output results in
jsonortextformat - Use
mockfake data for local joint debugging
dht_oled #Display temperature and humidity data on OLEDdht #Feedback `json` resultIf you want to display temperature and humidity results directly on OLED, you can also use dht_oled.
Note: If you want to write your own tutorial to read temperature and humidity data from the Python driver library, it is recommended to read DHT data at a two-second interval, as DHT sensors are more suitable for 2s sampling
4. Testing Temperature and Humidity Reading
Before starting this tutorial, please complete an openclaw tui basic conversation self-check first; if you haven't done this yet, see [05-Three Dialogue Configuration Tests]. After confirming OpenClaw can respond normally, proceed with the DHT-specific test.
Enter TUI by typing the following in the terminal:
xxxxxxxxxxopenclaw tui
You can try the following in the terminal:
- Read current temperature and humidity
- What is the current environmental humidity
- Help me judge if the current environment is comfortable
- Remind me if the temperature is too high

5. Three Ways to Communicate with OpenClaw
| Method | Suitable Scenario | Advantages | Suggested Use |
|---|---|---|---|
| Remote control, classroom demonstration | Easy to connect, suitable for multi-person experience | Demonstrate "remote natural language control" | |
| TUI | Local debugging, command verification | Most direct, easiest to troubleshoot | First to get the control link working |
| Voice Code | Voice interaction, complete AI experience | Closest to real conversation experience | As the final demonstration solution |
If you have the optional AI voice module + speaker, the TUI and WhatsApp conversations need to broadcast OpenClaw's replies. You can run the following program in the terminal. This is not needed for AI voice module conversations.
- Modify the TTS enable parameter
xxxxxxxxxx/home/pi/voice_to_openclaw/.env
xxxxxxxxxxENABLE_TTS=true # This parameter controls whether to broadcast replies. After saving, run the program below in the terminal.- Terminal input
xxxxxxxxxxcd ~/voice_to_openclawsource .venv/bin/activatepython -m src.openclaw_session_tts
5.1 WhatsApp Solution
For WhatsApp integration steps, please refer directly to [05-Three Dialogue Configuration Tests]. This section only includes dialogue examples suitable for the DHT tutorial.
After creating, you can converse directly, for example:
- Read current temperature and humidity
- Judge if it's currently hot
- Remind me if the humidity is too low

5.2 TUI Solution
If you have already completed the TUI self-check from chapter 0, simply type the following command in the terminal to continue the conversation:
xxxxxxxxxxopenclaw tui
5.3 Voice Code Solution
xxxxxxxxxxRequires optional AI voice interaction module + speaker
For voice module installation, environment configuration, and basic wake-up flow, please refer directly to [04-AI Voice Interaction Configuration].
You need to say "Hi,yahboom" to wake up for conversation.
After waking up, you can directly speak control content, for example:
- What is the current temperature
- Help me read the humidity
- Tell me if it's too hot and humid

6. Comprehensive Cases
Note: All demonstrations below use the openclaw tui method for conversation. You can also choose WhatsApp or voice to complete.
6.1 Case 1: Single Reading
Experiment Objective
Get current temperature and humidity once for the most basic environmental sampling.
Effect Description
After OpenClaw receives the command, it will call the DHT driver to read current temperature and humidity and return the results to the user in natural language.
Example Commands
- Read current temperature and humidity
- What is the current indoor temperature
- Help me check the current humidity
6.2 Case 2: Comfort Judgment
Experiment Objective
Have OpenClaw make a simple judgment about the current environment after reading the data.
Effect Description
Besides directly reporting numbers, OpenClaw can also roughly judge "too hot", "too cold", "too dry", "too humid" based on temperature and humidity, making the results closer to natural conversation.
Example Commands
- Help me judge if the current environment is comfortable
- Is the current temperature and humidity suitable for prolonged office work
- Give me a short evaluation based on temperature and humidity
6.3 Case 3: Threshold Alert
Experiment Objective
Have OpenClaw give an alert when temperature or humidity exceeds a set range.
Effect Description
When the temperature is too high, too low, or the humidity is too high or too low, OpenClaw can directly output alert information, and can also link with RGB lights for more obvious feedback.
Example Commands
- Remind me if the temperature exceeds 30 degrees
- If humidity is below 40%, prompt that the air is too dry
- Has the alert condition been reached now
Extensible Play
- Link with RGB for red, yellow, blue three-color alerts
- Link with OLED to display alert text
- Add a buzzer for stronger alerts
6.4 Case 4: OLED Display
Experiment Objective
Display the just-read temperature and humidity results directly on OLED, forming a complete data display chain.
Effect Description
After OpenClaw completes an environmental sampling, it can not only reply the results to the user but also synchronously write temperature and humidity to the OLED screen, forming a complete "reading + display" effect.
Example Commands
- Read current temperature and humidity and display on OLED
- Write temperature and humidity to the screen
- Make a simple temperature and humidity display page
Extensible Play
- Periodically refresh OLED content
- Make a temperature and humidity dashboard
- Link with the weather station project to form a complete application