35 lines
842 B
Python
35 lines
842 B
Python
import json
|
|
import requests
|
|
import sys
|
|
|
|
#https://howchoo.com/g/zdi2zgq2mjb/how-to-use-siri-to-control-anything-from-iftt-to-custom-programs-and-devices
|
|
|
|
moduleName = 'garage'
|
|
commandWords = ['garage', 'door']
|
|
GARAGE_HOST = 'http://192.168.1.183'
|
|
|
|
|
|
def execute(command):
|
|
try:
|
|
action = command.split(' ')[0]
|
|
except IndexError:
|
|
print('No command passed.')
|
|
return
|
|
|
|
if not action in ['open', 'close']:
|
|
print('Invalid action.')
|
|
return
|
|
|
|
response = requests.get('{0}/status'.format(GARAGE_HOST))
|
|
status = json.loads(response.text)
|
|
|
|
if action == 'open' and status.get('open'):
|
|
print('Door already open.')
|
|
return
|
|
|
|
if action == 'close' and status.get('close'):
|
|
print('Door already closed.')
|
|
return
|
|
|
|
requests.get('{0}/relay'.format(GARAGE_HOST))
|
|
|