Skip to main content

Overview

Control lights, relays, or any GPIO-connected devices on a Raspberry Pi through natural language conversation. Turn devices on/off, check status, and automate with scheduled jobs. What it does:
  • Toggle relay or LED on/off via chat
  • Control GPIO pins remotely
  • Schedule automated on/off times
  • Safe, authenticated edge API
Hardware: Raspberry Pi 4/5, relay module (optocoupled recommended), jumper wires APIs used: Custom Edge API on Raspberry Pi

Architecture


Complete Implementation

Edge API on Raspberry Pi

Setup (one-time)

Important: After adding your user to the gpio group, you must log out and back in (or reboot) for permissions to take effect.

Edge API Code

Create edge_api.py:

Run the Edge API

Test Edge API


Lua Agent Implementation

src/tools/SetRelayTool.ts

src/index.ts

Uses LuaAgent with scheduled jobs for automated device control (e.g., turn off lights at night).

Environment Setup

Or set via CLI:

Testing

Test Edge API Directly

Test with Lua


Wiring

Relay Module (Active-Low):
Safety: Use optocoupled relay modules for AC loads. Never exceed the relay’s rated voltage/current. Always verify correct wiring before powering on.

Production Deployment

Run Edge API on Boot

Create systemd service /etc/systemd/system/iot-edge.service:
Enable and start:

Key Features

Remote Control

Control GPIO devices from anywhere via chat

Secure API

API key authentication protects your edge API

Scheduled Automation

Jobs for automated on/off schedules

Safety First

Confirmation before physical state changes

Next IoT Demo

Greenhouse Climate Monitor

Read temperature, humidity, and pressure from BME280 sensor