AI GPT Home Automation

parmarjatin4911@gmail.com - Jan 28 - - Dev Community

AI GPT Home Automation

GPT OpenAPI Schema

{
"openapi": "3.1.0",
"info": {
"title": "Hue Light Control",
"description": "Controls Philips Hue lights via a Flask API.",
"version": "1.0.0"
},
"servers": [
{
"url": "https://example.repl.co"
}
],
"paths": {
"/light": {
"post": {
"description": "Turns a specified light on or off.",
"operationId": "controlLight",
"requestBody": {
"description": "Light control data",
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"light_id": {
"type": "integer",
"description": "The ID of the light to control."
},
"status": {
"type": "string",
"description": "Desired state of the light ('on' or 'off')."
}
},
"required": ["light_id", "status"]
}
}
}
},
"responses": {
"200": {
"description": "Light control response",
"content": {
"text/plain": {
"schema": {
"type": "string"
}
}
}
}
}
}
}
},

"components": {
"schemas": {}
}
}

Public App

from flask import Flask, request

app = Flask(name)

@app.route('/', methods=['GET'])
def home():
return "Hello World!"

@app.route('/light', methods=['POST'])
def control_light():
light_data = request.json
response = request.post('http://[PUBLIC_IP]/light', json=light_data)
return response.text

if name == 'main':
app.run(debug=True, host='0.0.0.0')

Local App

from flask import Flask, request
from huesdk import Hue

app = Flask(name)
hue = Hue(bridge_ip='[LOCAL_IP]', username='[USERNAME]')
lights = hue.get_lights()
for light in lights:
print(f'Light ID: {light.id_}, Name: {light.name}')

@app.route('/light', methods=['POST'])
def control_light():
light_id = request.json.get('light_id') | 1
status = request.json.get('status')
light = hue.get_light(id_=light_id)
if status == 'on':
light.on()
else:
light.off()
return f'Light {light_id} turned {"on" if status == "on" else "off"}'

if name == 'main':
app.run(debug=True, host='0.0.0.0')

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player