Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Inteligencia Artificial
1
Indice
# PanelDomotico.py ............................................................................................................................ 4
# Declaracion de Librerias del Modulo tkinter ................................................................................ 4
######### VENTANA # 1 ########### ......................................................................................... 4
#Programacin Horaria de la Alarma y Activacin del Sensor .................................................... 4
# FOCO -1 .................................................................................................................................... 6
#FOCO -2 ..................................................................................................................................... 7
#FOCO -3 ..................................................................................................................................... 8
#FOCO -4 ..................................................................................................................................... 9
#Configuracin de las Luces por Horario .................................................................................. 10
#Label para Hora y Minuto ........................................................................................................ 12
#Las Cajas de Textos de Hora y Minuto .................................................................................... 12
#Boton para programar la hora................................................................................................. 14
# Reloj Time ............................................................................................................................... 14
######## VENTANA PROGRAMA ALARMA########................................................................... 14
# Boton Guardar ........................................................................................................................ 15
# Reloj Time ............................................................................................................................... 15
######### VENTANA PARA ACERCA DE ######### .................................................................... 16
########3 VENTANA PROGRAMAR FOCOS ######### ............................................................... 16
# Asignar imagenes a Foco1 ...................................................................................................... 20
# Asignar imagenes a Foco2 ...................................................................................................... 21
# Asignar Imagen a Foco3 ......................................................................................................... 21
# Asignar Imagen a Foco4 .............................................................Error! Bookmark not defined.
# Asignar Imagen a Alarma............................................................Error! Bookmark not defined.
# Alarma.sh............................................................................................Error! Bookmark not defined.
# Alarmaoff.sh .......................................................................................Error! Bookmark not defined.
# Correo.sh ........................................................................................................................................ 22
#Foco1.sh .......................................................................................................................................... 22
#Foco1off.sh ...................................................................................................................................... 22
#Foco2.sh .......................................................................................................................................... 22
#Foco2off.sh ...................................................................................................................................... 23
#Foco3.sh .......................................................................................................................................... 23
#Foco3off.sh ...................................................................................................................................... 23
2
3
# PanelDomotico.py
# Declaracion de Librerias del Modulo tkinter
from Tkinter import *
import tkFont
import tkMessageBox
import pygame
import os
import subprocess
import sqlite3
import time
import os
import webbrowser
pygame.mixer.init()
#pygame.mixer.music.load("/home/pi/PracticasTK/acceso1.mp3")
def settings():
global operator
operator=operator+str(numbers)
cod.set(operator)
#####################################################################
tab=StringVar()
hi=horai.get()
4
mi=mini.get()
hf=horaf.get()
mf=minf.get()
dia="*"
mes="*"
ano="*"
tab=" "
user="root"
path="/home/pi/alarma2.py"
path2="/home/pi/apagar_alarma2.py"
cadena=(str(mi)+''+str(tab)+''+str(hi)+''+str(tab)+''+str(dia)+''+str(tab)+''+str(mes)+''+str(tab)
+''+str(ano)+''+str(tab)+''+str(user)+''+str(tab)+''+str(path))
print(str(cadena))
pf=open(r'/etc/cron.d/alarma','w')
pf.write(cadena)
pf.write("\n")
pf.close()
cadena2=(str(mf)+''+str(tab)+''+str(hf)+''+str(tab)+''+str(dia)+''+str(tab)+''+str(mes)+''+str(tab)
print(str(cadena2))
pf2=open(r'/etc/cron.d/alarmaoff','w')
#LA CARPETA "CRON.D" AHI SE ALAMACENA LOS ARCHIVOS PARA PROGRAMAR A QUE HORA SE
ACTIVA LA ALARMA O FOCOS
pf2.write(cadena2)
5
pf2.write("\n")
pf2.close()
pygame.mixer.music.play()
#####################################################################
# FOCO -1
def saveFocos():
tab=StringVar()
hi=horaih1.get()
mi=minih1.get()
hf=horafh1.get()
mf=minfh1.get()
dia="*"
mes="*"
ano="*"
tab=" "
user="root"
path="/home/pi/foco1.sh"
path2="/home/pi/foco1off.sh"
cadena=(str(mi)+''+str(tab)+''+str(hi)+''+str(tab)+''+str(dia)+''+str(tab)+''+str(mes)+''+str(tab)
+''+str(ano)+''+str(tab)+''+str(user)+''+str(tab)+''+str(path))
print(str(cadena))
pf=open(r'/etc/cron.d/test','w')
pf.write(cadena)
pf.write("\n")
pf.close()
6
cadena2=(str(mf)+''+str(tab)+''+str(hf)+''+str(tab)+''+str(dia)+''+str(tab)+''+str(mes)+''+str(tab)
+''+str(ano)+''+str(tab)+''+str(user)+''+str(tab)+''+str(path2))
print(str(cadena2))
pf2=open(r'/etc/cron.d/testoff','w')
pf2.write(cadena2)
pf2.write("\n")
pf2.close()
pygame.mixer.music.load("/home/pi/PracticasTK/horarioprog.mp3")
pygame.mixer.music.play()
########################################################
#FOCO -2
tab=StringVar()
hi=horaih2.get()
mi=minih2.get()
hf=horafh2.get()
mf=minfh2.get()
dia="*"
mes="*"
ano="*"
tab=" "
user="root"
path="/home/pi/foco2.sh"
path2="/home/pi/foco2off.sh"
cadena=(str(mi)+''+str(tab)+''+str(hi)+''+str(tab)+''+str(dia)+''+str(tab)+''+str(mes)+''+str(tab)
+''+str(ano)+''+str(tab)+''+str(user)+''+str(tab)+''+str(path))
print(str(cadena))
7
pf=open(r'/etc/cron.d/test2','w')
pf.write(cadena)
pf.write("\n")
pf.close()
cadena2=(str(mf)+''+str(tab)+''+str(hf)+''+str(tab)+''+str(dia)+''+str(tab)+''+str(mes)+''+str(tab)
+''+str(ano)+''+str(tab)+''+str(user)+''+str(tab)+''+str(path2))
print(str(cadena2))
pf2=open(r'/etc/cron.d/testoff2','w')
pf2.write(cadena2)
pf2.write("\n")
pf2.close()
pygame.mixer.music.load("/home/pi/PracticasTK/horarioprog.mp3")
pygame.mixer.music.play()
########################################################
#FOCO -3
tab=StringVar()
hi=horaih3.get()
mi=minih3.get()
hf=horafh3.get()
mf=minfh3.get()
dia="*"
mes="*"
ano="*"
tab=" "
user="root"
path="/home/pi/foco3.sh"
path2="/home/pi/foco3off.sh"
8
cadena=(str(mi)+''+str(tab)+''+str(hi)+''+str(tab)+''+str(dia)+''+str(tab)+''+str(mes)+''+str(tab)
+''+str(ano)+''+str(tab)+''+str(user)+''+str(tab)+''+str(path))
print(str(cadena))
pf=open(r'/etc/cron.d/test3','w')
pf.write(cadena)
pf.write("\n")
pf.close()
cadena2=(str(mf)+''+str(tab)+''+str(hf)+''+str(tab)+''+str(dia)+''+str(tab)+''+str(mes)+''+str(tab)
+''+str(ano)+''+str(tab)+''+str(user)+''+str(tab)+''+str(path2))
print(str(cadena2))
pf2=open(r'/etc/cron.d/testoff3','w')
pf2.write(cadena2)
pf2.write("\n")
pf2.close()
pygame.mixer.music.load("/home/pi/PracticasTK/horarioprog.mp3")
pygame.mixer.music.play()
########################################################
#FOCO -4
tab=StringVar()
hi=horaih4.get()
mi=minih4.get()
hf=horafh4.get()
mf=minfh4.get()
dia="*"
mes="*"
ano="*"
9
tab=" "
user="root"
path="/home/pi/foco4.sh"
path2="/home/pi/foco4off.sh"
cadena=(str(mi)+''+str(tab)+''+str(hi)+''+str(tab)+''+str(dia)+''+str(tab)+''+str(mes)+''+str(tab)
+''+str(ano)+''+str(tab)+''+str(user)+''+str(tab)+''+str(path))
print(str(cadena))
pf=open(r'/etc/cron.d/test4','w')
pf.write(cadena)
pf.write("\n")
pf.close()
cadena2=(str(mf)+''+str(tab)+''+str(hf)+''+str(tab)+''+str(dia)+''+str(tab)+''+str(mes)+''+str(tab)
+''+str(ano)+''+str(tab)+''+str(user)+''+str(tab)+''+str(path2))
print(str(cadena2))
pf2=open(r'/etc/cron.d/testoff4','w')
pf2.write(cadena2)
pf2.write("\n")
pf2.close()
pygame.mixer.music.play()
######################################################
10
def toplevel2():
global horaih1,horaih2,horaih3,horaih4,horaih5,horaih6
global horafh1,horafh2,horafh3,horafh4,horafh5,horafh6
global minih1,minih2,minih3,minih4,minih5,minih6
global minfh1,minfh2,minfh3,minfh4,minfh5,minfh6
v2=Toplevel()
v2.geometry("550x350+400+200")
horaih1=StringVar()
minih1=StringVar()
horafh1=StringVar()
minfh1=StringVar()
horaih2=StringVar()
minih2=StringVar()
horafh2=StringVar()
minfh2=StringVar()
horaih3=StringVar()
minih3=StringVar()
horafh3=StringVar()
minfh3=StringVar()
horaih4=StringVar()
minih4=StringVar()
horafh4=StringVar()
minfh4=StringVar()
11
#horaih5=StringVar()
#minih5=StringVar()
#horafh5=StringVar()
#minfh5=StringVar()
#horaih6=StringVar()
#minih6=StringVar()
#horafh6=StringVar()
#minfh6=StringVar()
textfont2=tkFont.Font(family="Helvetica",size=10,weight="bold")
labelon=Label(v2,text="- - - ON - - -",font=textfont).place(x=210,y=40)
labelhorai=Label(v2,text="Hora-ini").place(x=190,y=60)
labelmini=Label(v2,text="Min-ini").place(x=260,y=60)
labelhoraf=Label(v2,text="Hora-fin").place(x=330,y=60)
labelhorai=Label(v2,text="Min-fin").place(x=410,y=60)
labelhab1=Label(v2,text="Habitacion -1-",font=textfont).place(x=70,y=80)
labelhab2=Label(v2,text="Habitacion -2-",font=textfont).place(x=70,y=120)
labelhab3=Label(v2,text="Habitacion -3-",font=textfont).place(x=70,y=160)
labelhab4=Label(v2,text="Habitacion -4-",font=textfont).place(x=70,y=200)
#labelhab5=Label(v2,text="Habitacion -5-",font=textfont).place(x=70,y=240)
#labelhab6=Label(v2,text="Habitacion -6-",font=textfont).place(x=70,y=280)
12
textminih1=Entry(v2,textvariable=minih1,width=7).place(x=260,y=80)
#####################
texthorafh1=Entry(v2,textvariable=horafh1,width=7).place(x=330,y=80) #
textminfh1=Entry(v2,textvariable=minfh1,width=7).place(x=410,y=80) #
texthoraih2=Entry(v2,textvariable=horaih2,width=7).place(x=190,y=120) #
textminih2=Entry(v2,textvariable=minih2,width=7).place(x=260,y=120) #
texthorafh2=Entry(v2,textvariable=horafh2,width=7).place(x=330,y=120) #
textminfh2=Entry(v2,textvariable=minfh2,width=7).place(x=410,y=120) #
texthoraih3=Entry(v2,textvariable=horaih3,width=7).place(x=190,y=160) #
textminih3=Entry(v2,textvariable=minih3,width=7).place(x=260,y=160) #
texthorafh3=Entry(v2,textvariable=horafh3,width=7).place(x=330,y=160) #
textminfh3=Entry(v2,textvariable=minfh3,width=7).place(x=410,y=160) #
texthoraih4=Entry(v2,textvariable=horaih4,width=7).place(x=190,y=200) #
textminih4=Entry(v2,textvariable=minih4,width=7).place(x=260,y=200) #
texthorafh4=Entry(v2,textvariable=horafh4,width=7).place(x=330,y=200)
textminfh4=Entry(v2,textvariable=minfh4,width=7).place(x=410,y=200)
#texthoraih5=Entry(v2,textvariable=horaih5,width=7).place(x=190,y=240)
#textminih5=Entry(v2,textvariable=minih5,width=7).place(x=260,y=240)
#texthorafh5=Entry(v2,textvariable=horafh5,width=7).place(x=330,y=240)
#textminfh5=Entry(v2,textvariable=minfh5,width=7).place(x=410,y=240)
#texthoraih6=Entry(v2,textvariable=horaih6,width=7).place(x=190,y=280)
#textminih6=Entry(v2,textvariable=minih6,width=7).place(x=260,y=280)
#texthorafh6=Entry(v2,textvariable=horafh6,width=7).place(x=330,y=280)
#textminfh6=Entry(v2,textvariable=minfh6,width=7).place(x=410,y=280)
13
botosettings=Button(v2,text="PROGRAMAR",command=saveFocos).place(x=215,y=260,height=30)
botonclose=Button(v2,text="SALIR", command=v2.destroy).place(x=305,y=260,height=30)
#Boton para salir de la ventana
# Reloj Time
def update():
current=time.strftime("%H:%M:%S")
labeltime=Label(v2,text=current).place(x=120,y=260)
v2.after(1000,update)
update()
v2.mainloop()
# Las variables Globales siempre deben de declarse al inicio de cada metodo o funcion
global horai
global horaf
global mini
global minf
v1=Toplevel()
v1.geometry("500x350+200+200")
mini=StringVar()
14
minf=StringVar()
horai=StringVar()
horaf=StringVar()
# Declarar Variables Globales para ser usadas dentro de cualquier funcion o metodo
texttop=tkFont.Font(family="Helvetica",size=10,weight="bold")
texttop2=tkFont.Font(family="Helvetica",size=9,weight="bold")
caja2=Entry(v1,textvariable=horai,width=20).place(x=215,y=70)
TextBox2=Entry(v1,textvariable=mini,width=20).place(x=215,y=110)
TextBox3=Entry(v1,textvariable=horaf,width=20).place(x=215,y=150)
TextBox4=Entry(v1,textvariable=minf,width=20).place(x=215,y=190)
# Boton Guardar
imgsave=PhotoImage(file="guardar.gif")
botosettings=Button(v1,image=imgsave,command=save,width=50).place(x=215,y=220,height=50)
# COMMAND=SAVE, ESTA FUNCION ESTA AL INICIO DEL PROGRAMA
botonclose=Button(v1,text="Cerrar", command=v1.destroy).place(x=295,y=220,height=50)
# Reloj Time
def update():
current=time.strftime("%H:%M:%S")
labeltime=Label(v1,text=current).place(x=120,y=250)
15
v1.after(1000,update)
update()
v1.mainloop()
v3=Toplevel()
v3.title("Acerca de")
v3.geometry("300x350+450+230")
label2=Label(v3,text="Programadores",font=bgtext2).place(x=30,y=70)
label3=Label(v3,text="Anthony Paz",font=bgtext3).place(x=30,y=100)
label3=Label(v3,text="Ramiro Leiva",font=bgtext3).place(x=30,y=120)
label3=Label(v3,text="Justo Valentin",font=bgtext3).place(x=30,y=140)
label3=Label(v3,text="Joseph",font=bgtext3).place(x=30,y=160)
botonclose=Button(v3,text="Cerrar", command=v3.destroy).place(x=110,y=270,height=50)
v3.mainloop()
################################################################################
###############################
def Foco1on():
16
boton1b=Button(v0,image=imgboton1b,command=Foco1off,state='normal',width=100).place(x=1
40,y=50,height=100) #Esto activa el boton para desactivar el foco
boton1=Button(v0,image=imgboton1,command=Foco1on,state='disabled').place(x=20,y=50,height
=100,width=100) #El boton que presionamos quedara desactivado por lo que no podremos
activar el mismo foco hasta que lo desactivemos primero
def Foco1off():
os.system("/./home/pi/foco1off.sh")
boton1b=Button(v0,image=imgboton1b,command=Foco1off,state='disabled',width=100).place(x=
140,y=50,height=100) #El boton que presionamos quedara desactivado por lo que no podremos
desactivar el mismo foco hasta que lo activemos primero
boton1=Button(v0,image=imgboton1,command=Foco1on,state='normal').place(x=20,y=50,height=
100,width=100) #Esto activa el boton para activar el foco
def Foco2on():
os.system("/./home/pi/foco2.sh")
boton2=Button(v0,image=imgboton2,command=Foco2on,width=100,state='disabled').place(x=20,
y=205,height=100)
boton2b=Button(v0,image=imgboton2b,command=Foco2off,state='normal',width=100).place(x=1
40,y=205,height=100)
def Foco2off():
os.system("/./home/pi/foco2off.sh")
boton2=Button(v0,image=imgboton2,command=Foco2on,width=100,state='normal').place(x=20,y
=205,height=100)
17
boton2b=Button(v0,image=imgboton2b,command=Foco2off,state='disabled',width=100).place(x=
140,y=205,height=100)
def Foco3on():
os.system("/./home/pi/foco3.sh")
boton3=Button(v0,image=imgboton3,command=Foco3on,width=100,state='disabled').place(x=20,
y=360,height=100)
boton3b=Button(v0,image=imgboton3b,command=Foco3off,state='normal',width=100).place(x=1
40,y=360,height=100)
def Foco3off():
os.system("/./home/pi/foco3off.sh")
boton3=Button(v0,image=imgboton3,command=Foco3on,width=100,state='normal').place(x=20,y
=360,height=100)
boton3b=Button(v0,image=imgboton3b,command=Foco3off,state='disabled',width=100).place(x=
140,y=360,height=100)
def Foco4on():
os.system("/./home/pi/foco4.sh")
boton4=Button(v0,image=imgboton4,command=Foco4on,width=100,state='disabled').place(x=28
0,y=50,height=100)
boton4b=Button(v0,image=imgboton4b,command=Foco4off,state='normal',width=100).place(x=4
00,y=50,height=100)
def Foco4off():
18
os.system("/./home/pi/foco4off.sh")
boton4=Button(v0,image=imgboton4,command=Foco4on,width=100,state='normal').place(x=280,
y=50,height=100)
boton4b=Button(v0,image=imgboton4b,command=Foco4off,state='disabled',width=100).place(x=
400,y=50,height=100)
def alarmaON():
os.system("/./home/pi/alarma.sh")
boton8=Button(v0,image=imgboton7,command=alarmaOFF,width=100).place(x=590,y=50,height=
100)
def alarmaOFF():
os.system("/./home/pi/alarmaoff.sh")
boton7=Button(v0,image=imgboton7,command=alarmaON,width=100).place(x=590,y=50,height=
100)
def btnClick(numbers):
global operator
operator=operator+str(numbers)
cod.set(operator)
def btnClsCaja1():
global operator
operator=""
cod.set(operator)
19
# Defincion de la Ventana Principal (ventana Padre)
v0=Tk()
v0.geometry("820x527+300+130")
def Funcion():
menu_general = Menu(v0)
menu_archivo.add_separator()
label1=Label(v0,text="HABITACION 1",font=bgtext1).place(x=70,y=10)
imgboton1=PhotoImage(file="on.gif")
boton1=Button(v0,image=imgboton1,command=Foco1on).place(x=20,y=50,height=100,width=100
) #command=Foco1on: ESTO HACE LA FUNCION DE ENCENDER EL FOCO (ARRIBA ESTA LA
PROGRAMACION)
20
imgboton1b=PhotoImage(file="of.gif")
boton1b=Button(v0,image=imgboton1b,command=Foco1off,state='disabled',width=100).place(x=
140,y=50,height=100) #STATE=DISABLED: ESTO HACE QUE AL INICIAR EL PROGRAMA SE
DESHABILITEN EL BOTON DE DESACTIVAR FOCO 1 PARA EVITAR QUE UN FOCO QUE ESTE
APAGADO LO PUEDA VOLVER APAGAR
label2=Label(v0,text="HABITACION 2",font=bgtext2).place(x=70,y=160)
imgboton2=PhotoImage(file="on.gif")
boton2=Button(v0,image=imgboton2,command=Foco2on,width=100).place(x=20,y=205,height=10
0)
imgboton2b=PhotoImage(file="of.gif")
boton2b=Button(v0,image=imgboton2b,command=Foco2off,state='disabled',width=100).place(x=
140,y=205,height=100)
label3=Label(v0,text="HABITACION 3",font=bgtext3).place(x=70,y=315)
imgboton3=PhotoImage(file="on.gif")
boton3=Button(v0,image=imgboton3,command=Foco3on,width=100).place(x=20,y=360,height=10
0)
imgboton3b=PhotoImage(file="of.gif")
boton3b=Button(v0,image=imgboton3b,command=Foco3off,state='disabled',width=100).place(x=
140,y=360,height=100)
21
# Correo.sh
#!/bin/bash
rm -f /tmp/out.mail
#Foco1.sh
#bin/bash
clear
#Foco1off.sh
#bin/bash
clear
#Foco2.sh
#bin/bash
clear
22
#Foco2off.sh
#bin/bash
clear
#Foco3.sh
#bin/bash
clear
#Foco3off.sh
#bin/bash
clear
23