klingel
This commit is contained in:
@@ -25,6 +25,11 @@ arduino = serial.Serial('/dev/Doorbell', 9600, timeout=.1)
|
|||||||
#arduino.setRTS(False)
|
#arduino.setRTS(False)
|
||||||
|
|
||||||
last_ring = time.time()
|
last_ring = time.time()
|
||||||
|
headers = {
|
||||||
|
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJjYjY5NjA5NmY0N2E0NmZlOGEzYjczOGYzYmUzOTk5ZSIsImlhdCI6MTY2MTM0NDgxOSwiZXhwIjoxOTc2NzA0ODE5fQ.z9fzbVOA1Pbur3Zb07481n-SoYesj8cetw-CX6WPmTs",
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
data = arduino.readline()[:-2] #the last bit gets rid of the new-line chars
|
data = arduino.readline()[:-2] #the last bit gets rid of the new-line chars
|
||||||
@@ -43,13 +48,15 @@ while True:
|
|||||||
# send MQTT if last ring was more than 5 seconds ago
|
# send MQTT if last ring was more than 5 seconds ago
|
||||||
if ((time.time() - last_ring) > 5):
|
if ((time.time() - last_ring) > 5):
|
||||||
last_ring = time.time()
|
last_ring = time.time()
|
||||||
headers = {
|
|
||||||
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJjYjY5NjA5NmY0N2E0NmZlOGEzYjczOGYzYmUzOTk5ZSIsImlhdCI6MTY2MTM0NDgxOSwiZXhwIjoxOTc2NzA0ODE5fQ.z9fzbVOA1Pbur3Zb07481n-SoYesj8cetw-CX6WPmTs",
|
|
||||||
"Content-Type": "application/json"
|
|
||||||
}
|
|
||||||
data = json.dumps({'payload': 'RING', 'topic': 'lewe/doorbell', 'retain': 'False'}).encode('utf8')
|
data = json.dumps({'payload': 'RING', 'topic': 'lewe/doorbell', 'retain': 'False'}).encode('utf8')
|
||||||
request = urllib.request.Request("https://ha.nodebucket.de/api/services/mqtt/publish", data, headers)
|
request = urllib.request.Request("https://ha.nodebucket.de/api/services/mqtt/publish", data, headers)
|
||||||
response = urllib.request.urlopen(request)
|
response = urllib.request.urlopen(request)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.error("Could not ring doorbell")
|
logger.error("Could not ring doorbell")
|
||||||
time.sleep(300)
|
time.sleep(300)
|
||||||
|
elif (data == 'CLICK'):
|
||||||
|
if ((time.time() - last_ring) > 5):
|
||||||
|
last_ring = time.time()
|
||||||
|
data = json.dumps({'payload': 'CLICK', 'topic': 'lewe/doorbell', 'retain': 'False'}).encode('utf8')
|
||||||
|
request = urllib.request.Request("https://ha.nodebucket.de/api/services/mqtt/publish", data, headers)
|
||||||
|
response = urllib.request.urlopen(request)
|
||||||
|
|||||||
Reference in New Issue
Block a user