This commit is contained in:
2026-07-05 15:58:27 +00:00
parent 437faa1573
commit ce98f21c97
@@ -25,6 +25,11 @@ arduino = serial.Serial('/dev/Doorbell', 9600, timeout=.1)
#arduino.setRTS(False)
last_ring = time.time()
headers = {
"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJjYjY5NjA5NmY0N2E0NmZlOGEzYjczOGYzYmUzOTk5ZSIsImlhdCI6MTY2MTM0NDgxOSwiZXhwIjoxOTc2NzA0ODE5fQ.z9fzbVOA1Pbur3Zb07481n-SoYesj8cetw-CX6WPmTs",
"Content-Type": "application/json"
}
while True:
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
if ((time.time() - last_ring) > 5):
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')
request = urllib.request.Request("https://ha.nodebucket.de/api/services/mqtt/publish", data, headers)
response = urllib.request.urlopen(request)
except Exception:
logger.error("Could not ring doorbell")
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)