ich blutiger Python anfänger habe ein kleines Problem:
Hardware:
Raspberry -> MCP23017 -> ULN2803 -> 12V Finder Relais für hutschiene inkl. Freilaufdiode
Das ganze dient als Terrarium Steuerung. Nun...
Heute bin ich nach der Arbeit nachhause gekommen und musste feststellen das alles aus ist.
Ich bin mir nicht Sicher ob meine If abfragen so richtig gestaltet sind oder nicht...
Code: Alles auswählen
#!/usr/bin/python
from Adafruit_I2C import Adafruit_I2C
import smbus
import time
import datetime
///unnötiges entfern
if __name__ == '__main__':
Relais = Adafruit_MCP230XX(address = 0x20, num_gpios = 16) # MCP23017
# Set pins 0, 1 and 2 to output (you can set pins 0..15 this way)
Relais.config(0, Relais.OUTPUT)
Relais.config(1, Relais.OUTPUT)
Relais.config(2, Relais.OUTPUT)
Relais.config(8, Relais.OUTPUT)
Relais.config(9, Relais.OUTPUT)
Relais.config(10, Relais.OUTPUT)
Relais.config(11, Relais.OUTPUT)
Relais.config(12, Relais.OUTPUT)
Relais.config(13, Relais.OUTPUT)
Relais.config(15, Relais.OUTPUT)
HCIlockan = 0
HCIlockaus = 0
LSlockan = 0
LSlockaus = 0
Spotlockan = 0
Spotlockaus = 0
Halogenlockan = 0
Halogenlockaus = 0
Filterlockan = 0
Filterlockaus = 0
Wasserfalllockan = 0
Wasserfalllockaus = 0
LED1lockan = 0
LED1lockaus = 0
LED2lockan = 0
LED2lockaus = 0
LED3lockan = 0
LED3lockaus = 0
# Set pin 3 to input with the pullup resistor enabled
# mcp.config(3, mcp.INPUT)
# mcp.pullup(3, 1)
# Read input pin and display the results
# print "Pin 3 = %d" % (mcp.input(3) >> 3)
# Python speed test on output 0 toggling at max speed
while (True):
#Relais.output(9, 1)# Pin 0 High
now = datetime.datetime.now()
HCIAn = now.replace(hour=6, minute=0, second=0, microsecond=0)
HalogenAn = now.replace(hour=6, minute=2, second=0, microsecond=0)
LED1An = now.replace(hour=6, minute=2, second=0, microsecond=0)
LED2An = now.replace(hour=6, minute=2, second=0, microsecond=0)
LED3An = now.replace(hour=6, minute=2, second=40, microsecond=0)
FilterAn = now.replace(hour=6, minute=3, second=0, microsecond=0)
WasserfallAn = now.replace(hour=6, minute=3, second=10, microsecond=0)
LSAn = now.replace(hour=6, minute=10, second=0, microsecond=0)
SpotAn = now.replace(hour=6, minute=12, second=0, microsecond=0)
WasserfallAus = now.replace(hour=20, minute=0, second=0, microsecond=0)
HCIAus = now.replace(hour=21, minute=0, second=0, microsecond=0)
LSAus = now.replace(hour=21, minute=30, second=0, microsecond=0)
SpotAus = now.replace(hour=21, minute=35, second=0, microsecond=0)
FilterAus = now.replace(hour=21, minute=36, second=0, microsecond=0)
LED1aus = now.replace(hour=21, minute=55, second=0, microsecond=0)
LED2aus = now.replace(hour=21, minute=55, second=0, microsecond=0)
LED3aus = now.replace(hour=21, minute=55, second=0, microsecond=0)
HalogenAus = now.replace(hour=21, minute=55, second=10, microsecond=0)
RegenAn = now.replace(hour=10, minute=0, second=0, microsecond=0)
RegenAus = now.replace(hour=21, minute=0, second=0, microsecond=0)
# <---- 12V Relais beginn ---->
if now >= HCIAn and now >= HCIAus and HCIlockaus == 0:
HCIlockaus = 1
Relais.output(8,0)
print now
print "HCI Aus"
HCIlockan = 0
if now <= HCIAus and now >= HCIAn and HCIlockan == 0:
HCIlockan = 1
Relais.output(8,1)
print now
print "HCI An"
HCIlockaus = 0
if now >= LSAn and now >= LSAus and LSlockaus == 0:
LSlockaus = 1
Relais.output(9,0)
print now
print "LS Aus"
LSlockan = 0
if now <= LSAus and now >= LSAn and LSlockan == 0:
LSlockan = 1
Relais.output(9,1)
print now
print "LS An"
LSlockaus = 0
if now >= SpotAn and now >= SpotAus and Spotlockaus == 0:
Spotlockaus = 1
Relais.output(10,0)
Relais.output(15,0)
print now
print "Spot Aus"
Spotlockan = 0
if now <= SpotAus and now >= SpotAn and Spotlockan == 0:
Spotlockan = 1
Relais.output(10,1)
Relais.output(15,1)
print now
print "Spot An"
Spotlockaus = 0
if now >= HalogenAn and now >= HalogenAus and Halogenlockaus == 0:
Halogenlockaus = 1
Relais.output(11,0)
Relais.output(0,0)
Relais.output(1,0)
Relais.output(2,0)
print now
print "Halogen Aus"
Halogenlockan = 0
if now <= HalogenAus and now >= HalogenAn and Halogenlockan == 0:
Halogenlockan = 1
Relais.output(11,1)
Relais.output(0,1)
Relais.output(1,1)
Relais.output(2,1)
print now
print "Halogen An"
Halogenlockaus = 0
if now >= FilterAn and now >= FilterAus and Filterlockaus == 0:
Filterlockaus = 1
Relais.output(12,0)
print now
print "Filter Aus"
Filterlockan = 0
if now <= FilterAus and now >= FilterAn and Filterlockan == 0:
Filterlockan = 1
Relais.output(12,1)
print now
print "Filter An"
Filterlockaus = 0
if now >= WasserfallAn and now >= WasserfallAus and Wasserfalllockaus == 0:
Wasserfalllockaus = 1
Relais.output(13,0)
print now
print "Wasserfall Aus"
Wasserfalllockan = 0
if now <= WasserfallAus and now >= WasserfallAn and Wasserfalllockan == 0:
Wasserfalllockan = 1
Relais.output(13,1)
print now
print "Wasserfall An"
Wasserfalllockaus = 0
# <---- 12V Relais Ende ---->
# <---- 5V Relais beginn ---->
"""
if now >= LED1An and now >= LED1aus and LED1lockaus == 0:
LED1lockaus = 1
Relais.output(0,0) //LED 1
print now
print "LED1 Aus"
LED1lockan = 0
if now <= LED1aus and now >= LED1An and LED1lockan == 0:
LED1lockan = 1
Relais.output(0,1)
print now
print "LED1 An"
LED1loclaus = 0
if now >= LED2An and now >= LED2aus and LED2lockaus == 0:
LED2lockaus = 1
Relais.output(1,0)
print now
print "LED2 Aus"
LED2lockan = 0
if now <= LED2aus and now >= LED2An and LED2lockan == 0:
LED2lockan = 1
Relais.output(1,1)
print now
print "LED2 An"
LED2loclaus = 0
if now >= LED3An and now >= LED3aus and LED3lockaus == 0:
LED3lockaus = 1
Relais.output(2,0)
print now
print "LED3 Aus"
LED3lockan = 0
if now <= LED3aus and now >= LED3An and LED3lockan == 0:
LED3lockan = 1
Relais.output(2,1)
print now
print "LED3 An"
LED3loclaus = 0
"""
# <---- 5V Relais Ende ---->
so: wo steckt der Wurm?
Ich möchte das HCI z.b. um 10 an geht um 21 ausgeht und wenn ich das Script mal während des Tages abschalte wegen änderungen und sich von der Zeit was geändert hat das beim zuschalten der gewollte zustand geschaltet wird und nicht erst bei erreichen der nächsten erfolgreichen zeitabfrage
ansonsten könnte ich die zeitabfragen ja so gestalten
if now == WasserfallAn and Wasserfalllockaus == 0:
//anschalten
if now == WasserfallAus and Wasserfalllockan == 0:
//abschalten
aber dann hab ich eben das was ich nicht möchte
könnt ihr mir bitte weiterhelfen?
vielen dank schonmal =)