commit 718ed410f025252d732b346c17a2fc3ef0939a3f Author: jerick Date: Sat Oct 22 16:24:49 2022 -0400 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/lightSwitch.py b/lightSwitch.py new file mode 100644 index 0000000..563d355 --- /dev/null +++ b/lightSwitch.py @@ -0,0 +1,29 @@ +import subprocess +import time +import RPi.GPIO as GPIO + +#Toggle instead of turn on +#Don't have to check if on or off +#curl -k -X POST -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIwYWRkMGMxZmFlNWQ0YWNmYThjNTdmMDRhNWIwODBjNiIsImlhdCI6MTY2NjQ2NzMzMCwiZXhwIjoxOTgxODI3MzMwfQ.Egk1vDF0LC_WRlorhCHLPihkPICIEwz6nbfJR7Y1Prs" -H "Content-Type: application/json" -d '{"entity_id": "switch.lamp_plug"}' http://192.168.0.196:8123/api/services/switch/turn_on + + +touchPin = 31 + +GPIO.setmode(GPIO.BCM) +GPIO.setup(touchPin, GPIO.IN, pullUpDown=GPIO.PUD_UP) + +def touchDet(pin): + touch = GPIO.input(pin) + return touch + +try: + while True: + if touchDet(touchPin): print('['+time.ctime()+'] - '+'Touch Detected') + time.sleep(0.2) + +except KeyboardInterrupt: + print('interrupted!') + GPIO.cleanup() + + +#subprocess.run('./lightSwitch.sh') \ No newline at end of file diff --git a/lightSwitch.sh b/lightSwitch.sh new file mode 100644 index 0000000..87101bb --- /dev/null +++ b/lightSwitch.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +curl -k -X POST - "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIwYWRkMGMxZmFlNWQ0YWNmYThjNTdmMDRhNWIwODBjNiIsImlhdCI6MTY2NjQ2NzMzMCwiZXhwIjoxOTgxODI3MzMwfQ.Egk1vDF0LC_WRlorhCHLPihkPICIEwz6nbfJR7Y1Prs" -H "Content-Type: application/json" -d '{"entity_id": "switch.lamp_plug"}' http://192.168.0.196:8123/api/services/switch/toggle diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..f30e0a0 --- /dev/null +++ b/test.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +curl -k -X POST -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIwYWRkMGMxZmFlNWQ0YWNmYThjNTdmMDRhNWIwODBjNiIsImlhdCI6MTY2NjQ2NzMzMCwiZXhwIjoxOTgxODI3MzMwfQ.Egk1vDF0LC_WRlorhCHLPihkPICIEwz6nbfJR7Y1Prs" -H "Content-Type: application/json" -d '{"entity_id": "switch.lamp_plug"}' http://192.168.0.196:8123/api/services/switch/turn_on + +sleep 2 + +curl -k -X POST -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIwYWRkMGMxZmFlNWQ0YWNmYThjNTdmMDRhNWIwODBjNiIsImlhdCI6MTY2NjQ2NzMzMCwiZXhwIjoxOTgxODI3MzMwfQ.Egk1vDF0LC_WRlorhCHLPihkPICIEwz6nbfJR7Y1Prs" -H "Content-Type: application/json" -d '{"entity_id": "switch.lamp_plug"}' http://192.168.0.196:8123/api/services/switch/turn_off \ No newline at end of file diff --git a/testAPI.py b/testAPI.py new file mode 100644 index 0000000..9362df1 --- /dev/null +++ b/testAPI.py @@ -0,0 +1,3 @@ +import subprocess + +subprocess.run('./test.sh') \ No newline at end of file