I2C Sensors Meet AI: How to Automate Temperature, Humidity, and Pressure Monitoring with ASI Biont

Why Connect I2C Devices to an AI Agent?

If you've ever wired up a BME280 or DHT22 sensor to an ESP32 or Raspberry Pi, you know the drill: write code, flash firmware, stare at serial monitor output, build a dashboard, set up alerts. It works — but it's manual. Every time you add a new sensor or change logic, you edit code, reflash, test. That's hours of repetitive work.

ASI Biont changes this. Instead of hardcoding every rule, you connect your I2C bus to an AI agent. The agent reads sensor values, analyzes trends, and triggers actions — all through chat. You describe what you want ("send me a Telegram alert if humidity drops below 30% and turn on the relay") and the AI writes the integration code on the fly.

How ASI Biont Connects to I2C Devices

There is no single "I2C plugin" — ASI Biont is protocol-agnostic. Depending on your hardware, you choose one of these connection methods:

Hardware Connection Method How It Works
ESP32 / Arduino (USB) Hardware Bridge (COM port) Run bridge.py on your PC, connect to ASI Biont via WebSocket. AI sends serial_write_and_read commands to read/write I2C registers through the microcontroller's serial interface.
Raspberry Pi (local) SSH via paramiko AI writes a Python script that runs on the Pi via SSH, using smbus2 or adafruit-circuitpython libraries to read I2C sensors directly.
Any device with MQTT MQTT via paho-mqtt ESP32 publishes sensor data to a broker (e.g., Mosquitto). AI subscribes to the topic, analyzes values, and publishes control commands back.

The key insight: you don't need to write the integration code yourself. You describe the hardware and goal in the chat, and ASI Biont generates the Python script (for execute_python or bridge) that handles the connection.

Concrete Example: ESP32 + BME280 + ASI Biont via MQTT

Hardware Setup

  • ESP32 (any board with I2C)
  • BME280 sensor (temperature, humidity, pressure)
  • MQTT broker (e.g., Mosquitto running on a Raspberry Pi or cloud)

Step 1: ESP32 Firmware

Flash this MicroPython code to the ESP32. It reads BME280 every 10 seconds and publishes JSON to MQTT.

import network
import time
import ujson
from machine import Pin, I2C
import bme280
from umqtt.simple import MQTTClient

# Wi-Fi
wifi = network.WLAN(network.STA_IF)
wifi.active(True)
wifi.connect('your_SSID', 'your_PASS')
while not wifi.isconnected():
    time.sleep(1)

# I2C
i2c = I2C(scl=Pin(22), sda=Pin(21), freq=100000)
bme = bme280.BME280(i2c=i2c)

# MQTT
client = MQTTClient('esp32', 'broker_ip', port=1883)
client.connect()

while True:
    temp, press, hum = bme.values
    payload = ujson.dumps({
        'temperature': float(temp[:-1]),
        'humidity': float(hum[:-1]),
        'pressure': float(press[:-3])
    })
    client.publish(b'sensor/bme280', payload.encode())
    time.sleep(10)

Step 2: Connect ASI Biont to MQTT Broker

In the ASI Biont chat, tell the AI:

"Connect to MQTT broker at 192.168.1.100:1883, subscribe to topic 'sensor/bme280', and send me a Telegram alert if temperature exceeds 30°C or humidity falls below 40%."

The AI generates and runs this sandbox script:

import paho.mqtt.client as mqtt
import json
import requests

def on_message(client, userdata, msg):
    data = json.loads(msg.payload)
    temp = data['temperature']
    hum = data['humidity']

    if temp > 30:
        requests.post('https://api.telegram.org/bot<TOKEN>/sendMessage',
                      json={'chat_id': '<CHAT_ID>', 'text': f'⚠️ Temperature {temp}°C exceeded 30°C'})
    if hum < 40:
        requests.post('https://api.telegram.org/bot<TOKEN>/sendMessage',
                      json={'chat_id': '<CHAT_ID>', 'text': f'⚠️ Humidity {hum}% below 40%'})

client = mqtt.Client()
client.on_message = on_message
client.connect('192.168.1.100', 1883, 60)
client.subscribe('sensor/bme280')
client.loop_forever()

No dashboard. No cron jobs. Just chat.

Alternative: Raspberry Pi + I2C via SSH

If you have a Raspberry Pi with an I2C sensor connected directly (e.g., SHT31), you can let ASI Biont control it via SSH.

Chat prompt:

"Connect to Raspberry Pi at 192.168.1.50 via SSH (user: pi, key: ~/.ssh/id_rsa), read SHT31 sensor every 30 seconds using smbus2, log values to a CSV file, and if temperature exceeds 28°C, turn on GPIO pin 17 (relay)."

The AI generates a Python script using paramiko and executes it on the sandbox. The sandbox script connects to the Pi, runs the sensor reading logic, and processes the data. The Pi itself runs a simple listener script that the AI deploys via SSH.

Why This Matters

  • Zero manual coding for integration logic. You describe the rule, AI writes the code.
  • No vendor lock-in. Use any I2C sensor, any microcontroller, any protocol.
  • Real-time automation. AI monitors the data stream and reacts instantly.
  • Save 40+ hours per month on routine monitoring and alert setup.

Pitfalls to Avoid

  1. I2C address conflicts — ASI Biont can't resolve hardware collisions. Make sure your sensors have unique addresses (common addresses: 0x76 for BME280, 0x5C for SHT31).
  2. MQTT broker firewall — if the broker is on a different network, open port 1883 or use WebSocket bridge (port 9001).
  3. Sandbox timeout — execute_python scripts timeout after 30 seconds. For long-running MQTT listeners, use the industrial_command tool with publish command instead of infinite loops.
  4. Bridge on Windows — if bridge.py fails to write to COM port (overlapped I/O issues), the AI automatically applies CancelIoEx and PurgeComm. Ensure your baud rate matches (115200 for most ESP32).

Try It Yourself

Go to asibiont.com, create an account, and start a chat. Tell the AI:

"I have an ESP32 with a BME280 sensor publishing to MQTT at 192.168.1.100:1883. Send me a Slack message if pressure drops below 990 hPa."

The AI will guide you through the remaining steps — no coding required.

Further Reading

This article is based on real user setups from the ASI Biont community. All code examples have been tested with ESP32 running MicroPython v1.22 and bridge.py v2.1.3.

← All posts

Comments