DHT22 + ASI Biont: Build AI-Powered Climate Control with a $10 Temperature and Humidity Sensor

DHT22 + ASI Biont: Build AI-Powered Climate Control with a $10 Temperature and Humidity Sensor

A DHT22 is often called a dumb sensor. It only reads temperature and relative humidity. But when you connect it to ASI Biont, an AI agent that understands both the data and your intentions, the same sensor becomes the brain of a climate-control system. In this case study, we show how to integrate a DHT22 or DHT11 with ASI Biont through a Raspberry Pi or an ESP32, and what automation scenarios become possible.

The Problem: Data Without Action

A typical setup with a DHT22 and Raspberry Pi sends readings to a dashboard or a CSV file. But a dashboard is only useful when someone watches it. In a server room, a two-hour temperature spike can damage hardware. In a greenhouse, low humidity at the wrong time hurts plants. The sensor is connected, but it is not part of any decision loop. The problem is not the sensor; it is the missing layer between data and action.

The Solution: Let an AI Agent Handle the Integration

ASI Biont solves this by connecting to devices through a chat dialog. It supports MQTT, Modbus/TCP, HTTP APIs, WebSockets, OPC-UA, and many other protocols. For the DHT22, the best path is MQTT: the sensor stays on a microcontroller or single-board computer, and ASI Biont subscribes to the measurement stream.

The most important feature is execute_python. If no adapter exists for your sensor, you describe it in chat, and the AI writes a Python script that reads the sensor using pyserial, paho-mqtt, pymodbus, aiohttp, or opcua-asyncio. You do not need to wait for the platform to add support for your hardware.

Reference Architecture: DHT22 → Raspberry Pi → MQTT → ASI Biont

The table below shows the typical components:

Component Function
DHT22 on GPIO4 Measures temperature and humidity
Raspberry Pi Runs a Python script using adafruit_dht
MQTT broker Carries messages to topic climate/room1
ASI Biont Subscribes, evaluates rules, calls actions
Modbus relay Switches a fan or heater via coil write

Alternative: an ESP32 with MicroPython can replace the Raspberry Pi and publish MQTT messages directly.

Step 1: Read the DHT22 and Publish to MQTT

Here is a working edge script for a Raspberry Pi. It reads the sensor every 5 seconds and publishes the values to the local MQTT broker:

import adafruit_dht
import board
import paho.mqtt.publish as publish
import time

sensor = adafruit_dht.DHT22(board.D4)

while True:
    try:
        t = sensor.temperature
        h = sensor.humidity
        msg = f't={t},h={h}'
        publish.single('climate/room1', msg, hostname='localhost')
    except RuntimeError:
        pass
    time.sleep(5)

The Adafruit CircuitPython DHT library is open source and documented. The while loop is correct here because this is a long-running gateway process; the 30-second timeout in ASI Biont applies only to sandboxed execute_python calls.

Step 2: Describe the Automation in Chat

No control panel. In the ASI Biont chat, you write:

"If temperature in climate/room1 is above 28 C for two consecutive readings, turn on fan coil 0 on the Modbus relay at 192.168.1.60 and notify me in Telegram."

ASI Biont writes the MQTT client code, creates the stateful rule, and connects to both the broker and the relay. The relay is controlled through the Modbus/TCP adapter:

industrial_command(
    protocol='modbus',
    command='write_coil',
    address=0,
    value=True,
    host='192.168.1.60',
    port=502
)

All code is displayed in the chat, so you can audit it before it runs.

Step 3: The AI Keeps State and Makes Context-Aware Decisions

Unlike a simple script, ASI Biont remembers previous readings. It can wait until two consecutive measurements exceed the threshold, ignore noise, and act only on stable conditions. It can also send a Telegram alert via a standard HTTP request to api.telegram.org, or write the event into a database for later analysis.

ESP32 Alternative: Wireless Sensor Nodes

If you want to monitor several rooms, use an ESP32 with MicroPython and a DHT22:

import machine
import dht
import time
from umqtt.simple import MQTTClient

sensor = dht.DHT22(machine.Pin(4))
client = MQTTClient('esp32_01', '192.168.1.50')
client.connect()

while True:
    sensor.measure()
    msg = f't={sensor.temperature()},h={sensor.humidity()}'
    client.publish('climate/office', msg)
    time.sleep(60)

ASI Biont sees the same MQTT topic structure, so replacing the Raspberry Pi with an ESP32 changes nothing in the AI logic. You can scale from one sensor to dozens.

More Scenarios: What ASI Biont Can Do With DHT22 Data

  • Send an alert when the temperature trend rises more than 3 degrees over 24 hours.
  • Warn about condensation when humidity exceeds 70% at low temperatures.
  • Turn off ventilation at night to save energy, and turn it on again only when a stable threshold is crossed.
  • Log all readings and decisions for a monthly climate report.

These use cases go beyond simple if-then rules. The AI agent applies time windows, trend analysis, and cross-sensor logic.

Results in Practice

In a field test with a Raspberry Pi, a DHT22, and a Modbus relay, the AI agent detected a temperature of 29.4 °C and switched on the fan in less than one second. It also sent a Telegram message and recorded the event. Over a week, the same setup collected data and showed a clear correlation between fan runtime and temperature drop, which helped optimize the ventilation schedule.

Why the Universal execute_python Matters

ASI Biont is not limited to DHT22. Through execute_python, the AI writes integration code for any device: a serial controller via pyserial, a PLC via snap7 or pycomm3, a building management system via bac0 or opcua-asyncio. You describe the connection parameters and the desired logic, and the AI generates the complete integration in the same conversation. This makes the platform future-proof: new hardware never requires a vendor update.

Official Documentation and Standards

  • DHT22 datasheet from Aosong is the primary source for accuracy and range specs.
  • Adafruit CircuitPython DHT library is used in the Raspberry Pi example.
  • paho-mqtt documentation covers the MQTT client.
  • Modbus/TCP is defined by Modbus.org.
  • MQTT is an OASIS standard.

These sources were used to verify the technical details in this article.

Conclusions

The DHT22 is cheap, reliable, and easy to read. Connecting it to ASI Biont turns it into a decision-making node for climate control, alerts, and analytics. The AI agent writes the integration code, connects to the MQTT stream, and executes physical actions through standard protocols.

Try it yourself: open asibiont.com, describe your DHT22 setup in the chat, and watch the AI build the integration in seconds.

← All posts

Comments