def check_light_status(threadName, delay):
    count = 0
    temp = "tv off"
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(18, GPIO.OUT)
    while count < float('inf'):
        r = requests.get('http://178.128.62.29/api/device/stat')
        data = r.json()
        time.sleep(delay)
        count += 1
        if data['light']['status'] == 'light on':
            GPIO.output(18, GPIO.HIGH)
            print('Light on!')
        if data['light']['status'] == 'light off':
            GPIO.output(18, GPIO.LOW)
##            GPIO.cleanup()
            print('Light off!')
        if data['tv']['status'] == 'tv on' and temp == 'tv off':
            temp = data['tv']['status']
            irsend.send_once('/home/pi/lircd.conf', ['KEY_POWER'])
            print("TV on!")
        if data['tv']['status'] == 'tv off' and temp == 'tv on':
            temp = data['tv']['status']
            irsend.send_once('/home/pi/lircd.conf', ['KEY_POWER'])
            print("TV off!")
Exemplo n.º 2
0
def handle(text, mic, profile):
    irsend.send_once('/home/pi/lircd.conf', ['KEY_POWER'])
    message = "turning on television"
    mic.say(message)

    payload = {'status': 'tv on'}
    r = requests.post("http://178.128.62.29/api/device/tvon", params=payload)
Exemplo n.º 3
0
    def handle_send_code_intent(self, message):
        name = message.data.get("Remote")
        remote = self.remote_normalized_name_to_real_name_table[name]

        name = message.data.get("Code")
        code = self.code_normalized_name_to_real_name_table[name]

        count = message.data.get("Number")
        irsend.send_once(remote, [code], count or 1, self.device, self.address)
Exemplo n.º 4
0
    def handle_send_code_intent(self, message):
        normalized_remote = message.data.get("Remote")
        normalized_codes = self.normalized_remote_to_code_table[normalized_remote]

        remote = self.remote_normalized_name_to_real_name_table[normalized_remote]
        utterance = message.data['utterance'].lower()
        extracted_codes = self._extract_codes(normalized_codes, utterance)

        count = message.data.get("Number")

        irsend.send_once(remote, extracted_codes, count or 1, self.device, self.address)
Exemplo n.º 5
0
def dialogflow(request):
    if request.body:
        data = json.loads(request.body.decode("utf-8"))
        if 'queryResult' in data:
            intent = data['queryResult']['intent']['displayName']
            if intent == 'radio-on':
                irsend.send_once('radio', ['aux'])
            elif intent == 'radio-off':
                irsend.send_once('radio', ['power'])
            elif intent == 'tv':
                irsend.send_once('tv', ['power'])
            elif intent == 'channel-next':
                irsend.send_once('tv', ['ch-up'])
            elif intent == 'channel-prev':
                irsend.send_once('tv', ['ch-down'])

            return JsonResponse({"fulfillment_text": "ok"})

    return JsonResponse({"fulfillment_text": "unknown command"})
Exemplo n.º 6
0
def on_message(client, userdata, msg):
    global config
    global DEVICE
    global ADDRESS

    """
    The callback for when a PUBLISH message is received from the MQTT server.
    """
    print("Received command:"+msg.topic+" "+str(msg.payload))
    sys.stdout.flush()

    """
    Handle IR Commands
    """

    payload = json.loads(msg.payload.decode())

    if "device" in payload:
        DEVICE = payload["device"]
    
    if "address" in payload:
        ADDRESS = payload["address"]
    
    command = payload["command"]
    remote = payload["remote"]
    codes = payload["codes"]
    count = payload.get("count", None) 
    
    if command == "send_once":
        if isinstance(codes, str):
            codes = [codes]

        irsend.send_once(remote, codes, device=DEVICE, address=ADDRESS, count=count)
    
    else:
        if hasattr(irsend, command):
            func = getattr(irsend, command)
            func(remote, codes, device=DEVICE, address=ADDRESS)
Exemplo n.º 7
0
 def sendCode(self, code):
     irsend.send_once(self.remote, [str(code)])
Exemplo n.º 8
0
#!/usr/bin/python
# External module imports
from py_irsend import irsend
import cgi
import cgitb
import sys
import json

cgitb.enable()

# Query Params:
arguments = cgi.FieldStorage()
state = int(arguments["state"].value)

if state == 0:
    irsend.send_once('screen', ['KEY_0'])
if state == 1:
    irsend.send_once('screen', ['KEY_2'])

print 'Content-Type: application/json;charset=UTF-8\n\n{"success":true}'
Exemplo n.º 9
0
 def do(self, params):
     irsend.send_once(params['device'], params['key'])
Exemplo n.º 10
0
#!/usr/bin/python
# External module imports
from py_irsend import irsend
import cgi
import cgitb
import sys
import json
import time

cgitb.enable()

# Query Params:
arguments = cgi.FieldStorage()
state = int(arguments["state"].value)

if state == 0:
    irsend.send_once('projector', ['KEY_POWER2'])
    time.sleep(1)
    irsend.send_once('projector', ['KEY_POWER2'])
if state == 1:
    irsend.send_once('projector', ['KEY_POWER'])

print 'Content-Type: application/json;charset=UTF-8\n\n{"success":true}'
Exemplo n.º 11
0
def send_once(device, cmd):
    try:
        irsend.send_once(device, [cmd])
        print("Sent: " + device + " - " + cmd)
    except:
        print("Failed to send: " + device + " - " + cmd)
Exemplo n.º 12
0
def toggleACPower():
    irsend.send_once('AC', ['KEY_POWER'])
    return 'DONE'
Exemplo n.º 13
0
#!/usr/bin/python
# External module imports
from py_irsend import irsend
import cgi
import cgitb
import sys
import json

cgitb.enable()

# Query Params:
arguments = cgi.FieldStorage()
input = int(arguments["input"].value)

if input == 1:
    irsend.send_once('hdmi_switch', ['KEY_1'])
if input == 2:
    irsend.send_once('hdmi_switch', ['KEY_2'])
if input == 3:
    irsend.send_once('hdmi_switch', ['KEY_3'])

print 'Content-Type: application/json;charset=UTF-8\n\n{"success":true}'
Exemplo n.º 14
0
    elif val < 70:
        return RED
    elif val < 80:
        return ORANGE
    return GREEN


def text_transform_bg(val):
    return str(val) + ' mg/dl'


if value is None:
    response = requests.get(DATA_SOURCE)
    data = response.json()
    # print(data[0])
    value = data[0]['sgv']

try:
    print("Current glucose is ", value)
    color = get_bg_color(value)
    irsend.send_once('desk0', ['ON'])
    irsend.send_once('desk0', [color])
    irsend.send_once('desk0', ['darker'])
    irsend.send_once('desk0', ['darker'])
    irsend.send_once('desk0', ['darker'])
    irsend.send_once('desk0', ['lighter'])
    irsend.send_once('desk0', ['lighter'])
    irsend.send_once('desk0', ['lighter'])
except RuntimeError as e:
    print("Some error occured, retrying! -", e)
Exemplo n.º 15
0
 def send_infrared():
     send_once("TV", ["KEY_4", "KEY_2", "KEY_OK"])
Exemplo n.º 16
0
def VERIZON(command):
    print("This is what was passed to irsend:" + command)

    remote = 'VERIZON_STB'

    ### THIS SECTION CONTROLS POWER-------------------------------------------------------------------

    if command in ['all on', 'all off']:
        irsend.send_once(remote, ['TV_POWER'])
        irsend.send_once(remote, ['STB_POWER'])

    elif command.lower() in [
            'set top on', 'set top off', 'cable box on', 'cable box off'
    ]:
        irsend.send_once(remote, ['STB_POWER'])

    elif command.lower() in ['on', 'off']:
        irsend.send_once(remote, ['TV_POWER'])

    ### THIS SECTION IS FOR CHANNEL CONTROL-----------------------------------------------------------

    elif command.find('channel') != -1:
        channelSplit = command.split()

        ### change channel based on channel number in this section
        if channelSplit[1].isdigit():
            for chan in channelSplit[1]:
                irsend.send_once(remote, ['BTN_' + chan])
                sleep(.05)
            irsend.send_once(remote, ['ENTER_BTN'])

        else:
            ### change channels based on channel names in this section
            try:

                def chanCipher(command):
                    chanDict = {
                        "cbs": "502",
                        "nbc": "504",
                        "fox": "505",
                        "abc": "507",
                        "tbs": "552",
                        "comedy": "690",
                        "discovery": "620",
                        "science": "622",
                        "history": "628",
                        "food": "664",
                        "velocity": "631",
                        "cartoon": "757",
                        "hgtv": "665",
                    }

                    chanNameSplit = command.split()
                    chanName = chanNameSplit[1]

                    return chanDict[chanName.lower()]

                for chan in chanCipher(command):
                    irsend.send_once(remote, ['BTN_' + chan])
                    sleep(.05)
                irsend.send_once(remote, ['ENTER_BTN'])
            except:
                print("Channel not found!")

    ###-----------------------------------------------------------------------------------------------
    ### THIS SECTION IS FOR INDIVIDUAL REMOTE COMMAND BUTTONS-----------------------------------------
    else:
        try:

            def vzCmdCipher(command):
                cmdDict = {
                    "menu":
                    "MENU",
                    "guide":
                    "GUIDE",
                    "info":
                    "INFO",
                    "up arrow":
                    "CIRCLE_UP",
                    "right arrow":
                    "CIRCLE_RIGHT",
                    "down arrow":
                    "CIRCLE_DOWN",
                    "left arrow":
                    "CIRCLE_LEFT",
                    "ok button":
                    "OK_BTN",
                    "exit":
                    "EXIT",
                    "widgets":
                    "WIDGETS",
                    "on demand":
                    "ON_DEMAND",
                    "options":
                    "OPTIONS",
                    "mute":
                    "MUTE",
                    "last":
                    "LAST",
                    "volume up":
                    "VOLUME_UP",
                    "volume down":
                    "VOLUME_DOWN",
                    "fios button":
                    "FIOS_TV_BTN",
                    "channel up":
                    "CHANNEL_UP",
                    "channel down":
                    "CHANNEL_DOWN",
                    "previous":
                    "PREVIOUS",
                    "dvr":
                    "DVR_BTN",
                    "next":
                    "NEXT",
                    "rewind":
                    "REWIND",
                    "play":
                    "PLAY_BTN",
                    "pause":
                    "PAUSE_BTN",
                    "fast forward":
                    "FFWD",
                    "stop":
                    "STOP",
                    "record":
                    "REC",
                    ''' ### these buttons probably are not needed
					"1 button":"BTN_1",
					"2 button":"BTN_2",
					"3 button":"BTN_3",
					"4 button":"BTN_4",
					"5 button":"BTN_5",
					"6 button":"BTN_6",
					"7 button":"BTN_7",
					"8 button":"BTN_8",
					"9 button":"BTN_9",
					"0 button":"BTN_0",
					'''
                    "asteric":
                    "ASTERIC_BTN",
                    "hash":
                    "HASH_BTN",
                    "a button":
                    "A_BTN",
                    "b button":
                    "B_BTN",
                    "c button":
                    "C_BTN",
                    "d button":
                    "D_BTN",
                    "input":
                    "AV_INPUT",
                    "pip":
                    "PIP_BTN",
                    "enter button":
                    "ENTER_BTN",
                }

                if any(char.isdigit() for char in command):
                    commandList = command.split()
                    del commandList[-2::]
                    newCommand = " ".join(commandList)
                    print("this is returned with digits: " + newCommand)
                    return cmdDict[newCommand.lower()]
                else:
                    print("this is returned with no digits: " + command)
                    return cmdDict[command.lower()]

            print(vzCmdCipher(command))

            ### this section will run the command x number of times if provided in the voice command-------
            if any(char.isdigit() for char in command):
                #for i in range(int(command.split()[-2])):
                for i in range(int(command.split()[-2])):
                    cleanedCmd = [vzCmdCipher(command)]
                    irsend.send_once(remote, cleanedCmd)
                    sleep(.3)
                    print("sent IR")
            ###---------------------------------------------------------------------------------------------
            ###THIS SECTION RUNS THE COMMANDS INDIVIDUALLY--------------------------------------------------
            else:
                cleanedCmd = [vzCmdCipher(command)]
                irsend.send_once(remote, cleanedCmd)
                print("IR command sent!")

        except:
            print("Command not found!")
def send_power_signal():
    irsend.send_once('HDX', ['KEY_POWER'])
Exemplo n.º 18
0
def send(request):
    irsend.send_once(request.GET['device'], [request.GET['button']])
    return HttpResponse('ok')
Exemplo n.º 19
0
# External module imports
from py_irsend import irsend
import cgi
import cgitb
import sys
import json
import time

cgitb.enable()
arguments = cgi.FieldStorage()
# HDMI switcher
if arguments.has_key("hdmi_input"):
    hdmi_input = int(arguments["hdmi_input"].value)

    if hdmi_input == 1:
        irsend.send_once('hdmi_switch', ['KEY_1'])
    if hdmi_input == 2:
        irsend.send_once('hdmi_switch', ['KEY_2'])
    if hdmi_input == 3:
        irsend.send_once('hdmi_switch', ['KEY_3'])

# Screen
if arguments.has_key("screen_state"):
    screen_state = int(arguments["screen_state"].value)

    if screen_state == 0:
        irsend.send_once('screen', ['KEY_0'])
    if screen_state == 1:
        irsend.send_once('screen', ['KEY_2'])

# Projector: