Feb-13-2022, 04:15 PM
I need help making this run faster. It takes about 7 seconds for the lights to respond when I open or close the door. I'm thinking lines 24-26 and 48-50 should be somewhere else, so that their state is already known before the change in state is to be made. Like, instead of checking them when the door opens, already know what they are (on or off).
from gpiozero import Button, LED from signal import pause from time import sleep from datetime import datetime from datetime import timedelta import requests from wyze_sdk import Client from wyze_sdk.errors import WyzeApiError client = Client(email="d***********@gmail.com", password="********") garagepassage = Button(20) # Input from garage passage door stairspassage = Button(18) # Input from door at top of stairs now = datetime.now() current_time = now.strftime("%H:%M:%S") print("Door Started at ", current_time) r = requests.post("https://autoremotejoaomgcd.appspot.com/sendnotification?key=APA9SecretAutoRemoteCodeo8V75nUXCU8solLv-Y2mbzGOzkybqKGibberishO2Ody2SsXjiC&title=Just%20Saying&text=Switch%20monitoring%20has%20begun") def open(): #now = datetime.now() #current_time = now.strftime("%H:%M:%S") #print("Door open at " + current_time) bulbS1 = client.bulbs.info(device_mac='2CAA8E5B0550') bulbS2 = client.bulbs.info(device_mac='2CAA8E5B13B1') plugSLED = client.plugs.info(device_mac='7C78B2717462') if bulbS1.is_on: client.bulbs.turn_off(device_mac=bulbS1.mac, device_model=bulbS1.product.model, after=timedelta(hours=.5)) else: client.bulbs.turn_on(device_mac=bulbS1.mac, device_model=bulbS1.product.model) bulbS1 = client.bulbs.info(device_mac=bulbS1.mac) if bulbS2.is_on: client.bulbs.turn_off(device_mac=bulbS2.mac, device_model=bulbS2.product.model, after=timedelta(hours=.5)) else: client.bulbs.turn_on(device_mac=bulbS2.mac, device_model=bulbS2.product.model) bulbS2 = client.bulbs.info(device_mac=bulbS2.mac) if plugSLED.is_on: client.plugs.turn_off(device_mac=plugSLED.mac, device_model=plugSLED.product.model, after=timedelta(hours=.5)) else: client.plugs.turn_on(device_mac=plugSLED.mac, device_model=plugSLED.product.model) print("on") def closed(): #now = datetime.now() #current_time = now.strftime("%H:%M:%S") #print("Door closed at " + current_time) bulbS1 = client.bulbs.info(device_mac='2CAA8E5B0550') bulbS2 = client.bulbs.info(device_mac='2CAA8E5B13B1') plugSLED = client.plugs.info(device_mac='7C78B2717462') if bulbS1.is_on: client.bulbs.turn_off(device_mac=bulbS1.mac, device_model=bulbS1.product.model, after=timedelta(hours=.05)) if bulbS2.is_on: client.bulbs.turn_off(device_mac=bulbS2.mac, device_model=bulbS2.product.model, after=timedelta(hours=.05)) if plugSLED.is_on: client.plugs.turn_off(device_mac=plugSLED.mac, device_model=plugSLED.product.model, after=timedelta(hours=.05)) print("off") stairspassage.when_pressed = closed stairspassage.when_released = open garagepassage.when_pressed = closed garagepassage.when_released = open pause()