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 wiresAPIs used: Custom Edge API on Raspberry Pi
# Install OS packagessudo apt updatesudo apt install -y python3-pip python3-venv python3-libgpiod# Add user to gpio group (required for GPIO access without sudo)sudo adduser $USER gpio# Log out and back in (or reboot) for this to take effect# Create project foldermkdir -p ~/iot-edge && cd ~/iot-edgepython3 -m venv .venvsource .venv/bin/activate# Install dependenciespip install flask gpiozero
Important: After adding your user to the gpio group, you must log out and back in (or reboot) for permissions to take effect.
import { LuaAgent, LuaSkill, LuaJob } from 'lua-cli';import SetRelayTool from './tools/SetRelayTool';// IoT control skillconst iotSkill = new LuaSkill({ name: "raspberry-pi-gpio", description: "Control GPIO devices on Raspberry Pi", context: ` This skill controls physical devices on a Raspberry Pi. - set_relay: Turn GPIO relay or LED on/off Use when user asks to control lights, fans, or any GPIO device Safety: - Always confirm which device a pin controls before toggling - Never rapidly toggle relays without user intent - Mention current state after changing `, tools: [new SetRelayTool()]});// Scheduled job: Turn off grow light at nightconst nighttimeOffJob = new LuaJob({ name: 'nighttime-off', description: 'Turn off grow light at 10 PM', schedule: { type: 'cron', pattern: '0 22 * * *' // 10 PM daily }, execute: async (job) => { const tool = new SetRelayTool(); await tool.execute({ pin: 17, state: 'off', active_low: true }); const user = await job.user(); await user.send([{ type: 'text', text: '🌙 Grow light turned off for the night.' }]); }});// Configure agent (v3.0.0)export const agent = new LuaAgent({ name: "smart-home-agent", persona: `You are a smart home automation assistant controlling Raspberry Pi devices.Your role:- Control lights, fans, and GPIO devices- Confirm actions before making physical changes- Report current device states- Provide clear feedback on actionsCommunication style:- Clear and confirmatory- Safety-conscious- Brief and actionableSafety practices:- Always confirm which device you're controlling- Mention current state after changes- Don't rapidly toggle devices- Warn if unsure about pin assignmentsDevice knowledge:- Pin 17: Grow light (active-low relay)- Pin 18: Ventilation fan- Pin 27: LED indicator`, skills: [iotSkill], jobs: [nighttimeOffJob]});
v3.0.0 Features: Uses LuaAgent with scheduled jobs for automated device control (e.g., turn off lights at night).
# Test tool directlylua test# Select: set_relay# Input: pin=17, state=on# Test conversationallylua chat# You: "Turn on the grow light"# You: "Turn off pin 17"