Skip to content

Commit

Permalink
rpi home automation
Browse files Browse the repository at this point in the history
  • Loading branch information
markroxor committed Jan 14, 2019
1 parent 1085d0f commit 057889c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def process_df_api():
parameters = json_request['queryResult']['parameters']
action = json_request['queryResult']['action']

print("Sending query {} with params {} and action {} to {}".format(url, query, parameters, action))
print("Sending query {} with params {} and action {} to {}".format(query, parameters, action, url))
requests.post(url=url, data=json.dumps(json_request), headers=headers)

return return_text(json_request['queryResult']['fulfillmentText']), 200
Expand Down
20 changes: 16 additions & 4 deletions client/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,25 @@ def take_action(data):
query = data['queryResult']['queryText']
parameters = data['queryResult']['parameters']
action = data['queryResult']['action']

print(query)
print(parameters)

with open("key_mapping.json") as km:
key_map = json.load(km)

if action == 'home_automation' and parameters['state'] != '' and parameters['switch'][0] != '':
import RPi.GPIO as GPIO
switch = int(parameters['switch'][0])

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(switch, GPIO.OUT)

if parameters['state'] == 'off':
GPIO.output(switch,GPIO.HIGH)
else:
GPIO.output(switch,GPIO.LOW)
if action == 'open_app' and parameters['app'] != '':
print(parameters['app'])
pyautogui.press('apps')
Expand All @@ -41,7 +53,7 @@ def take_action(data):
else:
if keystroke in key_map:
keystroke = key_map[keystroke]

print("Pressing {}".format(keystroke))
pyautogui.press(keystroke)

Expand All @@ -60,9 +72,9 @@ def process_update():
js.write(json.dumps(json_request['queryResult']['queryText']) + '\n')
else:
take_action(json_request)

return "ok got your post!", 200

if request.method == "GET":
return "ok GOT it", 200

Expand Down

0 comments on commit 057889c

Please sign in to comment.