Merge branch 'main' of https://git.jerick.xyz/jerick/homeassistantPi
This commit is contained in:
16
lightSwitch.py
Normal file → Executable file
16
lightSwitch.py
Normal file → Executable file
@@ -1,3 +1,4 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
@@ -6,11 +7,14 @@ import RPi.GPIO as GPIO
|
|||||||
#Don't have to check if on or off
|
#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
|
#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
|
||||||
|
|
||||||
|
#Find an accurate broadcom pinout here
|
||||||
|
#https://www.etechnophiles.com/raspberry-pi-3-b-pinout-with-gpio-functions-schematic-and-specs-in-detail/
|
||||||
|
|
||||||
touchPin = 31
|
|
||||||
|
touchPin = 21
|
||||||
|
|
||||||
GPIO.setmode(GPIO.BCM)
|
GPIO.setmode(GPIO.BCM)
|
||||||
GPIO.setup(touchPin, GPIO.IN, pullUpDown=GPIO.PUD_UP)
|
GPIO.setup(touchPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||||
|
|
||||||
def touchDet(pin):
|
def touchDet(pin):
|
||||||
touch = GPIO.input(pin)
|
touch = GPIO.input(pin)
|
||||||
@@ -18,12 +22,14 @@ def touchDet(pin):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
if touchDet(touchPin): print('['+time.ctime()+'] - '+'Touch Detected')
|
if touchDet(touchPin):
|
||||||
time.sleep(0.2)
|
print('['+time.ctime()+'] - '+'Touch Detected, Light Switch Toggled')
|
||||||
|
subprocess.run('./home/pi/homeassistantPi/lightSwitch.sh')
|
||||||
|
time.sleep(0.2)
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print('interrupted!')
|
print('interrupted!')
|
||||||
GPIO.cleanup()
|
GPIO.cleanup()
|
||||||
|
|
||||||
|
|
||||||
#subprocess.run('./lightSwitch.sh')
|
#subprocess.run('./lightSwitch.sh')
|
||||||
|
|||||||
2
lightSwitch.sh
Normal file → Executable file
2
lightSwitch.sh
Normal file → Executable file
@@ -1,3 +1,3 @@
|
|||||||
#!/bin/bash
|
#!/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
|
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/toggle
|
||||||
|
|||||||
Reference in New Issue
Block a user