ESP32 & ASI Biont: How to Build an AI-Powered Smart Thermostat in 10 Minutes

From Dumb Sensors to Smart Decisions

I’ve been tinkering with ESP32 for years — temperature sensors, motion detectors, smart plugs. The problem? Every sensor just dumps raw numbers. You either stare at a dashboard all day or write brittle scripts that break when you add a new device. That’s where ASI Biont comes in. Instead of coding a full backend, you tell the AI agent: “Monitor my DHT22, send me a Telegram alert if temp goes above 30°C, and log hourly averages to a Google Sheet.” It writes the integration in seconds.

How ASI Biont Connects to ESP32

ASI Biont doesn’t have a clunky dashboard with "Add Device" buttons. Everything happens through chat. The AI has 14 native connection methods — for ESP32, the most common are:

Method Use Case Key Library
MQTT Cloud-connected ESP32 (WiFi + sensor) paho-mqtt
Hardware Bridge ESP32 connected via USB (COM port) pyserial
HTTP API ESP32 with a simple REST server aiohttp

I’ll show you the MQTT path — it’s the fastest way to get real data flowing.

Step-by-Step: ESP32 + DHT22 → MQTT → ASI Biont → Telegram

1. Flash ESP32 with MQTT Firmware

Upload this MicroPython script to your ESP32 using Thonny or esptool:

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

# WiFi credentials
SSID = "YourWiFi"
PASSWORD = "YourPassword"

# MQTT broker (Mosquitto, HiveMQ, or any public broker)
BROKER = "broker.hivemq.com"
TOPIC = "home/temperature"

# Sensor on GPIO4
sensor = dht.DHT22(Pin(4))

wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, PASSWORD)

while not wlan.isconnected():
    time.sleep(0.5)

client = MQTTClient("esp32_01", BROKER)
client.connect()

while True:
    sensor.measure()
    temp = sensor.temperature()
    hum = sensor.humidity()
    payload = f'{{"temp": {temp}, "hum": {hum}}}'
    client.publish(TOPIC, payload)
    time.sleep(60)

This publishes JSON like {"temp": 25.3, "hum": 60.1} every minute.

2. Tell ASI Biont to Listen

In the chat, simply type:

"Connect to MQTT broker broker.hivemq.com, subscribe to topic home/temperature, parse the JSON, and if temp > 30°C send me a Telegram message with the current reading. Also log every reading to a local CSV file."

ASI Biont will automatically generate and execute this Python script in its sandbox:

import paho.mqtt.client as mqtt
import json
import csv
from datetime import datetime
import os

TELEGRAM_BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
TELEGRAM_CHAT_ID = os.getenv("TELEGRAM_CHAT_ID")
CSV_FILE = "temperature_log.csv"

def on_message(client, userdata, msg):
    data = json.loads(msg.payload)
    temp = data["temp"]
    hum = data["hum"]
    now = datetime.now().isoformat()

    # Log to CSV
    with open(CSV_FILE, "a") as f:
        writer = csv.writer(f)
        writer.writerow([now, temp, hum])

    # Alert if too hot
    if temp > 30:
        import requests
        text = f"🔥 Temp alert at {now}: {temp}°C"
        requests.post(
            f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage",
            json={"chat_id": TELEGRAM_CHAT_ID, "text": text}
        )

client = mqtt.Client()
client.on_message = on_message
client.connect("broker.hivemq.com", 1883)
client.subscribe("home/temperature")
client.loop_forever()

No manual coding. You just describe what you want, and the AI writes the bridge code.

3. Real-Time Alerts in Telegram

Once the script runs, you’ll get instant Telegram notifications when thresholds are exceeded. The AI also keeps a conversation — you can ask:

"What was the max temperature in the last hour?"

And it will query the CSV file or a database (if you asked it to store there).

Going Further: Hardware Bridge for USB-Connected ESP32

If your ESP32 is connected via USB (e.g., for serial monitoring), ASI Biont uses bridge.py — a small Python app you run on your PC. The AI sends commands like:

industrial_command(protocol="serial://", command="serial_write_and_read", data="HELP\n", port="COM3", baud=115200)

Bridge writes HELP to the COM port and returns the response. You can read sensor values, control relays, or flash firmware — all from the chat.

Why This Changes Everything

  • No backend to build: The AI writes and runs the integration code live.
  • No vendor lock-in: You can switch from MQTT to HTTP or Modbus in one sentence.
  • Extensible: Add a new sensor? Just tell the AI: "Also subscribe to topic home/motion and alert if motion detected after 10 PM."

Real-World Pitfalls (Avoid These)

  1. MQTT broker doesn’t persist messages — if your script starts later, it misses old data. Use retain=True on the ESP32 publisher.
  2. Sandbox timeout of 30 seconds — don’t write while True: loops in execute_python. The MQTT script above uses loop_forever() which is allowed only in the background listener mode (AI handles this).
  3. Telegram bot tokens — store them as environment variables in the ASI Biont dashboard, not hardcoded.

Conclusion

ESP32 is a $5 board. ASI Biont turns it into an intelligent edge node that not only collects data but reacts, alerts, and optimizes — all through natural language. No more glue code, no more brittle cron jobs.

Try it yourself: Go to asibiont.com, create a free account, tell the AI agent "Connect to my ESP32 via MQTT and send me alerts on Telegram", and watch it work in under a minute.

← All posts

Comments