from signal import signal, SIGINT from time import sleep, time from pyowm import OWM from pcf8574 import PCF8574 from digital import DigitalOut, DigitalIn, R_TRIG from blind import WindowBlind running = 1 def handler(signum, frame): global running running = 0 def getWindSpeed(city): owm = OWM('your-API-key') return owm.weather_at_place(city).get_weather().get_wind()['speed'] if __name__=="__main__": signal(SIGINT, handler) triggerUp, triggerDown = R_TRIG(), R_TRIG() lastWeatherCheck = 0 with PCF8574(bus=1, addr=0x20) as outputs, PCF8574(bus=1, addr=0x38) as inputs: outUp, outDown = DigitalOut(outputs, 0), DigitalOut(outputs, 1) inUp, inDown = DigitalIn(inputs, 0), DigitalIn(inputs, 1) blind = WindowBlind(20, 21, outUp, outDown) while running: if triggerUp(inUp.getValue()): blind.up() if triggerDown(inDown.getValue()): blind.down() if time() - lastWeatherCheck > 900: if getWindSpeed("Vienna,at") > 10: blind.up() lastWeatherCheck = time() blind.run() sleep(.05)