Close

communicating with x10

A project log for x10

a project for interfacing x10 stuff with alexa via home assistant

jlbrian7jlbrian7 12/24/2017 at 20:490 Comments

I wrote a simple flask app just to get things up and running.  When a url is curled from the command line the web app sends the appropriate even to the microcontroller which sends the command to the x10 devices.

from flask import Flask
import serial

x10 = serial.Serial('/dev/ttyACM1', 115200)
proj = serial.Serial('/dev/ttyUSB0', 9600)

app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Welcome!'

@app.route('/living_room_lamp_on')
def living_room_lamp_on():
    x10.write('A011')
    return 'Living room lamp on.'

@app.route('/living_room_lamp_off')
def living_room_lamp_off():
    x10.write('A010')
    return 'Living room lamp off.'

@app.route('/bedside_lamp_on')
def bedside_lamp_on():
    x10.write('A021')
    return 'Bedside lamp on.'

@app.route('/bedside_lamp_off')
def bedside_lamp_off():
    x10.write('A020')
    return 'Bedside lamp off.'

@app.route('/bedroom_tv_on')
def bedroom_tv_on():
    x10.write('A031')
    return 'Bedroom tv on.'

@app.route('/bedroom_tv_off')
def bedroom_tv_off():
    x10.write('A030')
    return 'Bedroom tv off.'

@app.route('/living_room_tv_on')
def living_room_tv_on():
    proj.write('POWR   1\r')
    return 'Living room tv on.'

@app.route('/living_room_tv_off')
def living_room_tv_off():
    proj.write('POWR   0\r')
    return 'Living room tv off.'

Discussions