Pilotage pompe et éclairage

De l'aquarium à la piscine en passant par l'arrosage du massif de fleurs et la photo ultra-rapide de gouttes qui tombent, le Raspberry Pi peut tout faire...

Modérateur : Francois

Topodoco
Messages : 62
Enregistré le : mer. 16 mars 2016 23:08

Re: Pilotage pompe et éclairage

Message par Topodoco » sam. 23 avr. 2016 22:16

Merci, je ne connaissait pas du tout.
Ça a l'air très bien.
Maintenant, je suis partit dans une idée de pouvoir mettre moi même les mains dans le cambouis.. et au besoin, adapter à mon utilisation.
Bien sur, je n'irai pas aussi loin que Yana, pas de commande vocale, pas d'appli Android...
Ça pourrait servir à d'autres personnes, mais pour le moment, cela me semble "trop complet" pour ce que j'ai en tête...
A voir dans quelques temps si le projet prend une autre tournure.
xavier1306 a écrit :Plutôt ce lien (deuxième leçon du tutoriel)
http://webiopi.trouch.com/Tutorial_Macros.html

Je vais récupérer les fichiers sur le Pi en qiestion et te les faire parvenir.
Merci, j'ai aussi déjà fouillé ce tuto... mais pour le moment je n'ai encore rien écrit...
J'essaye de mettre les idées en place dans ma tête avant de passer à l'écrit...
Merci aussi pour les fichiers, je vais attendre que tu ais l'occasion de les partager !

Sinon une petite piste déjà pour traiter les infos dans une page HTML: https://www.youtube.com/watch?v=PSFo5fw5APU
Il reste encore à transférer ces infos dans le fichier JSON, mais le 2nd script m'a l'air d’être déjà une bonne base pour récupérer toutes les infos utiles.

parrain27
Raspinaute
Messages : 905
Enregistré le : lun. 1 déc. 2014 13:46

Re: Pilotage pompe et éclairage

Message par parrain27 » sam. 23 avr. 2016 22:17

Non mate son blog il fait beaucoup de choses tu trouveras peut-être ton bonheur

Topodoco
Messages : 62
Enregistré le : mer. 16 mars 2016 23:08

Re: Pilotage pompe et éclairage

Message par Topodoco » mar. 10 mai 2016 12:12

Voila, le projet avance pas à pas...
Modifications apportées depuis l'ancienne version:
- éclairage cuisine d'été en sortie 5
- protection de la pompe "dôme solaire" en la désactivant si la pompe "filtration" est en fonction
- activation d'une règle, uniquement si le jour sélectionné est le bon

Il reste donc toujours:
- assigner les sorties pour les 8 relais
- initialisation des sorties lors du démarrage
- à programmer l'interface WEB pour piloter manuellement les sorties
- à programmer l'interface WEB pour paramétrer les règles automatiques
- sauver les règles dans un fichier JSON de manière à ne pas perdre les paramètres en cas de redémarrage de la framboise
- ajouter les sondes de température et programmer le pilotage de la pompe "dôme solaire"
- ajouter un bouton (sur l'interface Web ?) pour éteindre proprement la framboise
- enfin faire quelques essais !! bah oui pour le moment tout n'est que théorique...

Le code:

Code : Tout sélectionner

import webiopi
import datetime

GPIO = webiopi.GPIO

# Assignation des sorties
TERRASSE = 17 # GPIO pin using BCM numbering
PISCINEBLANC = 17 # GPIO pin using BCM numbering
PISCINECOULEURS = 17 # GPIO pin using BCM numbering
ABRISJARDIN = 17 # GPIO pin using BCM numbering
CUISINE = 17 # GPIO pin using BCM numbering
FILTRATION = 17 # GPIO pin using BCM numbering
DOMESOLAIRE = 17 # GPIO pin using BCM numbering
PRESENCE = 17 # GPIO pin using BCM numbering

# Règle1
actif_1 = 1
sortie1_1 = 0
sortie2_1 = 0
sortie3_1 = 0
sortie4_1 = 0
sortie5_1 = 0
sortie6_1 = 1
sortie7_1 = 0
Lu_1 = 1
Ma_1 = 1
Me_1 = 0
Je_1 = 1
Ve_1 = 1
Sa_1 = 0
Di_1 = 0
jour_debut_1 = 1
mois_debut_1 = 5
heure_debut_1 = 11
minutes_debut_1 = 0
jour_fin_1 = 30
mois_fin_1 = 9
heure_fin_1 = 15
minutes_fin_1 = 30

# Règle2
actif_2 = 1
sortie1_2 = 0
sortie2_2 = 0
sortie3_2 = 0
sortie4_2 = 0
sortie5_2 = 0
sortie6_2 = 1
sortie7_2 = 0
Lu_2 = 0
Ma_2 = 0
Me_2 = 1
Je_2 = 0
Ve_2 = 0
Sa_2 = 1
Di_2 = 1
jour_debut_2 = 1
mois_debut_2 = 5
heure_debut_2 = 10
minutes_debut_2 = 0
jour_fin_2 = 30
mois_fin_2 = 9
heure_fin_2 = 14
minutes_fin_2 = 0

#Règle3
actif_3 = 0
sortie1_3 = 0
sortie2_3 = 0
sortie3_3 = 0
sortie4_3 = 0
sortie5_3 = 0
sortie6_3 = 0
sortie7_3 = 0
Lu_3 = 0
Ma_3 = 0
Me_3 = 0
Je_3 = 0
Ve_3 = 0
Sa_3 = 0
Di_3 = 0
jour_debut_3 = 1
mois_debut_3 = 1
heure_debut_3 = 0
minutes_debut_3 = 0
jour_fin_3 = 1
mois_fin_3 = 1
heure_fin_3 = 0
minutes_fin_3 = 0

#Règle4
actif_4 = 0
sortie1_4 = 0
sortie2_4 = 0
sortie3_4 = 0
sortie4_4 = 0
sortie5_4 = 0
sortie6_4 = 0
sortie7_4 = 0
Lu_4 = 0
Ma_4 = 0
Me_4 = 0
Je_4 = 0
Ve_4 = 0
Sa_4 = 0
Di_4 = 0
jour_debut_4 = 1
mois_debut_4 = 1
heure_debut_4 = 0
minutes_debut_4 = 0
jour_fin_4 = 1
mois_fin_4 = 1
heure_fin_4 = 0
minutes_fin_4 = 0

#Règle5
actif_5 = 0
sortie1_5 = 0
sortie2_5 = 0
sortie3_5 = 0
sortie4_5 = 0
sortie5_5 = 0
sortie6_5 = 0
sortie7_5 = 0
Lu_5 = 0
Ma_5 = 0
Me_5 = 0
Je_5 = 0
Ve_5 = 0
Sa_5 = 0
Di_5 = 0
jour_debut_5 = 1
mois_debut_5 = 1
heure_debut_5 = 0
minutes_debut_5 = 0
jour_fin_5 = 1
mois_fin_5 = 1
heure_fin_5 = 0
minutes_fin_5 = 0

#RègleRAZ
actif_RAZ = 1
sortie1_RAZ = 1
sortie2_RAZ = 1
sortie3_RAZ = 1
sortie4_RAZ = 1
sortie5_RAZ = 1
sortie6_RAZ = 0
sortie7_RAZ = 0
heure_RAZ = 8
minutes_RAZ = 0

# setup function is automatically called at WebIOPi startup
def setup():
    # set the GPIO used by the light to output
    GPIO.setFunction(TERRASSE, GPIO.OUT)
	GPIO.setFunction(PISCINEBLANC, GPIO.OUT)
	GPIO.setFunction(PISCINECOULEURS, GPIO.OUT)
	GPIO.setFunction(ABRISJARDIN, GPIO.OUT)
	GPIO.setFunction(CUISINE, GPIO.OUT)
	GPIO.setFunction(FILTRATION, GPIO.OUT)
	GPIO.setFunction(DOMESOLAIRE, GPIO.OUT)
	GPIO.setFunction(PRESENCE, GPIO.OUT)

# retrieve current datetime
now = datetime.datetime.now()
act_day = datetime.isoweekday()

	# Initialisation des sorties relais 1-7 (la sortie 8 tenant compte de l'état des sorties 1-5 sera piloté automatiquement).
	# Initialisation sortie TERRASSE (sortie 1)	

	# Initialisation sortie PISCINEBLANC (sortie 2)
			   
	# Initialisation sortie PISCINECOULEURS (sortie 3)
	
	# Initialisation sortie ABRISJARDIN (sortie 4)
	
	# Initialisation sortie CUISINE (sortie 5)
	
	# Initialisation sortie FILTRATION (sortie 6)
	
	# Initialisation sortie DOMESOLAIRE (sortie 7)


# loop function is repeatedly called by WebIOPi 
def loop():
    # retrieve current datetime
    now = datetime.datetime.now()
	act_day = datetime.isoweekday()

	# Gestion sortie TERRASSE (sortie 1)
	# Activation sortie TERRASSE (sortie 1)
	if ((now.second == 0) and ((((actif_1 == 1) and (sortie1_1 == 1) and (((act_day == 1) and (Lu_1 == 1)) or ((act_day == 2) and (Ma_1 == 1)) or ((act_day == 3) and (Me_1 == 1)) or ((act_day == 4) and (Je_1 == 1)) or ((act_day == 5) and (Ve_1 == 1)) or ((act_day == 6) and (Sa_1 == 1)) or ((act_day == 7) and (Di_1 == 1)))) and ((((now.month > mois_debut_1) and (now.month < mois_fin_1)) or ((now.month == mois_debut_1) and (now.day >=  jour_debut_1)) or ((now.month == mois_fin_1) and (now.day <= jour_fin_1))) and (now.hour == heure_debut_1) and (now.minute == minutes_debut_1))) or (((actif_2 == 1) and (sortie1_2 == 1) and (((act_day == 1) and (Lu_2 == 1)) or ((act_day == 2) and (Ma_2 == 1)) or ((act_day == 3) and (Me_2 == 1)) or ((act_day == 4) and (Je_2 == 1)) or ((act_day == 5) and (Ve_2 == 1)) or ((act_day == 6) and (Sa_2 == 1)) or ((act_day == 7) and (Di_2 == 1)))) and ((((now.month > mois_debut_2) and (now.month < mois_fin_2)) or ((now.month == mois_debut_2) and (now.day >=  jour_debut_2)) or ((now.month == mois_fin_2) and (now.day <= jour_fin_2))) and (now.hour == heure_debut_2) and (now.minute == minutes_debut_2))) or (((actif_3 == 1) and (sortie1_3 == 1) and (((act_day == 1) and (Lu_3 == 1)) or ((act_day == 2) and (Ma_3 == 1)) or ((act_day == 3) and (Me_3 == 1)) or ((act_day == 4) and (Je_3 == 1)) or ((act_day == 5) and (Ve_3 == 1)) or ((act_day == 6) and (Sa_3 == 1)) or ((act_day == 7) and (Di_3 == 1)))) and ((((now.month > mois_debut_3) and (now.month < mois_fin_3)) or ((now.month == mois_debut_3) and (now.day >=  jour_debut_3)) or ((now.month == mois_fin_3) and (now.day <= jour_fin_3))) and (now.hour == heure_debut_3) and (now.minute == minutes_debut_3))) or (((actif_4 == 1) and (sortie1_4 == 1) and (((act_day == 1) and (Lu_4 == 1)) or ((act_day == 2) and (Ma_4 == 1)) or ((act_day == 3) and (Me_4 == 1)) or ((act_day == 4) and (Je_4 == 1)) or ((act_day == 5) and (Ve_4 == 1)) or ((act_day == 6) and (Sa_4 == 1)) or ((act_day == 7) and (Di_4 == 1)))) and ((((now.month > mois_debut_4) and (now.month < mois_fin_4)) or ((now.month == mois_debut_4) and (now.day >=  jour_debut_4)) or ((now.month == mois_fin_4) and (now.day <= jour_fin_4))) and (now.hour == heure_debut_4) and (now.minute == minutes_debut_4))) or (((actif_5 == 1) and (sortie1_5 == 1) and (((act_day == 1) and (Lu_5 == 1)) or ((act_day == 2) and (Ma_5 == 1)) or ((act_day == 3) and (Me_5 == 1)) or ((act_day == 4) and (Je_5 == 1)) or ((act_day == 5) and (Ve_5 == 1)) or ((act_day == 6) and (Sa_5 == 1)) or ((act_day == 7) and (Di_5 == 1)))) and ((((now.month > mois_debut_5) and (now.month < mois_fin_5)) or ((now.month == mois_debut_5) and (now.day >=  jour_debut_5)) or ((now.month == mois_fin_5) and (now.day <= jour_fin_5))) and (now.hour == heure_debut_5) and (now.minute == minutes_debut_5))))):
		   if (GPIO.digitalRead(TERRASSE) == GPIO.LOW):
               GPIO.digitalWrite(TERRASSE, GPIO.HIGH)
	# Désactivation sortie TERRASSE (sortie 1)
	if ((now.second == 0) and ((((actif_1 == 1) and (sortie1_1 == 1) and (((act_day == 1) and (Lu_1 == 1)) or ((act_day == 2) and (Ma_1 == 1)) or ((act_day == 3) and (Me_1 == 1)) or ((act_day == 4) and (Je_1 == 1)) or ((act_day == 5) and (Ve_1 == 1)) or ((act_day == 6) and (Sa_1 == 1)) or ((act_day == 7) and (Di_1 == 1)))) and ((((now.month > mois_debut_1) and (now.month < mois_fin_1)) or ((now.month == mois_debut_1) and (now.day >=  jour_debut_1)) or ((now.month == mois_fin_1) and (now.day <= jour_fin_1))) and (now.hour == heure_fin_1) and (now.minute == minutes_fin_1))) or (((actif_2 == 1) and (sortie1_2 == 1) and (((act_day == 1) and (Lu_2 == 1)) or ((act_day == 2) and (Ma_2 == 1)) or ((act_day == 3) and (Me_2 == 1)) or ((act_day == 4) and (Je_2 == 1)) or ((act_day == 5) and (Ve_2 == 1)) or ((act_day == 6) and (Sa_2 == 1)) or ((act_day == 7) and (Di_2 == 1)))) and ((((now.month > mois_debut_2) and (now.month < mois_fin_2)) or ((now.month == mois_debut_2) and (now.day >=  jour_debut_2)) or ((now.month == mois_fin_2) and (now.day <= jour_fin_2))) and (now.hour == heure_fin_2) and (now.minute == minutes_fin_2))) or (((actif_3 == 1) and (sortie1_3 == 1) and (((act_day == 1) and (Lu_3 == 1)) or ((act_day == 2) and (Ma_3 == 1)) or ((act_day == 3) and (Me_3 == 1)) or ((act_day == 4) and (Je_3 == 1)) or ((act_day == 5) and (Ve_3 == 1)) or ((act_day == 6) and (Sa_3 == 1)) or ((act_day == 7) and (Di_3 == 1)))) and ((((now.month > mois_debut_3) and (now.month < mois_fin_3)) or ((now.month == mois_debut_3) and (now.day >=  jour_debut_3)) or ((now.month == mois_fin_3) and (now.day <= jour_fin_3))) and (now.hour == heure_fin_3) and (now.minute == minutes_fin_3))) or (((actif_4 == 1) and (sortie1_4 == 1) and (((act_day == 1) and (Lu_4 == 1)) or ((act_day == 2) and (Ma_4 == 1)) or ((act_day == 3) and (Me_4 == 1)) or ((act_day == 4) and (Je_4 == 1)) or ((act_day == 5) and (Ve_4 == 1)) or ((act_day == 6) and (Sa_4 == 1)) or ((act_day == 7) and (Di_4 == 1)))) and ((((now.month > mois_debut_4) and (now.month < mois_fin_4)) or ((now.month == mois_debut_4) and (now.day >=  jour_debut_4)) or ((now.month == mois_fin_4) and (now.day <= jour_fin_4))) and (now.hour == heure_fin_4) and (now.minute == minutes_fin_4))) or (((actif_5 == 1) and (sortie1_5 == 1) and (((act_day == 1) and (Lu_5 == 1)) or ((act_day == 2) and (Ma_5 == 1)) or ((act_day == 3) and (Me_5 == 1)) or ((act_day == 4) and (Je_5 == 1)) or ((act_day == 5) and (Ve_5 == 1)) or ((act_day == 6) and (Sa_5 == 1)) or ((act_day == 7) and (Di_5 == 1)))) and ((((now.month > mois_debut_5) and (now.month < mois_fin_5)) or ((now.month == mois_debut_5) and (now.day >=  jour_debut_5)) or ((now.month == mois_fin_5) and (now.day <= jour_fin_5))) and (now.hour == heure_fin_5) and (now.minute == minutes_fin_5))))):
		   if (GPIO.digitalRead(TERRASSE) == GPIO.HIGH):
               GPIO.digitalWrite(TERRASSE, GPIO.LOW)
			   
	# Gestion sortie PISCINEBLANC (sortie 2)
	# Activation sortie PISCINEBLANC (sortie 2)
	if ((now.second == 0) and ((((actif_1 == 1) and (sortie2_1 == 1) and (((act_day == 1) and (Lu_1 == 1)) or ((act_day == 2) and (Ma_1 == 1)) or ((act_day == 3) and (Me_1 == 1)) or ((act_day == 4) and (Je_1 == 1)) or ((act_day == 5) and (Ve_1 == 1)) or ((act_day == 6) and (Sa_1 == 1)) or ((act_day == 7) and (Di_1 == 1)))) and ((((now.month > mois_debut_1) and (now.month < mois_fin_1)) or ((now.month == mois_debut_1) and (now.day >=  jour_debut_1)) or ((now.month == mois_fin_1) and (now.day <= jour_fin_1))) and (now.hour == heure_debut_1) and (now.minute == minutes_debut_1))) or (((actif_2 == 1) and (sortie2_2 == 1) and (((act_day == 1) and (Lu_2 == 1)) or ((act_day == 2) and (Ma_2 == 1)) or ((act_day == 3) and (Me_2 == 1)) or ((act_day == 4) and (Je_2 == 1)) or ((act_day == 5) and (Ve_2 == 1)) or ((act_day == 6) and (Sa_2 == 1)) or ((act_day == 7) and (Di_2 == 1)))) and ((((now.month > mois_debut_2) and (now.month < mois_fin_2)) or ((now.month == mois_debut_2) and (now.day >=  jour_debut_2)) or ((now.month == mois_fin_2) and (now.day <= jour_fin_2))) and (now.hour == heure_debut_2) and (now.minute == minutes_debut_2))) or (((actif_3 == 1) and (sortie2_3 == 1) and (((act_day == 1) and (Lu_3 == 1)) or ((act_day == 2) and (Ma_3 == 1)) or ((act_day == 3) and (Me_3 == 1)) or ((act_day == 4) and (Je_3 == 1)) or ((act_day == 5) and (Ve_3 == 1)) or ((act_day == 6) and (Sa_3 == 1)) or ((act_day == 7) and (Di_3 == 1)))) and ((((now.month > mois_debut_3) and (now.month < mois_fin_3)) or ((now.month == mois_debut_3) and (now.day >=  jour_debut_3)) or ((now.month == mois_fin_3) and (now.day <= jour_fin_3))) and (now.hour == heure_debut_3) and (now.minute == minutes_debut_3))) or (((actif_4 == 1) and (sortie2_4 == 1) and (((act_day == 1) and (Lu_4 == 1)) or ((act_day == 2) and (Ma_4 == 1)) or ((act_day == 3) and (Me_4 == 1)) or ((act_day == 4) and (Je_4 == 1)) or ((act_day == 5) and (Ve_4 == 1)) or ((act_day == 6) and (Sa_4 == 1)) or ((act_day == 7) and (Di_4 == 1)))) and ((((now.month > mois_debut_4) and (now.month < mois_fin_4)) or ((now.month == mois_debut_4) and (now.day >=  jour_debut_4)) or ((now.month == mois_fin_4) and (now.day <= jour_fin_4))) and (now.hour == heure_debut_4) and (now.minute == minutes_debut_4))) or (((actif_5 == 1) and (sortie2_5 == 1) and (((act_day == 1) and (Lu_5 == 1)) or ((act_day == 2) and (Ma_5 == 1)) or ((act_day == 3) and (Me_5 == 1)) or ((act_day == 4) and (Je_5 == 1)) or ((act_day == 5) and (Ve_5 == 1)) or ((act_day == 6) and (Sa_5 == 1)) or ((act_day == 7) and (Di_5 == 1)))) and ((((now.month > mois_debut_5) and (now.month < mois_fin_5)) or ((now.month == mois_debut_5) and (now.day >=  jour_debut_5)) or ((now.month == mois_fin_5) and (now.day <= jour_fin_5))) and (now.hour == heure_debut_5) and (now.minute == minutes_debut_5))))):
		   if (GPIO.digitalRead(PISCINEBLANC) == GPIO.LOW):
               GPIO.digitalWrite(PISCINEBLANC, GPIO.HIGH)
	# Désactivation sortie PISCINEBLANC (sortie 2)
	if ((now.second == 0) and ((((actif_1 == 1) and (sortie2_1 == 1) and (((act_day == 1) and (Lu_1 == 1)) or ((act_day == 2) and (Ma_1 == 1)) or ((act_day == 3) and (Me_1 == 1)) or ((act_day == 4) and (Je_1 == 1)) or ((act_day == 5) and (Ve_1 == 1)) or ((act_day == 6) and (Sa_1 == 1)) or ((act_day == 7) and (Di_1 == 1)))) and ((((now.month > mois_debut_1) and (now.month < mois_fin_1)) or ((now.month == mois_debut_1) and (now.day >=  jour_debut_1)) or ((now.month == mois_fin_1) and (now.day <= jour_fin_1))) and (now.hour == heure_fin_1) and (now.minute == minutes_fin_1))) or (((actif_2 == 1) and (sortie2_2 == 1) and (((act_day == 1) and (Lu_2 == 1)) or ((act_day == 2) and (Ma_2 == 1)) or ((act_day == 3) and (Me_2 == 1)) or ((act_day == 4) and (Je_2 == 1)) or ((act_day == 5) and (Ve_2 == 1)) or ((act_day == 6) and (Sa_2 == 1)) or ((act_day == 7) and (Di_2 == 1)))) and ((((now.month > mois_debut_2) and (now.month < mois_fin_2)) or ((now.month == mois_debut_2) and (now.day >=  jour_debut_2)) or ((now.month == mois_fin_2) and (now.day <= jour_fin_2))) and (now.hour == heure_fin_2) and (now.minute == minutes_fin_2))) or (((actif_3 == 1) and (sortie2_3 == 1) and (((act_day == 1) and (Lu_3 == 1)) or ((act_day == 2) and (Ma_3 == 1)) or ((act_day == 3) and (Me_3 == 1)) or ((act_day == 4) and (Je_3 == 1)) or ((act_day == 5) and (Ve_3 == 1)) or ((act_day == 6) and (Sa_3 == 1)) or ((act_day == 7) and (Di_3 == 1)))) and ((((now.month > mois_debut_3) and (now.month < mois_fin_3)) or ((now.month == mois_debut_3) and (now.day >=  jour_debut_3)) or ((now.month == mois_fin_3) and (now.day <= jour_fin_3))) and (now.hour == heure_fin_3) and (now.minute == minutes_fin_3))) or (((actif_4 == 1) and (sortie2_4 == 1) and (((act_day == 1) and (Lu_4 == 1)) or ((act_day == 2) and (Ma_4 == 1)) or ((act_day == 3) and (Me_4 == 1)) or ((act_day == 4) and (Je_4 == 1)) or ((act_day == 5) and (Ve_4 == 1)) or ((act_day == 6) and (Sa_4 == 1)) or ((act_day == 7) and (Di_4 == 1)))) and ((((now.month > mois_debut_4) and (now.month < mois_fin_4)) or ((now.month == mois_debut_4) and (now.day >=  jour_debut_4)) or ((now.month == mois_fin_4) and (now.day <= jour_fin_4))) and (now.hour == heure_fin_4) and (now.minute == minutes_fin_4))) or (((actif_5 == 1) and (sortie2_5 == 1) and (((act_day == 1) and (Lu_5 == 1)) or ((act_day == 2) and (Ma_5 == 1)) or ((act_day == 3) and (Me_5 == 1)) or ((act_day == 4) and (Je_5 == 1)) or ((act_day == 5) and (Ve_5 == 1)) or ((act_day == 6) and (Sa_5 == 1)) or ((act_day == 7) and (Di_5 == 1)))) and ((((now.month > mois_debut_5) and (now.month < mois_fin_5)) or ((now.month == mois_debut_5) and (now.day >=  jour_debut_5)) or ((now.month == mois_fin_5) and (now.day <= jour_fin_5))) and (now.hour == heure_fin_5) and (now.minute == minutes_fin_5))))):
		   if (GPIO.digitalRead(PISCINEBLANC) == GPIO.HIGH):
               GPIO.digitalWrite(PISCINEBLANC, GPIO.LOW)
			   
	# Gestion sortie PISCINECOULEURS (sortie 3)
	# Activation sortie PISCINECOULEURS (sortie 3)
	if ((now.second == 0) and ((((actif_1 == 1) and (sortie3_1 == 1) and (((act_day == 1) and (Lu_1 == 1)) or ((act_day == 2) and (Ma_1 == 1)) or ((act_day == 3) and (Me_1 == 1)) or ((act_day == 4) and (Je_1 == 1)) or ((act_day == 5) and (Ve_1 == 1)) or ((act_day == 6) and (Sa_1 == 1)) or ((act_day == 7) and (Di_1 == 1)))) and ((((now.month > mois_debut_1) and (now.month < mois_fin_1)) or ((now.month == mois_debut_1) and (now.day >=  jour_debut_1)) or ((now.month == mois_fin_1) and (now.day <= jour_fin_1))) and (now.hour == heure_debut_1) and (now.minute == minutes_debut_1))) or (((actif_2 == 1) and (sortie3_2 == 1) and (((act_day == 1) and (Lu_2 == 1)) or ((act_day == 2) and (Ma_2 == 1)) or ((act_day == 3) and (Me_2 == 1)) or ((act_day == 4) and (Je_2 == 1)) or ((act_day == 5) and (Ve_2 == 1)) or ((act_day == 6) and (Sa_2 == 1)) or ((act_day == 7) and (Di_2 == 1)))) and ((((now.month > mois_debut_2) and (now.month < mois_fin_2)) or ((now.month == mois_debut_2) and (now.day >=  jour_debut_2)) or ((now.month == mois_fin_2) and (now.day <= jour_fin_2))) and (now.hour == heure_debut_2) and (now.minute == minutes_debut_2))) or (((actif_3 == 1) and (sortie3_3 == 1) and (((act_day == 1) and (Lu_3 == 1)) or ((act_day == 2) and (Ma_3 == 1)) or ((act_day == 3) and (Me_3 == 1)) or ((act_day == 4) and (Je_3 == 1)) or ((act_day == 5) and (Ve_3 == 1)) or ((act_day == 6) and (Sa_3 == 1)) or ((act_day == 7) and (Di_3 == 1)))) and ((((now.month > mois_debut_3) and (now.month < mois_fin_3)) or ((now.month == mois_debut_3) and (now.day >=  jour_debut_3)) or ((now.month == mois_fin_3) and (now.day <= jour_fin_3))) and (now.hour == heure_debut_3) and (now.minute == minutes_debut_3))) or (((actif_4 == 1) and (sortie3_4 == 1) and (((act_day == 1) and (Lu_4 == 1)) or ((act_day == 2) and (Ma_4 == 1)) or ((act_day == 3) and (Me_4 == 1)) or ((act_day == 4) and (Je_4 == 1)) or ((act_day == 5) and (Ve_4 == 1)) or ((act_day == 6) and (Sa_4 == 1)) or ((act_day == 7) and (Di_4 == 1)))) and ((((now.month > mois_debut_4) and (now.month < mois_fin_4)) or ((now.month == mois_debut_4) and (now.day >=  jour_debut_4)) or ((now.month == mois_fin_4) and (now.day <= jour_fin_4))) and (now.hour == heure_debut_4) and (now.minute == minutes_debut_4))) or (((actif_5 == 1) and (sortie3_5 == 1) and (((act_day == 1) and (Lu_5 == 1)) or ((act_day == 2) and (Ma_5 == 1)) or ((act_day == 3) and (Me_5 == 1)) or ((act_day == 4) and (Je_5 == 1)) or ((act_day == 5) and (Ve_5 == 1)) or ((act_day == 6) and (Sa_5 == 1)) or ((act_day == 7) and (Di_5 == 1)))) and ((((now.month > mois_debut_5) and (now.month < mois_fin_5)) or ((now.month == mois_debut_5) and (now.day >=  jour_debut_5)) or ((now.month == mois_fin_5) and (now.day <= jour_fin_5))) and (now.hour == heure_debut_5) and (now.minute == minutes_debut_5))))):
		   if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.LOW):
               GPIO.digitalWrite(PISCINECOULEURS, GPIO.HIGH)
	# Désactivation sortie PISCINECOULEURS (sortie 3)
	if ((now.second == 0) and ((((actif_1 == 1) and (sortie3_1 == 1) and (((act_day == 1) and (Lu_1 == 1)) or ((act_day == 2) and (Ma_1 == 1)) or ((act_day == 3) and (Me_1 == 1)) or ((act_day == 4) and (Je_1 == 1)) or ((act_day == 5) and (Ve_1 == 1)) or ((act_day == 6) and (Sa_1 == 1)) or ((act_day == 7) and (Di_1 == 1)))) and ((((now.month > mois_debut_1) and (now.month < mois_fin_1)) or ((now.month == mois_debut_1) and (now.day >=  jour_debut_1)) or ((now.month == mois_fin_1) and (now.day <= jour_fin_1))) and (now.hour == heure_fin_1) and (now.minute == minutes_fin_1))) or (((actif_2 == 1) and (sortie3_2 == 1) and (((act_day == 1) and (Lu_2 == 1)) or ((act_day == 2) and (Ma_2 == 1)) or ((act_day == 3) and (Me_2 == 1)) or ((act_day == 4) and (Je_2 == 1)) or ((act_day == 5) and (Ve_2 == 1)) or ((act_day == 6) and (Sa_2 == 1)) or ((act_day == 7) and (Di_2 == 1)))) and ((((now.month > mois_debut_2) and (now.month < mois_fin_2)) or ((now.month == mois_debut_2) and (now.day >=  jour_debut_2)) or ((now.month == mois_fin_2) and (now.day <= jour_fin_2))) and (now.hour == heure_fin_2) and (now.minute == minutes_fin_2))) or (((actif_3 == 1) and (sortie3_3 == 1) and (((act_day == 1) and (Lu_3 == 1)) or ((act_day == 2) and (Ma_3 == 1)) or ((act_day == 3) and (Me_3 == 1)) or ((act_day == 4) and (Je_3 == 1)) or ((act_day == 5) and (Ve_3 == 1)) or ((act_day == 6) and (Sa_3 == 1)) or ((act_day == 7) and (Di_3 == 1)))) and ((((now.month > mois_debut_3) and (now.month < mois_fin_3)) or ((now.month == mois_debut_3) and (now.day >=  jour_debut_3)) or ((now.month == mois_fin_3) and (now.day <= jour_fin_3))) and (now.hour == heure_fin_3) and (now.minute == minutes_fin_3))) or (((actif_4 == 1) and (sortie3_4 == 1) and (((act_day == 1) and (Lu_4 == 1)) or ((act_day == 2) and (Ma_4 == 1)) or ((act_day == 3) and (Me_4 == 1)) or ((act_day == 4) and (Je_4 == 1)) or ((act_day == 5) and (Ve_4 == 1)) or ((act_day == 6) and (Sa_4 == 1)) or ((act_day == 7) and (Di_4 == 1)))) and ((((now.month > mois_debut_4) and (now.month < mois_fin_4)) or ((now.month == mois_debut_4) and (now.day >=  jour_debut_4)) or ((now.month == mois_fin_4) and (now.day <= jour_fin_4))) and (now.hour == heure_fin_4) and (now.minute == minutes_fin_4))) or (((actif_5 == 1) and (sortie3_5 == 1) and (((act_day == 1) and (Lu_5 == 1)) or ((act_day == 2) and (Ma_5 == 1)) or ((act_day == 3) and (Me_5 == 1)) or ((act_day == 4) and (Je_5 == 1)) or ((act_day == 5) and (Ve_5 == 1)) or ((act_day == 6) and (Sa_5 == 1)) or ((act_day == 7) and (Di_5 == 1)))) and ((((now.month > mois_debut_5) and (now.month < mois_fin_5)) or ((now.month == mois_debut_5) and (now.day >=  jour_debut_5)) or ((now.month == mois_fin_5) and (now.day <= jour_fin_5))) and (now.hour == heure_fin_5) and (now.minute == minutes_fin_5))))):
		   if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.HIGH):
               GPIO.digitalWrite(PISCINECOULEURS, GPIO.LOW)
		
	# Gestion sortie ABRISJARDIN (sortie 4)
	# Activation sortie ABRISJARDIN (sortie 4)
	if ((now.second == 0) and ((((actif_1 == 1) and (sortie4_1 == 1) and (((act_day == 1) and (Lu_1 == 1)) or ((act_day == 2) and (Ma_1 == 1)) or ((act_day == 3) and (Me_1 == 1)) or ((act_day == 4) and (Je_1 == 1)) or ((act_day == 5) and (Ve_1 == 1)) or ((act_day == 6) and (Sa_1 == 1)) or ((act_day == 7) and (Di_1 == 1)))) and ((((now.month > mois_debut_1) and (now.month < mois_fin_1)) or ((now.month == mois_debut_1) and (now.day >=  jour_debut_1)) or ((now.month == mois_fin_1) and (now.day <= jour_fin_1))) and (now.hour == heure_debut_1) and (now.minute == minutes_debut_1))) or (((actif_2 == 1) and (sortie4_2 == 1) and (((act_day == 1) and (Lu_2 == 1)) or ((act_day == 2) and (Ma_2 == 1)) or ((act_day == 3) and (Me_2 == 1)) or ((act_day == 4) and (Je_2 == 1)) or ((act_day == 5) and (Ve_2 == 1)) or ((act_day == 6) and (Sa_2 == 1)) or ((act_day == 7) and (Di_2 == 1)))) and ((((now.month > mois_debut_2) and (now.month < mois_fin_2)) or ((now.month == mois_debut_2) and (now.day >=  jour_debut_2)) or ((now.month == mois_fin_2) and (now.day <= jour_fin_2))) and (now.hour == heure_debut_2) and (now.minute == minutes_debut_2))) or (((actif_3 == 1) and (sortie4_3 == 1) and (((act_day == 1) and (Lu_3 == 1)) or ((act_day == 2) and (Ma_3 == 1)) or ((act_day == 3) and (Me_3 == 1)) or ((act_day == 4) and (Je_3 == 1)) or ((act_day == 5) and (Ve_3 == 1)) or ((act_day == 6) and (Sa_3 == 1)) or ((act_day == 7) and (Di_3 == 1)))) and ((((now.month > mois_debut_3) and (now.month < mois_fin_3)) or ((now.month == mois_debut_3) and (now.day >=  jour_debut_3)) or ((now.month == mois_fin_3) and (now.day <= jour_fin_3))) and (now.hour == heure_debut_3) and (now.minute == minutes_debut_3))) or (((actif_4 == 1) and (sortie4_4 == 1) and (((act_day == 1) and (Lu_4 == 1)) or ((act_day == 2) and (Ma_4 == 1)) or ((act_day == 3) and (Me_4 == 1)) or ((act_day == 4) and (Je_4 == 1)) or ((act_day == 5) and (Ve_4 == 1)) or ((act_day == 6) and (Sa_4 == 1)) or ((act_day == 7) and (Di_4 == 1)))) and ((((now.month > mois_debut_4) and (now.month < mois_fin_4)) or ((now.month == mois_debut_4) and (now.day >=  jour_debut_4)) or ((now.month == mois_fin_4) and (now.day <= jour_fin_4))) and (now.hour == heure_debut_4) and (now.minute == minutes_debut_4))) or (((actif_5 == 1) and (sortie4_5 == 1) and (((act_day == 1) and (Lu_5 == 1)) or ((act_day == 2) and (Ma_5 == 1)) or ((act_day == 3) and (Me_5 == 1)) or ((act_day == 4) and (Je_5 == 1)) or ((act_day == 5) and (Ve_5 == 1)) or ((act_day == 6) and (Sa_5 == 1)) or ((act_day == 7) and (Di_5 == 1)))) and ((((now.month > mois_debut_5) and (now.month < mois_fin_5)) or ((now.month == mois_debut_5) and (now.day >=  jour_debut_5)) or ((now.month == mois_fin_5) and (now.day <= jour_fin_5))) and (now.hour == heure_debut_5) and (now.minute == minutes_debut_5))))):
		   if (GPIO.digitalRead(ABRISJARDIN) == GPIO.LOW):
               GPIO.digitalWrite(ABRISJARDIN, GPIO.HIGH)
	# Désactivation sortie ABRISJARDIN (sortie 4)
	if ((now.second == 0) and ((((actif_1 == 1) and (sortie4_1 == 1) and (((act_day == 1) and (Lu_1 == 1)) or ((act_day == 2) and (Ma_1 == 1)) or ((act_day == 3) and (Me_1 == 1)) or ((act_day == 4) and (Je_1 == 1)) or ((act_day == 5) and (Ve_1 == 1)) or ((act_day == 6) and (Sa_1 == 1)) or ((act_day == 7) and (Di_1 == 1)))) and ((((now.month > mois_debut_1) and (now.month < mois_fin_1)) or ((now.month == mois_debut_1) and (now.day >=  jour_debut_1)) or ((now.month == mois_fin_1) and (now.day <= jour_fin_1))) and (now.hour == heure_fin_1) and (now.minute == minutes_fin_1))) or (((actif_2 == 1) and (sortie4_2 == 1) and (((act_day == 1) and (Lu_2 == 1)) or ((act_day == 2) and (Ma_2 == 1)) or ((act_day == 3) and (Me_2 == 1)) or ((act_day == 4) and (Je_2 == 1)) or ((act_day == 5) and (Ve_2 == 1)) or ((act_day == 6) and (Sa_2 == 1)) or ((act_day == 7) and (Di_2 == 1)))) and ((((now.month > mois_debut_2) and (now.month < mois_fin_2)) or ((now.month == mois_debut_2) and (now.day >=  jour_debut_2)) or ((now.month == mois_fin_2) and (now.day <= jour_fin_2))) and (now.hour == heure_fin_2) and (now.minute == minutes_fin_2))) or (((actif_3 == 1) and (sortie4_3 == 1) and (((act_day == 1) and (Lu_3 == 1)) or ((act_day == 2) and (Ma_3 == 1)) or ((act_day == 3) and (Me_3 == 1)) or ((act_day == 4) and (Je_3 == 1)) or ((act_day == 5) and (Ve_3 == 1)) or ((act_day == 6) and (Sa_3 == 1)) or ((act_day == 7) and (Di_3 == 1)))) and ((((now.month > mois_debut_3) and (now.month < mois_fin_3)) or ((now.month == mois_debut_3) and (now.day >=  jour_debut_3)) or ((now.month == mois_fin_3) and (now.day <= jour_fin_3))) and (now.hour == heure_fin_3) and (now.minute == minutes_fin_3))) or (((actif_4 == 1) and (sortie4_4 == 1) and (((act_day == 1) and (Lu_4 == 1)) or ((act_day == 2) and (Ma_4 == 1)) or ((act_day == 3) and (Me_4 == 1)) or ((act_day == 4) and (Je_4 == 1)) or ((act_day == 5) and (Ve_4 == 1)) or ((act_day == 6) and (Sa_4 == 1)) or ((act_day == 7) and (Di_4 == 1)))) and ((((now.month > mois_debut_4) and (now.month < mois_fin_4)) or ((now.month == mois_debut_4) and (now.day >=  jour_debut_4)) or ((now.month == mois_fin_4) and (now.day <= jour_fin_4))) and (now.hour == heure_fin_4) and (now.minute == minutes_fin_4))) or (((actif_5 == 1) and (sortie4_5 == 1) and (((act_day == 1) and (Lu_5 == 1)) or ((act_day == 2) and (Ma_5 == 1)) or ((act_day == 3) and (Me_5 == 1)) or ((act_day == 4) and (Je_5 == 1)) or ((act_day == 5) and (Ve_5 == 1)) or ((act_day == 6) and (Sa_5 == 1)) or ((act_day == 7) and (Di_5 == 1)))) and ((((now.month > mois_debut_5) and (now.month < mois_fin_5)) or ((now.month == mois_debut_5) and (now.day >=  jour_debut_5)) or ((now.month == mois_fin_5) and (now.day <= jour_fin_5))) and (now.hour == heure_fin_5) and (now.minute == minutes_fin_5))))):
		   if (GPIO.digitalRead(ABRISJARDIN) == GPIO.HIGH):
               GPIO.digitalWrite(ABRISJARDIN, GPIO.LOW)
	
	# Gestion sortie CUISINE (sortie 5)
	# Activation sortie CUISINE (sortie 5)
	if ((now.second == 0) and ((((actif_1 == 1) and (sortie5_1 == 1) and (((act_day == 1) and (Lu_1 == 1)) or ((act_day == 2) and (Ma_1 == 1)) or ((act_day == 3) and (Me_1 == 1)) or ((act_day == 4) and (Je_1 == 1)) or ((act_day == 5) and (Ve_1 == 1)) or ((act_day == 6) and (Sa_1 == 1)) or ((act_day == 7) and (Di_1 == 1)))) and ((((now.month > mois_debut_1) and (now.month < mois_fin_1)) or ((now.month == mois_debut_1) and (now.day >=  jour_debut_1)) or ((now.month == mois_fin_1) and (now.day <= jour_fin_1))) and (now.hour == heure_debut_1) and (now.minute == minutes_debut_1))) or (((actif_2 == 1) and (sortie5_2 == 1) and (((act_day == 1) and (Lu_2 == 1)) or ((act_day == 2) and (Ma_2 == 1)) or ((act_day == 3) and (Me_2 == 1)) or ((act_day == 4) and (Je_2 == 1)) or ((act_day == 5) and (Ve_2 == 1)) or ((act_day == 6) and (Sa_2 == 1)) or ((act_day == 7) and (Di_2 == 1)))) and ((((now.month > mois_debut_2) and (now.month < mois_fin_2)) or ((now.month == mois_debut_2) and (now.day >=  jour_debut_2)) or ((now.month == mois_fin_2) and (now.day <= jour_fin_2))) and (now.hour == heure_debut_2) and (now.minute == minutes_debut_2))) or (((actif_3 == 1) and (sortie5_3 == 1) and (((act_day == 1) and (Lu_3 == 1)) or ((act_day == 2) and (Ma_3 == 1)) or ((act_day == 3) and (Me_3 == 1)) or ((act_day == 4) and (Je_3 == 1)) or ((act_day == 5) and (Ve_3 == 1)) or ((act_day == 6) and (Sa_3 == 1)) or ((act_day == 7) and (Di_3 == 1)))) and ((((now.month > mois_debut_3) and (now.month < mois_fin_3)) or ((now.month == mois_debut_3) and (now.day >=  jour_debut_3)) or ((now.month == mois_fin_3) and (now.day <= jour_fin_3))) and (now.hour == heure_debut_3) and (now.minute == minutes_debut_3))) or (((actif_4 == 1) and (sortie5_4 == 1) and (((act_day == 1) and (Lu_4 == 1)) or ((act_day == 2) and (Ma_4 == 1)) or ((act_day == 3) and (Me_4 == 1)) or ((act_day == 4) and (Je_4 == 1)) or ((act_day == 5) and (Ve_4 == 1)) or ((act_day == 6) and (Sa_4 == 1)) or ((act_day == 7) and (Di_4 == 1)))) and ((((now.month > mois_debut_4) and (now.month < mois_fin_4)) or ((now.month == mois_debut_4) and (now.day >=  jour_debut_4)) or ((now.month == mois_fin_4) and (now.day <= jour_fin_4))) and (now.hour == heure_debut_4) and (now.minute == minutes_debut_4))) or (((actif_5 == 1) and (sortie5_5 == 1) and (((act_day == 1) and (Lu_5 == 1)) or ((act_day == 2) and (Ma_5 == 1)) or ((act_day == 3) and (Me_5 == 1)) or ((act_day == 4) and (Je_5 == 1)) or ((act_day == 5) and (Ve_5 == 1)) or ((act_day == 6) and (Sa_5 == 1)) or ((act_day == 7) and (Di_5 == 1)))) and ((((now.month > mois_debut_5) and (now.month < mois_fin_5)) or ((now.month == mois_debut_5) and (now.day >=  jour_debut_5)) or ((now.month == mois_fin_5) and (now.day <= jour_fin_5))) and (now.hour == heure_debut_5) and (now.minute == minutes_debut_5))))):
		   if (GPIO.digitalRead(CUISINE) == GPIO.LOW):
               GPIO.digitalWrite(CUISINE, GPIO.HIGH)
	# Désactivation sortie CUISINE (sortie 5)
	if ((now.second == 0) and ((((actif_1 == 1) and (sortie5_1 == 1) and (((act_day == 1) and (Lu_1 == 1)) or ((act_day == 2) and (Ma_1 == 1)) or ((act_day == 3) and (Me_1 == 1)) or ((act_day == 4) and (Je_1 == 1)) or ((act_day == 5) and (Ve_1 == 1)) or ((act_day == 6) and (Sa_1 == 1)) or ((act_day == 7) and (Di_1 == 1)))) and ((((now.month > mois_debut_1) and (now.month < mois_fin_1)) or ((now.month == mois_debut_1) and (now.day >=  jour_debut_1)) or ((now.month == mois_fin_1) and (now.day <= jour_fin_1))) and (now.hour == heure_fin_1) and (now.minute == minutes_fin_1))) or (((actif_2 == 1) and (sortie5_2 == 1) and (((act_day == 1) and (Lu_2 == 1)) or ((act_day == 2) and (Ma_2 == 1)) or ((act_day == 3) and (Me_2 == 1)) or ((act_day == 4) and (Je_2 == 1)) or ((act_day == 5) and (Ve_2 == 1)) or ((act_day == 6) and (Sa_2 == 1)) or ((act_day == 7) and (Di_2 == 1)))) and ((((now.month > mois_debut_2) and (now.month < mois_fin_2)) or ((now.month == mois_debut_2) and (now.day >=  jour_debut_2)) or ((now.month == mois_fin_2) and (now.day <= jour_fin_2))) and (now.hour == heure_fin_2) and (now.minute == minutes_fin_2))) or (((actif_3 == 1) and (sortie5_3 == 1) and (((act_day == 1) and (Lu_3 == 1)) or ((act_day == 2) and (Ma_3 == 1)) or ((act_day == 3) and (Me_3 == 1)) or ((act_day == 4) and (Je_3 == 1)) or ((act_day == 5) and (Ve_3 == 1)) or ((act_day == 6) and (Sa_3 == 1)) or ((act_day == 7) and (Di_3 == 1)))) and ((((now.month > mois_debut_3) and (now.month < mois_fin_3)) or ((now.month == mois_debut_3) and (now.day >=  jour_debut_3)) or ((now.month == mois_fin_3) and (now.day <= jour_fin_3))) and (now.hour == heure_fin_3) and (now.minute == minutes_fin_3))) or (((actif_4 == 1) and (sortie5_4 == 1) and (((act_day == 1) and (Lu_4 == 1)) or ((act_day == 2) and (Ma_4 == 1)) or ((act_day == 3) and (Me_4 == 1)) or ((act_day == 4) and (Je_4 == 1)) or ((act_day == 5) and (Ve_4 == 1)) or ((act_day == 6) and (Sa_4 == 1)) or ((act_day == 7) and (Di_4 == 1)))) and ((((now.month > mois_debut_4) and (now.month < mois_fin_4)) or ((now.month == mois_debut_4) and (now.day >=  jour_debut_4)) or ((now.month == mois_fin_4) and (now.day <= jour_fin_4))) and (now.hour == heure_fin_4) and (now.minute == minutes_fin_4))) or (((actif_5 == 1) and (sortie5_5 == 1) and (((act_day == 1) and (Lu_5 == 1)) or ((act_day == 2) and (Ma_5 == 1)) or ((act_day == 3) and (Me_5 == 1)) or ((act_day == 4) and (Je_5 == 1)) or ((act_day == 5) and (Ve_5 == 1)) or ((act_day == 6) and (Sa_5 == 1)) or ((act_day == 7) and (Di_5 == 1)))) and ((((now.month > mois_debut_5) and (now.month < mois_fin_5)) or ((now.month == mois_debut_5) and (now.day >=  jour_debut_5)) or ((now.month == mois_fin_5) and (now.day <= jour_fin_5))) and (now.hour == heure_fin_5) and (now.minute == minutes_fin_5))))):
		   if (GPIO.digitalRead(CUISINE) == GPIO.HIGH):
               GPIO.digitalWrite(CUISINE, GPIO.LOW)

	# Gestion sortie FILTRATION (sortie 6)
	# Activation sortie FILTRATION (sortie 6)
	if ((now.second == 0) and ((((actif_1 == 1) and (sortie6_1 == 1) and (((act_day == 1) and (Lu_1 == 1)) or ((act_day == 2) and (Ma_1 == 1)) or ((act_day == 3) and (Me_1 == 1)) or ((act_day == 4) and (Je_1 == 1)) or ((act_day == 5) and (Ve_1 == 1)) or ((act_day == 6) and (Sa_1 == 1)) or ((act_day == 7) and (Di_1 == 1)))) and ((((now.month > mois_debut_1) and (now.month < mois_fin_1)) or ((now.month == mois_debut_1) and (now.day >=  jour_debut_1)) or ((now.month == mois_fin_1) and (now.day <= jour_fin_1))) and (now.hour == heure_debut_1) and (now.minute == minutes_debut_1))) or (((actif_2 == 1) and (sortie6_2 == 1) and (((act_day == 1) and (Lu_2 == 1)) or ((act_day == 2) and (Ma_2 == 1)) or ((act_day == 3) and (Me_2 == 1)) or ((act_day == 4) and (Je_2 == 1)) or ((act_day == 5) and (Ve_2 == 1)) or ((act_day == 6) and (Sa_2 == 1)) or ((act_day == 7) and (Di_2 == 1)))) and ((((now.month > mois_debut_2) and (now.month < mois_fin_2)) or ((now.month == mois_debut_2) and (now.day >=  jour_debut_2)) or ((now.month == mois_fin_2) and (now.day <= jour_fin_2))) and (now.hour == heure_debut_2) and (now.minute == minutes_debut_2))) or (((actif_3 == 1) and (sortie6_3 == 1) and (((act_day == 1) and (Lu_3 == 1)) or ((act_day == 2) and (Ma_3 == 1)) or ((act_day == 3) and (Me_3 == 1)) or ((act_day == 4) and (Je_3 == 1)) or ((act_day == 5) and (Ve_3 == 1)) or ((act_day == 6) and (Sa_3 == 1)) or ((act_day == 7) and (Di_3 == 1)))) and ((((now.month > mois_debut_3) and (now.month < mois_fin_3)) or ((now.month == mois_debut_3) and (now.day >=  jour_debut_3)) or ((now.month == mois_fin_3) and (now.day <= jour_fin_3))) and (now.hour == heure_debut_3) and (now.minute == minutes_debut_3))) or (((actif_4 == 1) and (sortie6_4 == 1) and (((act_day == 1) and (Lu_4 == 1)) or ((act_day == 2) and (Ma_4 == 1)) or ((act_day == 3) and (Me_4 == 1)) or ((act_day == 4) and (Je_4 == 1)) or ((act_day == 5) and (Ve_4 == 1)) or ((act_day == 6) and (Sa_4 == 1)) or ((act_day == 7) and (Di_4 == 1)))) and ((((now.month > mois_debut_4) and (now.month < mois_fin_4)) or ((now.month == mois_debut_4) and (now.day >=  jour_debut_4)) or ((now.month == mois_fin_4) and (now.day <= jour_fin_4))) and (now.hour == heure_debut_4) and (now.minute == minutes_debut_4))) or (((actif_5 == 1) and (sortie6_5 == 1) and (((act_day == 1) and (Lu_5 == 1)) or ((act_day == 2) and (Ma_5 == 1)) or ((act_day == 3) and (Me_5 == 1)) or ((act_day == 4) and (Je_5 == 1)) or ((act_day == 5) and (Ve_5 == 1)) or ((act_day == 6) and (Sa_5 == 1)) or ((act_day == 7) and (Di_5 == 1)))) and ((((now.month > mois_debut_5) and (now.month < mois_fin_5)) or ((now.month == mois_debut_5) and (now.day >=  jour_debut_5)) or ((now.month == mois_fin_5) and (now.day <= jour_fin_5))) and (now.hour == heure_debut_5) and (now.minute == minutes_debut_5))))):
		   if (GPIO.digitalRead(DOMESOLAIRE) == GPIO.HIGH):
               GPIO.digitalWrite(DOMESOLAIRE, GPIO.LOW)
		   if (GPIO.digitalRead(FILTRATION) == GPIO.LOW):
               GPIO.digitalWrite(FILTRATION, GPIO.HIGH)
	# Désactivation sortie FILTRATION (sortie 6)
	if ((now.second == 0) and ((((actif_1 == 1) and (sortie6_1 == 1) and (((act_day == 1) and (Lu_1 == 1)) or ((act_day == 2) and (Ma_1 == 1)) or ((act_day == 3) and (Me_1 == 1)) or ((act_day == 4) and (Je_1 == 1)) or ((act_day == 5) and (Ve_1 == 1)) or ((act_day == 6) and (Sa_1 == 1)) or ((act_day == 7) and (Di_1 == 1)))) and ((((now.month > mois_debut_1) and (now.month < mois_fin_1)) or ((now.month == mois_debut_1) and (now.day >=  jour_debut_1)) or ((now.month == mois_fin_1) and (now.day <= jour_fin_1))) and (now.hour == heure_fin_1) and (now.minute == minutes_fin_1))) or (((actif_2 == 1) and (sortie6_2 == 1) and (((act_day == 1) and (Lu_2 == 1)) or ((act_day == 2) and (Ma_2 == 1)) or ((act_day == 3) and (Me_2 == 1)) or ((act_day == 4) and (Je_2 == 1)) or ((act_day == 5) and (Ve_2 == 1)) or ((act_day == 6) and (Sa_2 == 1)) or ((act_day == 7) and (Di_2 == 1)))) and ((((now.month > mois_debut_2) and (now.month < mois_fin_2)) or ((now.month == mois_debut_2) and (now.day >=  jour_debut_2)) or ((now.month == mois_fin_2) and (now.day <= jour_fin_2))) and (now.hour == heure_fin_2) and (now.minute == minutes_fin_2))) or (((actif_3 == 1) and (sortie6_3 == 1) and (((act_day == 1) and (Lu_3 == 1)) or ((act_day == 2) and (Ma_3 == 1)) or ((act_day == 3) and (Me_3 == 1)) or ((act_day == 4) and (Je_3 == 1)) or ((act_day == 5) and (Ve_3 == 1)) or ((act_day == 6) and (Sa_3 == 1)) or ((act_day == 7) and (Di_3 == 1)))) and ((((now.month > mois_debut_3) and (now.month < mois_fin_3)) or ((now.month == mois_debut_3) and (now.day >=  jour_debut_3)) or ((now.month == mois_fin_3) and (now.day <= jour_fin_3))) and (now.hour == heure_fin_3) and (now.minute == minutes_fin_3))) or (((actif_4 == 1) and (sortie6_4 == 1) and (((act_day == 1) and (Lu_4 == 1)) or ((act_day == 2) and (Ma_4 == 1)) or ((act_day == 3) and (Me_4 == 1)) or ((act_day == 4) and (Je_4 == 1)) or ((act_day == 5) and (Ve_4 == 1)) or ((act_day == 6) and (Sa_4 == 1)) or ((act_day == 7) and (Di_4 == 1)))) and ((((now.month > mois_debut_4) and (now.month < mois_fin_4)) or ((now.month == mois_debut_4) and (now.day >=  jour_debut_4)) or ((now.month == mois_fin_4) and (now.day <= jour_fin_4))) and (now.hour == heure_fin_4) and (now.minute == minutes_fin_4))) or (((actif_5 == 1) and (sortie6_5 == 1) and (((act_day == 1) and (Lu_5 == 1)) or ((act_day == 2) and (Ma_5 == 1)) or ((act_day == 3) and (Me_5 == 1)) or ((act_day == 4) and (Je_5 == 1)) or ((act_day == 5) and (Ve_5 == 1)) or ((act_day == 6) and (Sa_5 == 1)) or ((act_day == 7) and (Di_5 == 1)))) and ((((now.month > mois_debut_5) and (now.month < mois_fin_5)) or ((now.month == mois_debut_5) and (now.day >=  jour_debut_5)) or ((now.month == mois_fin_5) and (now.day <= jour_fin_5))) and (now.hour == heure_fin_5) and (now.minute == minutes_fin_5))))):
		   if (GPIO.digitalRead(FILTRATION) == GPIO.HIGH):
               GPIO.digitalWrite(FILTRATION, GPIO.LOW)

	# Gestion sortie DOMESOLAIRE (sortie 7)
	# Activation sortie DOMESOLAIRE (sortie 7)
	if ((now.second == 0) and ((((actif_1 == 1) and (sortie7_1 == 1) and (((act_day == 1) and (Lu_1 == 1)) or ((act_day == 2) and (Ma_1 == 1)) or ((act_day == 3) and (Me_1 == 1)) or ((act_day == 4) and (Je_1 == 1)) or ((act_day == 5) and (Ve_1 == 1)) or ((act_day == 6) and (Sa_1 == 1)) or ((act_day == 7) and (Di_1 == 1)))) and ((((now.month > mois_debut_1) and (now.month < mois_fin_1)) or ((now.month == mois_debut_1) and (now.day >=  jour_debut_1)) or ((now.month == mois_fin_1) and (now.day <= jour_fin_1))) and (now.hour == heure_debut_1) and (now.minute == minutes_debut_1))) or (((actif_2 == 1) and (sortie7_2 == 1) and (((act_day == 1) and (Lu_2 == 1)) or ((act_day == 2) and (Ma_2 == 1)) or ((act_day == 3) and (Me_2 == 1)) or ((act_day == 4) and (Je_2 == 1)) or ((act_day == 5) and (Ve_2 == 1)) or ((act_day == 6) and (Sa_2 == 1)) or ((act_day == 7) and (Di_2 == 1)))) and ((((now.month > mois_debut_2) and (now.month < mois_fin_2)) or ((now.month == mois_debut_2) and (now.day >=  jour_debut_2)) or ((now.month == mois_fin_2) and (now.day <= jour_fin_2))) and (now.hour == heure_debut_2) and (now.minute == minutes_debut_2))) or (((actif_3 == 1) and (sortie7_3 == 1) and (((act_day == 1) and (Lu_3 == 1)) or ((act_day == 2) and (Ma_3 == 1)) or ((act_day == 3) and (Me_3 == 1)) or ((act_day == 4) and (Je_3 == 1)) or ((act_day == 5) and (Ve_3 == 1)) or ((act_day == 6) and (Sa_3 == 1)) or ((act_day == 7) and (Di_3 == 1)))) and ((((now.month > mois_debut_3) and (now.month < mois_fin_3)) or ((now.month == mois_debut_3) and (now.day >=  jour_debut_3)) or ((now.month == mois_fin_3) and (now.day <= jour_fin_3))) and (now.hour == heure_debut_3) and (now.minute == minutes_debut_3))) or (((actif_4 == 1) and (sortie7_4 == 1) and (((act_day == 1) and (Lu_4 == 1)) or ((act_day == 2) and (Ma_4 == 1)) or ((act_day == 3) and (Me_4 == 1)) or ((act_day == 4) and (Je_4 == 1)) or ((act_day == 5) and (Ve_4 == 1)) or ((act_day == 6) and (Sa_4 == 1)) or ((act_day == 7) and (Di_4 == 1)))) and ((((now.month > mois_debut_4) and (now.month < mois_fin_4)) or ((now.month == mois_debut_4) and (now.day >=  jour_debut_4)) or ((now.month == mois_fin_4) and (now.day <= jour_fin_4))) and (now.hour == heure_debut_4) and (now.minute == minutes_debut_4))) or (((actif_5 == 1) and (sortie7_5 == 1) and (((act_day == 1) and (Lu_5 == 1)) or ((act_day == 2) and (Ma_5 == 1)) or ((act_day == 3) and (Me_5 == 1)) or ((act_day == 4) and (Je_5 == 1)) or ((act_day == 5) and (Ve_5 == 1)) or ((act_day == 6) and (Sa_5 == 1)) or ((act_day == 7) and (Di_5 == 1)))) and ((((now.month > mois_debut_5) and (now.month < mois_fin_5)) or ((now.month == mois_debut_5) and (now.day >=  jour_debut_5)) or ((now.month == mois_fin_5) and (now.day <= jour_fin_5))) and (now.hour == heure_debut_5) and (now.minute == minutes_debut_5))))):
		   if ((GPIO.digitalRead(DOMESOLAIRE) == GPIO.LOW) and (GPIO.digitalRead(FILTRATION) == GPIO.LOW)):
               GPIO.digitalWrite(DOMESOLAIRE, GPIO.HIGH)
	# Désactivation sortie DOMESOLAIRE (sortie 7)
	if ((GPIO.digitalRead(FILTRATION) == GPIO.HIGH) or ((now.second == 0) and ((((actif_1 == 1) and (sortie7_1 == 1) and (((act_day == 1) and (Lu_1 == 1)) or ((act_day == 2) and (Ma_1 == 1)) or ((act_day == 3) and (Me_1 == 1)) or ((act_day == 4) and (Je_1 == 1)) or ((act_day == 5) and (Ve_1 == 1)) or ((act_day == 6) and (Sa_1 == 1)) or ((act_day == 7) and (Di_1 == 1)))) and ((((now.month > mois_debut_1) and (now.month < mois_fin_1)) or ((now.month == mois_debut_1) and (now.day >=  jour_debut_1)) or ((now.month == mois_fin_1) and (now.day <= jour_fin_1))) and (now.hour == heure_fin_1) and (now.minute == minutes_fin_1))) or (((actif_2 == 1) and (sortie7_2 == 1) and (((act_day == 1) and (Lu_2 == 1)) or ((act_day == 2) and (Ma_2 == 1)) or ((act_day == 3) and (Me_2 == 1)) or ((act_day == 4) and (Je_2 == 1)) or ((act_day == 5) and (Ve_2 == 1)) or ((act_day == 6) and (Sa_2 == 1)) or ((act_day == 7) and (Di_2 == 1)))) and ((((now.month > mois_debut_2) and (now.month < mois_fin_2)) or ((now.month == mois_debut_2) and (now.day >=  jour_debut_2)) or ((now.month == mois_fin_2) and (now.day <= jour_fin_2))) and (now.hour == heure_fin_2) and (now.minute == minutes_fin_2))) or (((actif_3 == 1) and (sortie7_3 == 1) and (((act_day == 1) and (Lu_3 == 1)) or ((act_day == 2) and (Ma_3 == 1)) or ((act_day == 3) and (Me_3 == 1)) or ((act_day == 4) and (Je_3 == 1)) or ((act_day == 5) and (Ve_3 == 1)) or ((act_day == 6) and (Sa_3 == 1)) or ((act_day == 7) and (Di_3 == 1)))) and ((((now.month > mois_debut_3) and (now.month < mois_fin_3)) or ((now.month == mois_debut_3) and (now.day >=  jour_debut_3)) or ((now.month == mois_fin_3) and (now.day <= jour_fin_3))) and (now.hour == heure_fin_3) and (now.minute == minutes_fin_3))) or (((actif_4 == 1) and (sortie7_4 == 1) and (((act_day == 1) and (Lu_4 == 1)) or ((act_day == 2) and (Ma_4 == 1)) or ((act_day == 3) and (Me_4 == 1)) or ((act_day == 4) and (Je_4 == 1)) or ((act_day == 5) and (Ve_4 == 1)) or ((act_day == 6) and (Sa_4 == 1)) or ((act_day == 7) and (Di_4 == 1)))) and ((((now.month > mois_debut_4) and (now.month < mois_fin_4)) or ((now.month == mois_debut_4) and (now.day >=  jour_debut_4)) or ((now.month == mois_fin_4) and (now.day <= jour_fin_4))) and (now.hour == heure_fin_4) and (now.minute == minutes_fin_4))) or (((actif_5 == 1) and (sortie7_5 == 1) and (((act_day == 1) and (Lu_5 == 1)) or ((act_day == 2) and (Ma_5 == 1)) or ((act_day == 3) and (Me_5 == 1)) or ((act_day == 4) and (Je_5 == 1)) or ((act_day == 5) and (Ve_5 == 1)) or ((act_day == 6) and (Sa_5 == 1)) or ((act_day == 7) and (Di_5 == 1)))) and ((((now.month > mois_debut_5) and (now.month < mois_fin_5)) or ((now.month == mois_debut_5) and (now.day >=  jour_debut_5)) or ((now.month == mois_fin_5) and (now.day <= jour_fin_5))) and (now.hour == heure_fin_5) and (now.minute == minutes_fin_5))))):
		   if (GPIO.digitalRead(DOMESOLAIRE) == GPIO.HIGH):
               GPIO.digitalWrite(DOMESOLAIRE, GPIO.LOW)
    
	# Gestion sortie PRESENCE (sortie 8)	
	# Désactivation détécteur de présence
	if ((GPIO.digitalRead(TERRASSE) == GPIO.HIGH) or (GPIO.digitalRead(PISCINEBLANC) == GPIO.HIGH) or (GPIO.digitalRead(PISCINECOULEURS) == GPIO.HIGH) or (GPIO.digitalRead(ABRISJARDIN) == GPIO.HIGH) or (GPIO.digitalRead(CUISINE) == GPIO.HIGH)):
	    if (GPIO.digitalRead(PRESENCE) == GPIO.LOW):
		    GPIO.digitalWrite(PRESENCE, GPIO.HIGH)
	# Activation détécteur de présence
	if ((GPIO.digitalRead(TERRASSE) == GPIO.LOW) and (GPIO.digitalRead(PISCINEBLANC) == GPIO.LOW) and (GPIO.digitalRead(PISCINECOULEURS) == GPIO.LOW) and (GPIO.digitalRead(ABRISJARDIN) == GPIO.LOW) and (GPIO.digitalRead(CUISINE) == GPIO.LOW)): 
	    if (GPIO.digitalRead(PRESENCE) == GPIO.HIGH):
		    GPIO.digitalWrite(PRESENCE, GPIO.LOW)
			
	# Règle RAZ
    if ((actif-RAZ == 1) and (now.hour == heure_RAZ) and (now.minute == minutes_RAZ) and (now.second == 0)):
        if ((sortie1-RAZ == 1) and (GPIO.digitalRead(LIGHT) == GPIO.HIGH)):
            GPIO.digitalWrite(LIGHT, GPIO.LOW)
	    if ((sortie2-RAZ == 1) and (GPIO.digitalRead(LIGHT) == GPIO.HIGH)):
            GPIO.digitalWrite(LIGHT, GPIO.LOW)
		if ((sortie3-RAZ == 1) and (GPIO.digitalRead(LIGHT) == GPIO.HIGH)):
            GPIO.digitalWrite(LIGHT, GPIO.LOW)
		if ((sortie4-RAZ == 1) and (GPIO.digitalRead(LIGHT) == GPIO.HIGH)):
            GPIO.digitalWrite(LIGHT, GPIO.LOW)
		if ((sortie5-RAZ == 1) and (GPIO.digitalRead(LIGHT) == GPIO.HIGH)):
            GPIO.digitalWrite(LIGHT, GPIO.LOW)
		if ((sortie6-RAZ == 1) and (GPIO.digitalRead(LIGHT) == GPIO.HIGH)):
            GPIO.digitalWrite(LIGHT, GPIO.LOW)
		if ((sortie7-RAZ == 1) and (GPIO.digitalRead(LIGHT) == GPIO.HIGH)):
            GPIO.digitalWrite(LIGHT, GPIO.LOW)
	
	
    # gives CPU some time before looping again
    webiopi.sleep(1)

# destroy function is called at WebIOPi shutdown
def destroy():
	GPIO.digitalWrite(TERRASSE, GPIO.LOW)
	GPIO.digitalWrite(PISCINEBLANC, GPIO.LOW)
	GPIO.digitalWrite(PISCINECOULEURS, GPIO.LOW)
	GPIO.digitalWrite(ABRISJARDIN, GPIO.LOW)
	GPIO.digitalWrite(CUISINE, GPIO.LOW)
	GPIO.digitalWrite(FILTRATION, GPIO.LOW)
	GPIO.digitalWrite(DOMESOLAIRE, GPIO.LOW)
	GPIO.digitalWrite(PRESENCE, GPIO.LOW)

xavier1306
Messages : 72
Enregistré le : sam. 14 nov. 2015 23:00

Re: Pilotage pompe et éclairage

Message par xavier1306 » mar. 10 mai 2016 12:26

Pour ma curiosité: C'est quoi "dôme solaire" ?

Envoyé de mon GT-I9505 en utilisant Tapatalk

Topodoco
Messages : 62
Enregistré le : mer. 16 mars 2016 23:08

Re: Pilotage pompe et éclairage

Message par Topodoco » mar. 10 mai 2016 21:25

xavier1306 a écrit :Pour ma curiosité: C'est quoi "dôme solaire" ?
C'est ça:
:arrow: http://www.poolstar.fr/Catalog/Product/ ... re-poolsun
Enfin pour la marque, je n'en ai aucune idée... mais dans le principe c'est exactement la même chose :lol:

Topodoco
Messages : 62
Enregistré le : mer. 16 mars 2016 23:08

Re: Pilotage pompe et éclairage

Message par Topodoco » jeu. 12 mai 2016 01:21

Petit aide-mémoire pour les GPIO: http://pinout.xyz/pinout/pin37_gpio26

A part ça... bah j'en ai profité pour choisir les sorties GPIO de mon projet:

Code : Tout sélectionner

# Assignation des sorties
# GPIO pin using BCM numbering
# SONDES = GPIO 4 (PIN 7)
TERRASSE = 17  # (PIN 11)
PISCINEBLANC = 27 # (PIN 13)
PISCINECOULEURS = 22 # (PIN 15)
ABRISJARDIN = 5 #  (PIN 29)
CUISINE = 6 #  (PIN 31)
FILTRATION = 13 #  (PIN 33)
DOMESOLAIRE = 19 # (PIN 35)
PRESENCE = 26 #  (PIN 37)
Prochaine étape, programmer les états des GPIO lors du démarrage de la framboise...
Ça va faire beaucoup à écrire pour servir finalement pas trop souvent, mais au moins, je sais que tout sera fonctionnel immédiatement... :mrgreen:
Ensuite, il faudra se pencher sur la page WEB pour activer manuellement les sorties...
Puis étudier et programmer le démarrage de la pompe "DOMESOLAIRE" en fonction des températures d'une ou plusieurs sondes.
La page de configuration et le fichier JSON viendront en dernier... :o

Topodoco
Messages : 62
Enregistré le : mer. 16 mars 2016 23:08

Re: Pilotage pompe et éclairage

Message par Topodoco » ven. 13 mai 2016 00:19

Vous allez me prendre pour un fou... :lol:
Je sais que dans mon dernier post, j'avais tout annoncé, sauf ça...
Mais finalement, j'ai repris toute la programmation de mes règles d'activations/désactivations.
Mes réflexes en automatismes m'ayant rattrapés, je ne voulais écrire une sortie à 1 ou à 0, qu'une seule fois.
J'avais donc des "if (........)" à rallonge, tellement que l'on ne s'en sortait plus.
J'ai donc repris le tout de 0, pour éclaircir tout cela.
C'est plus aéré, les commentaires sont plus clairs aussi, et je pense même que de cette manière, le temps de cycle peut avoir été amélioré.
Voila donc la dernière version:

Code : Tout sélectionner

import webiopi
import datetime

GPIO = webiopi.GPIO

# Assignation des sorties
# GPIO pin using BCM numbering
# SONDES = GPIO 4 (PIN 7)
TERRASSE = 17  # (PIN 11)
PISCINEBLANC = 27 # (PIN 13)
PISCINECOULEURS = 22 # (PIN 15)
ABRISJARDIN = 5 #  (PIN 29)
CUISINE = 6 #  (PIN 31)
FILTRATION = 13 #  (PIN 33)
DOMESOLAIRE = 19 # (PIN 35)
PRESENCE = 26 #  (PIN 37)

# Règle1
actif_1 = 1
sortie1_1 = 0
sortie2_1 = 0
sortie3_1 = 0
sortie4_1 = 0
sortie5_1 = 0
sortie6_1 = 1
sortie7_1 = 0
Lu_1 = 1
Ma_1 = 1
Me_1 = 0
Je_1 = 1
Ve_1 = 1
Sa_1 = 0
Di_1 = 0
jour_debut_1 = 1
mois_debut_1 = 5
heure_debut_1 = 11
minutes_debut_1 = 0
jour_fin_1 = 30
mois_fin_1 = 9
heure_fin_1 = 15
minutes_fin_1 = 30

# Règle2
actif_2 = 1
sortie1_2 = 0
sortie2_2 = 0
sortie3_2 = 0
sortie4_2 = 0
sortie5_2 = 0
sortie6_2 = 1
sortie7_2 = 0
Lu_2 = 0
Ma_2 = 0
Me_2 = 1
Je_2 = 0
Ve_2 = 0
Sa_2 = 1
Di_2 = 1
jour_debut_2 = 1
mois_debut_2 = 5
heure_debut_2 = 10
minutes_debut_2 = 0
jour_fin_2 = 30
mois_fin_2 = 9
heure_fin_2 = 14
minutes_fin_2 = 0

#Règle3
actif_3 = 0
sortie1_3 = 0
sortie2_3 = 0
sortie3_3 = 0
sortie4_3 = 0
sortie5_3 = 0
sortie6_3 = 0
sortie7_3 = 0
Lu_3 = 0
Ma_3 = 0
Me_3 = 0
Je_3 = 0
Ve_3 = 0
Sa_3 = 0
Di_3 = 0
jour_debut_3 = 1
mois_debut_3 = 1
heure_debut_3 = 0
minutes_debut_3 = 0
jour_fin_3 = 1
mois_fin_3 = 1
heure_fin_3 = 0
minutes_fin_3 = 0

#Règle4
actif_4 = 0
sortie1_4 = 0
sortie2_4 = 0
sortie3_4 = 0
sortie4_4 = 0
sortie5_4 = 0
sortie6_4 = 0
sortie7_4 = 0
Lu_4 = 0
Ma_4 = 0
Me_4 = 0
Je_4 = 0
Ve_4 = 0
Sa_4 = 0
Di_4 = 0
jour_debut_4 = 1
mois_debut_4 = 1
heure_debut_4 = 0
minutes_debut_4 = 0
jour_fin_4 = 1
mois_fin_4 = 1
heure_fin_4 = 0
minutes_fin_4 = 0

#Règle5
actif_5 = 0
sortie1_5 = 0
sortie2_5 = 0
sortie3_5 = 0
sortie4_5 = 0
sortie5_5 = 0
sortie6_5 = 0
sortie7_5 = 0
Lu_5 = 0
Ma_5 = 0
Me_5 = 0
Je_5 = 0
Ve_5 = 0
Sa_5 = 0
Di_5 = 0
jour_debut_5 = 1
mois_debut_5 = 1
heure_debut_5 = 0
minutes_debut_5 = 0
jour_fin_5 = 1
mois_fin_5 = 1
heure_fin_5 = 0
minutes_fin_5 = 0

#RègleRAZ
actif_RAZ = 1
sortie1_RAZ = 1
sortie2_RAZ = 1
sortie3_RAZ = 1
sortie4_RAZ = 1
sortie5_RAZ = 1
sortie6_RAZ = 0
sortie7_RAZ = 0
heure_RAZ = 8
minutes_RAZ = 0

# setup function is automatically called at WebIOPi startup
def setup():
	# set the GPIO used by the light to output
	GPIO.setFunction(TERRASSE, GPIO.OUT)
	GPIO.setFunction(PISCINEBLANC, GPIO.OUT)
	GPIO.setFunction(PISCINECOULEURS, GPIO.OUT)
	GPIO.setFunction(ABRISJARDIN, GPIO.OUT)
	GPIO.setFunction(CUISINE, GPIO.OUT)
	GPIO.setFunction(FILTRATION, GPIO.OUT)
	GPIO.setFunction(DOMESOLAIRE, GPIO.OUT)
	GPIO.setFunction(PRESENCE, GPIO.OUT)

    # retrieve current datetime
	now = datetime.datetime.now()
	act_day = datetime.isoweekday()

    # Initialisation des sorties relais 1-7 (la sortie 8 tenant compte de l'état des sorties 1-5 sera piloté automatiquement).
	# Initialisation règle 1:

	# Initialisation règle 2:

	# Initialisation règle 3:

	# Initialisation règle 4:

	# Initialisation règle 5:

# loop function is repeatedly called by WebIOPi 
def loop():
	# retrieve current datetime
	now = datetime.datetime.now()
	act_day = datetime.isoweekday()
	
	# Gestion des règles:
	if (now.second == 0):
		# Gestion Règle 1:
		if (actif_1 == 1):
			# Vérification si jour actuel programmé dans règle 1:
			if (((act_day == 1) and (Lu_1 == 1)) or ((act_day == 2) and (Ma_1 == 1)) or ((act_day == 3) and (Me_1 == 1)) or ((act_day == 4) and (Je_1 == 1)) or ((act_day == 5) and (Ve_1 == 1)) or ((act_day == 6) and (Sa_1 == 1)) or ((act_day == 7) and (Di_1 == 1))):
				# Vérification si période programmée active:
				# Vérification du mois/jour en cours
				if 	(((now.month > mois_debut_1) and (now.month < mois_fin_1)) or ((now.month == mois_debut_1) and (mois_debut_1 != mois_fin_1) and (now.day >=  jour_debut_1)) or ((now.month == mois_fin_1) and (mois_debut_1 != mois_fin_1) and (now.day <= jour_fin_1)) or ((now.month == mois_debut_1) and (mois_debut_1 == mois_fin_1) and (now.day >=  jour_debut_1)and (now.day <=  jour_fin_1))):
					# Vérification plage horaire marche:
					if ((now.hour == heure_debut_1) and (now.minute == minutes_debut_1)):
						# Vérification si sortie 1 sélectionnée dans règle 1:
						if (sortie1_1 == 1):
							# Activation sortie TERRASSE (sortie 1)
							if (GPIO.digitalRead(TERRASSE) == GPIO.LOW):
								GPIO.digitalWrite(TERRASSE, GPIO.HIGH)
						# Vérification si sortie 2 sélectionnée dans règle 1:
						if (sortie2_1 == 1):
							# Activation sortie PISCINEBLANC (sortie 2)
							if (GPIO.digitalRead(PISCINEBLANC) == GPIO.LOW):
								GPIO.digitalWrite(PISCINEBLANC, GPIO.HIGH)
						# Vérification si sortie 3 sélectionnée dans règle 1:
						if (sortie3_1 == 1):
							# Activation sortie PISCINECOULEURS (sortie 3)
							if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.LOW):
								GPIO.digitalWrite(PISCINECOULEURS, GPIO.HIGH)
						# Vérification si sortie 4 sélectionnée dans règle 1:
						if (sortie4_1 == 1):
							# Activation sortie ABRISJARDIN (sortie 4)
							if (GPIO.digitalRead(ABRISJARDIN) == GPIO.LOW):
								GPIO.digitalWrite(ABRISJARDIN, GPIO.HIGH)
						# Vérification si sortie 5 sélectionnée dans règle 1:
						if (sortie5_1 == 1):
							# Activation sortie CUISINE (sortie 5)
							if (GPIO.digitalRead(CUISINE) == GPIO.LOW):
								GPIO.digitalWrite(CUISINE, GPIO.HIGH)
						# Vérification si sortie 6 sélectionnée dans règle 1:
						if (sortie6_1 == 1):
							# Activation sortie FILTRATION (sortie 6)
							if (GPIO.digitalRead(FILTRATION) == GPIO.LOW):
								GPIO.digitalWrite(FILTRATION, GPIO.HIGH)
						# Vérification si sortie 7 sélectionnée dans règle 1:
						if (sortie7_1 == 1):
							# Activation sortie DOMESOLAIRE (sortie 7) si FILTRATION inactive (sortie 6)
							if ((GPIO.digitalRead(DOMESOLAIRE) == GPIO.LOW) and (GPIO.digitalRead(FILTRATION) == GPIO.LOW)):
								GPIO.digitalWrite(DOMESOLAIRE, GPIO.HIGH)
					# Vérification plage horaire arrêt
					if ((now.hour == heure_fin_1) and (now.minute == minutes_fin_1)):
						# Vérification si sortie 1 sélectionnée dans règle 1:
						if (sortie1_1 == 1):
							# Désactivation sortie TERRASSE (sortie 1)
							if (GPIO.digitalRead(TERRASSE) == GPIO.HIGH):
								GPIO.digitalWrite(TERRASSE, GPIO.LOW)
						# Vérification si sortie 2 sélectionnée dans règle 1:
						if (sortie2_1 == 1):
							# Désactivation sortie PISCINEBLANC (sortie 2)
							if (GPIO.digitalRead(PISCINEBLANC) == GPIO.HIGH):
								GPIO.digitalWrite(PISCINEBLANC, GPIO.LOW)
						# Vérification si sortie 3 sélectionnée dans règle 1:
						if (sortie3_1 == 1):
							# Désactivation sortie PISCINECOULEURS (sortie 3)
							if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.HIGH):
								GPIO.digitalWrite(PISCINECOULEURS, GPIO.LOW)
						# Vérification si sortie 4 sélectionnée dans règle 1:
						if (sortie4_1 == 1):
							# Désactivation sortie ABRISJARDIN (sortie 4)
							if (GPIO.digitalRead(ABRISJARDIN) == GPIO.HIGH):
								GPIO.digitalWrite(ABRISJARDIN, GPIO.LOW)
						# Vérification si sortie 5 sélectionnée dans règle 1:
						if (sortie5_1 == 1):
							# Désactivation sortie CUISINE (sortie 5)
							if (GPIO.digitalRead(CUISINE) == GPIO.HIGH):
								GPIO.digitalWrite(CUISINE, GPIO.LOW)
						# Vérification si sortie 6 sélectionnée dans règle 1:
						if (sortie6_1 == 1):
							# Désactivation sortie FILTRATION (sortie 6)
							if (GPIO.digitalRead(FILTRATION) == GPIO.HIGH):
								GPIO.digitalWrite(FILTRATION, GPIO.LOW)
						# Vérification si sortie 7 sélectionnée dans règle 1:
						if (sortie7_1 == 1):
							# Désactivation sortie DOMESOLAIRE (sortie 7)
							if (GPIO.digitalRead(DOMESOLAIRE) == GPIO.HIGH):
								GPIO.digitalWrite(DOMESOLAIRE, GPIO.LOW)

		# Gestion Règle 2:
		if (actif_2 == 1):
			# Vérification si jour actuel programmé dans règle 2:
			if (((act_day == 1) and (Lu_2 == 1)) or ((act_day == 2) and (Ma_2 == 1)) or ((act_day == 3) and (Me_2 == 1)) or ((act_day == 4) and (Je_2 == 1)) or ((act_day == 5) and (Ve_2 == 1)) or ((act_day == 6) and (Sa_2 == 1)) or ((act_day == 7) and (Di_2 == 1))):
				# Vérification si période programmée active:
				# Vérification du mois/jour en cours
				if 	(((now.month > mois_debut_2) and (now.month < mois_fin_2)) or ((now.month == mois_debut_2) and (mois_debut_2 != mois_fin_2) and (now.day >=  jour_debut_2)) or ((now.month == mois_fin_2) and (mois_debut_2 != mois_fin_2) and (now.day <= jour_fin_2)) or ((now.month == mois_debut_2) and (mois_debut_2 == mois_fin_2) and (now.day >=  jour_debut_2)and (now.day <=  jour_fin_2))):
					# Vérification plage horaire marche
					if ((now.hour == heure_debut_2) and (now.minute == minutes_debut_2)):
						# Vérification si sortie 1 sélectionnée dans règle 2:
						if (sortie1_2 == 1):
							# Activation sortie TERRASSE (sortie 1)
							if (GPIO.digitalRead(TERRASSE) == GPIO.LOW):
								GPIO.digitalWrite(TERRASSE, GPIO.HIGH)
						# Vérification si sortie 2 sélectionnée dans règle 2:
						if (sortie2_2 == 1):
							# Activation sortie PISCINEBLANC (sortie 2)
							if (GPIO.digitalRead(PISCINEBLANC) == GPIO.LOW):
								GPIO.digitalWrite(PISCINEBLANC, GPIO.HIGH)
						# Vérification si sortie 3 sélectionnée dans règle 2:
						if (sortie3_2 == 1):
							# Activation sortie PISCINECOULEURS (sortie 3)
							if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.LOW):
								GPIO.digitalWrite(PISCINECOULEURS, GPIO.HIGH)
						# Vérification si sortie 4 sélectionnée dans règle 2:
						if (sortie4_2 == 1):
							# Activation sortie ABRISJARDIN (sortie 4)
							if (GPIO.digitalRead(ABRISJARDIN) == GPIO.LOW):
								GPIO.digitalWrite(ABRISJARDIN, GPIO.HIGH)
						# Vérification si sortie 5 sélectionnée dans règle 2:
						if (sortie5_2 == 1):
							# Activation sortie CUISINE (sortie 5)
							if (GPIO.digitalRead(CUISINE) == GPIO.LOW):
								GPIO.digitalWrite(CUISINE, GPIO.HIGH)
						# Vérification si sortie 6 sélectionnée dans règle 2:
						if (sortie6_2 == 1):
							# Activation sortie FILTRATION (sortie 6)
							if (GPIO.digitalRead(FILTRATION) == GPIO.LOW):
								GPIO.digitalWrite(FILTRATION, GPIO.HIGH)
						# Vérification si sortie 7 sélectionnée dans règle 2:
						if (sortie7_2 == 1):
							# Activation sortie DOMESOLAIRE (sortie 7) si FILTRATION inactive (sortie 6)
							if ((GPIO.digitalRead(DOMESOLAIRE) == GPIO.LOW) and (GPIO.digitalRead(FILTRATION) == GPIO.LOW)):
								GPIO.digitalWrite(DOMESOLAIRE, GPIO.HIGH)
					# Vérification plage horaire arrêt
					if ((now.hour == heure_fin_2) and (now.minute == minutes_fin_2)):
						# Vérification si sortie 1 sélectionnée dans règle 2:
						if (sortie1_2 == 1):
						# Désactivation sortie TERRASSE (sortie 1)
							if (GPIO.digitalRead(TERRASSE) == GPIO.HIGH):
								GPIO.digitalWrite(TERRASSE, GPIO.LOW)
						# Vérification si sortie 2 sélectionnée dans règle 2:
						if (sortie2_2 == 1):
							# Désactivation sortie PISCINEBLANC (sortie 2)
							if (GPIO.digitalRead(PISCINEBLANC) == GPIO.HIGH):
								GPIO.digitalWrite(PISCINEBLANC, GPIO.LOW)
						# Vérification si sortie 3 sélectionnée dans règle 2:
						if (sortie3_2 == 1):
							# Désactivation sortie PISCINECOULEURS (sortie 3)
							if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.HIGH):
								GPIO.digitalWrite(PISCINECOULEURS, GPIO.LOW)
						# Vérification si sortie 4 sélectionnée dans règle 2:
						if (sortie4_2 == 1):
							# Désactivation sortie ABRISJARDIN (sortie 4)
							if (GPIO.digitalRead(ABRISJARDIN) == GPIO.HIGH):
								GPIO.digitalWrite(ABRISJARDIN, GPIO.LOW)
						# Vérification si sortie 5 sélectionnée dans règle 2:
						if (sortie5_2 == 1):
							# Désactivation sortie CUISINE (sortie 5)
							if (GPIO.digitalRead(CUISINE) == GPIO.HIGH):
								GPIO.digitalWrite(CUISINE, GPIO.LOW)
						# Vérification si sortie 6 sélectionnée dans règle 2:
						if (sortie6_2 == 1):
							# Désactivation sortie FILTRATION (sortie 6)
							if (GPIO.digitalRead(FILTRATION) == GPIO.HIGH):
								GPIO.digitalWrite(FILTRATION, GPIO.LOW)
						# Vérification si sortie 7 sélectionnée dans règle 2:
						if (sortie7_2 == 1):
							# Désactivation sortie DOMESOLAIRE (sortie 7)
							if (GPIO.digitalRead(DOMESOLAIRE) == GPIO.HIGH):
								GPIO.digitalWrite(DOMESOLAIRE, GPIO.LOW)

		# Gestion Règle 3:
		if (actif_3 == 1):
			# Vérification si jour actuel programmé dans règle 3:
			if (((act_day == 1) and (Lu_3 == 1)) or ((act_day == 2) and (Ma_3 == 1)) or ((act_day == 3) and (Me_3 == 1)) or ((act_day == 4) and (Je_3 == 1)) or ((act_day == 5) and (Ve_3 == 1)) or ((act_day == 6) and (Sa_3 == 1)) or ((act_day == 7) and (Di_3 == 1))):
				# Vérification si période programmée active:
				# Vérification du mois/jour en cours
				if 	(((now.month > mois_debut_3) and (now.month < mois_fin_3)) or ((now.month == mois_debut_3) and (mois_debut_3 != mois_fin_3) and (now.day >=  jour_debut_3)) or ((now.month == mois_fin_3) and (mois_debut_3 != mois_fin_3) and (now.day <= jour_fin_3)) or ((now.month == mois_debut_3) and (mois_debut_3 == mois_fin_3) and (now.day >=  jour_debut_3)and (now.day <=  jour_fin_3))):
					# Vérification plage horaire marche:
					if ((now.hour == heure_debut_3) and (now.minute == minutes_debut_3)):
						# Vérification si sortie 1 sélectionnée dans règle 3:
						if (sortie1_3 == 1):
							# Activation sortie TERRASSE (sortie 1)
							if (GPIO.digitalRead(TERRASSE) == GPIO.LOW):
								GPIO.digitalWrite(TERRASSE, GPIO.HIGH)
						# Vérification si sortie 2 sélectionnée dans règle 3:
						if (sortie2_3 == 1):
							# Activation sortie PISCINEBLANC (sortie 2)
							if (GPIO.digitalRead(PISCINEBLANC) == GPIO.LOW):
								GPIO.digitalWrite(PISCINEBLANC, GPIO.HIGH)
						# Vérification si sortie 3 sélectionnée dans règle 3:
						if (sortie3_3 == 1):
							# Activation sortie PISCINECOULEURS (sortie 3)
							if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.LOW):
								GPIO.digitalWrite(PISCINECOULEURS, GPIO.HIGH)
						# Vérification si sortie 4 sélectionnée dans règle 3:
						if (sortie4_3 == 1):
							# Activation sortie ABRISJARDIN (sortie 4)
							if (GPIO.digitalRead(ABRISJARDIN) == GPIO.LOW):
								GPIO.digitalWrite(ABRISJARDIN, GPIO.HIGH)
						# Vérification si sortie 5 sélectionnée dans règle 3:
						if (sortie5_3 == 1):
							# Activation sortie CUISINE (sortie 5)
							if (GPIO.digitalRead(CUISINE) == GPIO.LOW):
								GPIO.digitalWrite(CUISINE, GPIO.HIGH)
						# Vérification si sortie 6 sélectionnée dans règle 3:
						if (sortie6_3 == 1):
							# Activation sortie FILTRATION (sortie 6)
							if (GPIO.digitalRead(FILTRATION) == GPIO.LOW):
								GPIO.digitalWrite(FILTRATION, GPIO.HIGH)
						# Vérification si sortie 7 sélectionnée dans règle 3:
						if (sortie7_3 == 1):
							# Activation sortie DOMESOLAIRE (sortie 7) si FILTRATION inactive (sortie 6)
							if ((GPIO.digitalRead(DOMESOLAIRE) == GPIO.LOW) and (GPIO.digitalRead(FILTRATION) == GPIO.LOW)):
								GPIO.digitalWrite(DOMESOLAIRE, GPIO.HIGH)
					# Vérification plage horaire arrêt
					if ((now.hour == heure_fin_3) and (now.minute == minutes_fin_3)):
						# Vérification si sortie 1 sélectionnée dans règle 3:
						if (sortie1_3 == 1):
						# Désactivation sortie TERRASSE (sortie 1)
							if (GPIO.digitalRead(TERRASSE) == GPIO.HIGH):
								GPIO.digitalWrite(TERRASSE, GPIO.LOW)
						# Vérification si sortie 2 sélectionnée dans règle 3:
						if (sortie2_3 == 1):
							# Désactivation sortie PISCINEBLANC (sortie 2)
							if (GPIO.digitalRead(PISCINEBLANC) == GPIO.HIGH):
								GPIO.digitalWrite(PISCINEBLANC, GPIO.LOW)
						# Vérification si sortie 3 sélectionnée dans règle 3:
						if (sortie3_3 == 1):
							# Désactivation sortie PISCINECOULEURS (sortie 3)
							if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.HIGH):
								GPIO.digitalWrite(PISCINECOULEURS, GPIO.LOW)
						# Vérification si sortie 4 sélectionnée dans règle 3:
						if (sortie4_3 == 1):
							# Désactivation sortie ABRISJARDIN (sortie 4)
							if (GPIO.digitalRead(ABRISJARDIN) == GPIO.HIGH):
								GPIO.digitalWrite(ABRISJARDIN, GPIO.LOW)
						# Vérification si sortie 5 sélectionnée dans règle 3:
						if (sortie5_3 == 1):
							# Désactivation sortie CUISINE (sortie 5)
							if (GPIO.digitalRead(CUISINE) == GPIO.HIGH):
								GPIO.digitalWrite(CUISINE, GPIO.LOW)
						# Vérification si sortie 6 sélectionnée dans règle 3:
						if (sortie6_3 == 1):
							# Désactivation sortie FILTRATION (sortie 6)
							if (GPIO.digitalRead(FILTRATION) == GPIO.HIGH):
								GPIO.digitalWrite(FILTRATION, GPIO.LOW)
						# Vérification si sortie 7 sélectionnée dans règle 3:
						if (sortie7_3 == 1):
							# Désactivation sortie DOMESOLAIRE (sortie 7)
							if (GPIO.digitalRead(DOMESOLAIRE) == GPIO.HIGH):
								GPIO.digitalWrite(DOMESOLAIRE, GPIO.LOW)

		# Gestion Règle 4:
		if (actif_4 == 1):
			# Vérification si jour actuel programmé dans règle 4:
			if (((act_day == 1) and (Lu_4 == 1)) or ((act_day == 2) and (Ma_4 == 1)) or ((act_day == 3) and (Me_4 == 1)) or ((act_day == 4) and (Je_4 == 1)) or ((act_day == 5) and (Ve_4 == 1)) or ((act_day == 6) and (Sa_4 == 1)) or ((act_day == 7) and (Di_4 == 1))):
				# Vérification si période programmée active:
				# Vérification du mois/jour en cours
				if 	(((now.month > mois_debut_4) and (now.month < mois_fin_4)) or ((now.month == mois_debut_4) and (mois_debut_4 != mois_fin_4) and (now.day >=  jour_debut_4)) or ((now.month == mois_fin_4) and (mois_debut_4 != mois_fin_4) and (now.day <= jour_fin_4)) or ((now.month == mois_debut_4) and (mois_debut_4 == mois_fin_4) and (now.day >=  jour_debut_4)and (now.day <=  jour_fin_4))):
					# Vérification plage horaire marche:
					if ((now.hour == heure_debut_4) and (now.minute == minutes_debut_4)):
						# Vérification si sortie 1 sélectionnée dans règle 4:
						if (sortie1_4 == 1):
							# Activation sortie TERRASSE (sortie 1)
							if (GPIO.digitalRead(TERRASSE) == GPIO.LOW):
								GPIO.digitalWrite(TERRASSE, GPIO.HIGH)
						# Vérification si sortie 2 sélectionnée dans règle 4:
						if (sortie2_4 == 1):
							# Activation sortie PISCINEBLANC (sortie 2)
							if (GPIO.digitalRead(PISCINEBLANC) == GPIO.LOW):
								GPIO.digitalWrite(PISCINEBLANC, GPIO.HIGH)
						# Vérification si sortie 3 sélectionnée dans règle 4:
						if (sortie3_4 == 1):
							# Activation sortie PISCINECOULEURS (sortie 3)
							if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.LOW):
								GPIO.digitalWrite(PISCINECOULEURS, GPIO.HIGH)
						# Vérification si sortie 4 sélectionnée dans règle 4:
						if (sortie4_4 == 1):
							# Activation sortie ABRISJARDIN (sortie 4)
							if (GPIO.digitalRead(ABRISJARDIN) == GPIO.LOW):
								GPIO.digitalWrite(ABRISJARDIN, GPIO.HIGH)
						# Vérification si sortie 5 sélectionnée dans règle 4:
						if (sortie5_4 == 1):
							# Activation sortie CUISINE (sortie 5)
							if (GPIO.digitalRead(CUISINE) == GPIO.LOW):
								GPIO.digitalWrite(CUISINE, GPIO.HIGH)
						# Vérification si sortie 6 sélectionnée dans règle 4:
						if (sortie6_4 == 1):
							# Activation sortie FILTRATION (sortie 6)
							if (GPIO.digitalRead(FILTRATION) == GPIO.LOW):
								GPIO.digitalWrite(FILTRATION, GPIO.HIGH)
						# Vérification si sortie 7 sélectionnée dans règle 4:
						if (sortie7_4 == 1):
							# Activation sortie DOMESOLAIRE (sortie 7) si FILTRATION inactive (sortie 6)
							if ((GPIO.digitalRead(DOMESOLAIRE) == GPIO.LOW) and (GPIO.digitalRead(FILTRATION) == GPIO.LOW)):
								GPIO.digitalWrite(DOMESOLAIRE, GPIO.HIGH)
					# Vérification plage horaire arrêt
					if ((now.hour == heure_fin_4) and (now.minute == minutes_fin_4)):
						# Vérification si sortie 1 sélectionnée dans règle 4:
						if (sortie1_4 == 1):
							# Désactivation sortie TERRASSE (sortie 1)
							if (GPIO.digitalRead(TERRASSE) == GPIO.HIGH):
								GPIO.digitalWrite(TERRASSE, GPIO.LOW)
						# Vérification si sortie 2 sélectionnée dans règle 4:
						if (sortie2_4 == 1):
							# Désactivation sortie PISCINEBLANC (sortie 2)
							if (GPIO.digitalRead(PISCINEBLANC) == GPIO.HIGH):
								GPIO.digitalWrite(PISCINEBLANC, GPIO.LOW)
						# Vérification si sortie 3 sélectionnée dans règle 4:
						if (sortie3_4 == 1):
							# Désactivation sortie PISCINECOULEURS (sortie 3)
							if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.HIGH):
								GPIO.digitalWrite(PISCINECOULEURS, GPIO.LOW)
						# Vérification si sortie 4 sélectionnée dans règle 4:
						if (sortie4_4 == 1):
							# Désactivation sortie ABRISJARDIN (sortie 4)
							if (GPIO.digitalRead(ABRISJARDIN) == GPIO.HIGH):
								GPIO.digitalWrite(ABRISJARDIN, GPIO.LOW)
						# Vérification si sortie 5 sélectionnée dans règle 4:
						if (sortie5_4 == 1):
							# Désactivation sortie CUISINE (sortie 5)
							if (GPIO.digitalRead(CUISINE) == GPIO.HIGH):
								GPIO.digitalWrite(CUISINE, GPIO.LOW)
						# Vérification si sortie 6 sélectionnée dans règle 4:
						if (sortie6_4 == 1):
							# Désactivation sortie FILTRATION (sortie 6)
							if (GPIO.digitalRead(FILTRATION) == GPIO.HIGH):
								GPIO.digitalWrite(FILTRATION, GPIO.LOW)
						# Vérification si sortie 7 sélectionnée dans règle 4:
						if (sortie7_4 == 1):
							# Désactivation sortie DOMESOLAIRE (sortie 7)
							if (GPIO.digitalRead(DOMESOLAIRE) == GPIO.HIGH):
								GPIO.digitalWrite(DOMESOLAIRE, GPIO.LOW)

		# Gestion Règle 5:
		if (actif_5 == 1):
			# Vérification si jour actuel programmé dans règle 5:
			if (((act_day == 1) and (Lu_5 == 1)) or ((act_day == 2) and (Ma_5 == 1)) or ((act_day == 3) and (Me_5 == 1)) or ((act_day == 4) and (Je_5 == 1)) or ((act_day == 5) and (Ve_5 == 1)) or ((act_day == 6) and (Sa_5 == 1)) or ((act_day == 7) and (Di_5 == 1))):
				# Vérification si période programmée active:
				# Vérification du mois/jour en cours
				if 	(((now.month > mois_debut_5) and (now.month < mois_fin_5)) or ((now.month == mois_debut_5) and (mois_debut_5 != mois_fin_5) and (now.day >=  jour_debut_5)) or ((now.month == mois_fin_5) and (mois_debut_5 != mois_fin_5) and (now.day <= jour_fin_5)) or ((now.month == mois_debut_5) and (mois_debut_5 == mois_fin_5) and (now.day >=  jour_debut_5)and (now.day <=  jour_fin_5))):
					# Vérification plage horaire marche:
					if ((now.hour == heure_debut_5) and (now.minute == minutes_debut_5)):
						# Vérification si sortie 1 sélectionnée dans règle 5:
						if (sortie1_5 == 1):
							# Activation sortie TERRASSE (sortie 1)
							if (GPIO.digitalRead(TERRASSE) == GPIO.LOW):
								GPIO.digitalWrite(TERRASSE, GPIO.HIGH)
						# Vérification si sortie 2 sélectionnée dans règle 5:
						if (sortie2_5 == 1):
							# Activation sortie PISCINEBLANC (sortie 2)
							if (GPIO.digitalRead(PISCINEBLANC) == GPIO.LOW):
								GPIO.digitalWrite(PISCINEBLANC, GPIO.HIGH)
						# Vérification si sortie 3 sélectionnée dans règle 5:
						if (sortie3_5 == 1):
							# Activation sortie PISCINECOULEURS (sortie 3)
							if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.LOW):
								GPIO.digitalWrite(PISCINECOULEURS, GPIO.HIGH)
						# Vérification si sortie 4 sélectionnée dans règle 5:
						if (sortie4_5 == 1):
							# Activation sortie ABRISJARDIN (sortie 4)
							if (GPIO.digitalRead(ABRISJARDIN) == GPIO.LOW):
								GPIO.digitalWrite(ABRISJARDIN, GPIO.HIGH)
						# Vérification si sortie 5 sélectionnée dans règle 5:
						if (sortie5_5 == 1):
							# Activation sortie CUISINE (sortie 5)
							if (GPIO.digitalRead(CUISINE) == GPIO.LOW):
								GPIO.digitalWrite(CUISINE, GPIO.HIGH)
						# Vérification si sortie 6 sélectionnée dans règle 5:
						if (sortie6_5 == 1):
							# Activation sortie FILTRATION (sortie 6)
							if (GPIO.digitalRead(FILTRATION) == GPIO.LOW):
								GPIO.digitalWrite(FILTRATION, GPIO.HIGH)
						# Vérification si sortie 7 sélectionnée dans règle 5:
						if (sortie7_5 == 1):
							# Activation sortie DOMESOLAIRE (sortie 7) si FILTRATION inactive (sortie 6)
							if ((GPIO.digitalRead(DOMESOLAIRE) == GPIO.LOW) and (GPIO.digitalRead(FILTRATION) == GPIO.LOW)):
								GPIO.digitalWrite(DOMESOLAIRE, GPIO.HIGH)
					# Vérification plage horaire arrêt
					if ((now.hour == heure_fin_5) and (now.minute == minutes_fin_5)):
						# Vérification si sortie 1 sélectionnée dans règle 5:
						if (sortie1_5 == 1):
							# Désactivation sortie TERRASSE (sortie 1)
							if (GPIO.digitalRead(TERRASSE) == GPIO.HIGH):
								GPIO.digitalWrite(TERRASSE, GPIO.LOW)
						# Vérification si sortie 2 sélectionnée dans règle 5:
						if (sortie2_5 == 1):
							# Désactivation sortie PISCINEBLANC (sortie 2)
							if (GPIO.digitalRead(PISCINEBLANC) == GPIO.HIGH):
								GPIO.digitalWrite(PISCINEBLANC, GPIO.LOW)
						# Vérification si sortie 3 sélectionnée dans règle 5:
						if (sortie3_5 == 1):
							# Désactivation sortie PISCINECOULEURS (sortie 3)
							if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.HIGH):
								GPIO.digitalWrite(PISCINECOULEURS, GPIO.LOW)
						# Vérification si sortie 4 sélectionnée dans règle 5:
						if (sortie4_5 == 1):
							# Désactivation sortie ABRISJARDIN (sortie 4)
							if (GPIO.digitalRead(ABRISJARDIN) == GPIO.HIGH):
								GPIO.digitalWrite(ABRISJARDIN, GPIO.LOW)
						# Vérification si sortie 5 sélectionnée dans règle 5:
						if (sortie5_5 == 1):
							# Désactivation sortie CUISINE (sortie 5)
							if (GPIO.digitalRead(CUISINE) == GPIO.HIGH):
								GPIO.digitalWrite(CUISINE, GPIO.LOW)
						# Vérification si sortie 6 sélectionnée dans règle 5:
						if (sortie6_5 == 1):
							# Désactivation sortie FILTRATION (sortie 6)
							if (GPIO.digitalRead(FILTRATION) == GPIO.HIGH):
								GPIO.digitalWrite(FILTRATION, GPIO.LOW)
						# Vérification si sortie 7 sélectionnée dans règle 5:
						if (sortie7_5 == 1):
							# Désactivation sortie DOMESOLAIRE (sortie 7)
							if (GPIO.digitalRead(DOMESOLAIRE) == GPIO.HIGH):
								GPIO.digitalWrite(DOMESOLAIRE, GPIO.LOW)

	# Gestion RAZ
	if (actif_RAZ == 1):
				if ((now.hour == heure_RAZ) and (now.minute == minutes_RAZ)):
					# Vérification si sortie 1 sélectionnée dans règle RAZ:
					if (sortie1_RAZ == 1):
						# Désactivation sortie TERRASSE (sortie 1)
						if (GPIO.digitalRead(TERRASSE) == GPIO.HIGH):
							GPIO.digitalWrite(TERRASSE, GPIO.LOW)
					# Vérification si sortie 2 sélectionnée dans règle RAZ:
					if (sortie2_RAZ == 1):
						# Désactivation sortie PISCINEBLANC (sortie 2)
						if (GPIO.digitalRead(PISCINEBLANC) == GPIO.HIGH):
							GPIO.digitalWrite(PISCINEBLANC, GPIO.LOW)
					# Vérification si sortie 3 sélectionnée dans règle RAZ:
					if (sortie3_RAZ == 1):
						# Désactivation sortie PISCINECOULEURS (sortie 3)
						if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.HIGH):
							GPIO.digitalWrite(PISCINECOULEURS, GPIO.LOW)
					# Vérification si sortie 4 sélectionnée dans règle RAZ:
					if (sortie4_RAZ == 1):
						# Désactivation sortie ABRISJARDIN (sortie 4)
						if (GPIO.digitalRead(ABRISJARDIN) == GPIO.HIGH):
							GPIO.digitalWrite(ABRISJARDIN, GPIO.LOW)
					# Vérification si sortie 5 sélectionnée dans règle RAZ:
					if (sortie5_RAZ == 1):
						# Désactivation sortie CUISINE (sortie 5)
						if (GPIO.digitalRead(CUISINE) == GPIO.HIGH):
							GPIO.digitalWrite(CUISINE, GPIO.LOW)
					# Vérification si sortie 6 sélectionnée dans règle RAZ:
					if (sortie6_RAZ == 1):
						# Désactivation sortie FILTRATION (sortie 6)
						if (GPIO.digitalRead(FILTRATION) == GPIO.HIGH):
							GPIO.digitalWrite(FILTRATION, GPIO.LOW)
					# Vérification si sortie 7 sélectionnée dans règle RAZ:
					if (sortie7_RAZ == 1):
						# Désactivation sortie DOMESOLAIRE (sortie 7)
						if (GPIO.digitalRead(DOMESOLAIRE) == GPIO.HIGH):
							GPIO.digitalWrite(DOMESOLAIRE, GPIO.LOW)
	
	# Gestion sortie PRESENCE (sortie 8)	
	# Désactivation détecteur de présence
	if ((GPIO.digitalRead(TERRASSE) == GPIO.HIGH) or (GPIO.digitalRead(PISCINEBLANC) == GPIO.HIGH) or (GPIO.digitalRead(PISCINECOULEURS) == GPIO.HIGH) or (GPIO.digitalRead(ABRISJARDIN) == GPIO.HIGH) or (GPIO.digitalRead(CUISINE) == GPIO.HIGH)):
		if (GPIO.digitalRead(PRESENCE) == GPIO.LOW):
			GPIO.digitalWrite(PRESENCE, GPIO.HIGH)
	# Activation détecteur de présence
	if ((GPIO.digitalRead(TERRASSE) == GPIO.LOW) and (GPIO.digitalRead(PISCINEBLANC) == GPIO.LOW) and (GPIO.digitalRead(PISCINECOULEURS) == GPIO.LOW) and (GPIO.digitalRead(ABRISJARDIN) == GPIO.LOW) and (GPIO.digitalRead(CUISINE) == GPIO.LOW)): 
		if (GPIO.digitalRead(PRESENCE) == GPIO.HIGH):
			GPIO.digitalWrite(PRESENCE, GPIO.LOW)

	# Protection pompe DOMESOLAIRE (sortie 7):
	if (GPIO.digitalRead(FILTRATION) == GPIO.HIGH):
		GPIO.digitalWrite(DOMESOLAIRE, GPIO.LOW)

	# gives CPU some time before looping again
	webiopi.sleep(1)


# destroy function is called at WebIOPi shutdown
def destroy():
	GPIO.digitalWrite(TERRASSE, GPIO.LOW)
	GPIO.digitalWrite(PISCINEBLANC, GPIO.LOW)
	GPIO.digitalWrite(PISCINECOULEURS, GPIO.LOW)
	GPIO.digitalWrite(ABRISJARDIN, GPIO.LOW)
	GPIO.digitalWrite(CUISINE, GPIO.LOW)
	GPIO.digitalWrite(FILTRATION, GPIO.LOW)
	GPIO.digitalWrite(DOMESOLAIRE, GPIO.LOW)
	GPIO.digitalWrite(PRESENCE, GPIO.LOW)
Pour ce qui est de tout ce que j'avais prévu dans le dernier post, je n'ai encore rien fait, mais les idées restent les mêmes !

Topodoco
Messages : 62
Enregistré le : mer. 16 mars 2016 23:08

Re: Pilotage pompe et éclairage

Message par Topodoco » sam. 14 mai 2016 20:53

Bon aujourd'hui, je passe enfin au 1er essais...
Oui la programmation n'est pas terminée, et l'interface WEB n'est pas prête non plus...
Sans parler de la sauvegarde des paramètres dans un fichier JSON.
Mais bon, à un moment, ça chatouille trop pour rester la tête dans le code sans tout mettre sur ma framboise....
Donc premier essai, je redémarre ma framboise et essaye de jouer avec l'interface WebIOPI....
La ça commence mal, j'essaye à nouveau avec le navigateur par défaut sous Raspbian, et forcement ça ne fonctionne toujours pas... normal... mais j'avais zappé... :oops:
Du coup j'ai mis à jour ma Raspbian (viewtopic.php?f=7&t=2579) puis réinstallé proprement Webiopi et le patch... toujours la même chose... c'est la que je me suis souvenu...
Petit test avec le smartphone et tout fonctionne... bon au moins je suis à jour :lol:
Ensuite j'ai créé suivi ce tuto: http://webiopi.trouch.com/Tutorial_Basis.html
Petit copier/coller du code... et j'ai galéré à éditer le fichier CONFIG... il faut le modifier en ROOT, mais je ne suis pas un pro du pingouin... alors j'ai un peu cherché... :oops:
Puis comme ça fonctionnait, j'ai copier/coller mon code dans le fichier python...
Et la plus rien.... mais vraiment rien.... Même la page HTML ne s'affiche plus.... :roll:
Alors commence un marathon de "copier/coller le script" et "arrêter/redémarrer Webiopi".
Au fur et à mesure que je colle une partie, je teste....
Finalement, je me rend compte que la commande "datetime.isoweekday()" n'est pas supportée par Webiopi... :evil:
j'ai également testé différentes variantes en ajoutant "date" ou "datetime" entre les instruction (bizarre, mais trouvé avec l'aide de google).... ou encore testé "datetime.weekday()" mais jamais réussi à le faire fonctionner...
Du coup j'ai actuellement perdu un gros bloc de ma programmation...
:idea: Si quelqu’un connait une alternative, je suis preneur !
A part ça, ça à l'air de fonctionner... enfin au moins la sortie GPIO 17 que je vois et pilote encore grâce à l'interface WEB (du projet d'origine).
Super, finalement, il reste beaucoup à faire, mais ça avance bien !!
Je crois que j'ai gagné mon weekend !
Hop je me sauve ! Il est temps de profiter des 2 jours restants !

Topodoco
Messages : 62
Enregistré le : mer. 16 mars 2016 23:08

Re: Pilotage pompe et éclairage

Message par Topodoco » mar. 17 mai 2016 01:49

Bon voila l'avancement du projet:

Petit édit... j'avais tout envoyé directement de ma framboise... mais ce n'est pas très confortable...
Donc les nouveautés:

- ajout de tous les boutons (interface WEB) pour piloter tout l'éclairage ainsi que les 2 pompes,
- ajout d'un bouton "Black Out" qui éteint tout l'éclairage d'un coup,
- gestion des jours de la semaine (en remplaçant la commande "isoweekday" par: "datetime.date.isocalendar(now)[2]")

Fichier HTML:

Code : Tout sélectionner

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>WebIOPi | Light Control</title>
    <script type="text/javascript" src="/webiopi.js"></script>
    <script type="text/javascript">
    webiopi().ready(function() {
        // Create a "TERRASSE" labeled button for GPIO 17
        var button = webiopi().createGPIOButton(17, "TERRASSE");

        // Append button to HTML element with ID="controls" using jQuery
        $("#controls").append(button);

        // Create a "PISCINE BLANC" labeled button for GPIO 27
        var button = webiopi().createGPIOButton(27, "PISCINE BLANC");

        // Append button to HTML element with ID="controls" using jQuery
        $("#controls").append(button);

        // Create a "PISCINE COULEURS" labeled button for GPIO 22
        var button = webiopi().createGPIOButton(22, "PISCINE COULEURS");

        // Append button to HTML element with ID="controls" using jQuery
        $("#controls").append(button);

        // Create a "ABRIS DE JARDIN" labeled button for GPIO 5
        var button = webiopi().createGPIOButton(5, "ABRIS DE JARDIN");

        // Append button to HTML element with ID="controls" using jQuery
        $("#controls").append(button);

	// Create a "CUISINE" labeled button for GPIO 6
        var button = webiopi().createGPIOButton(6, "CUISINE");

        // Append button to HTML element with ID="controls" using jQuery
        $("#controls").append(button);

        // Create a "FILTRATION" labeled button for GPIO 13
        var button = webiopi().createGPIOButton(13, "FILTRATION");

        // Append button to HTML element with ID="controls" using jQuery
        $("#controls").append(button);

        // Create a "DOMES SOLAIRE" labeled button for GPIO 19
        var button = webiopi().createGPIOButton(19, "DOMES SOLAIRE");

        // Append button to HTML element with ID="controls" using jQuery
        $("#controls").append(button);

	// you can also create a button which calls a different function for mouse down and up events
        var button = webiopi().createButton("hold", "BLACK OUT !", mousedown, mouseup);
        $("#controls").append(button);

        // Refresh GPIO buttons
        // pass true to refresh repeatedly of false to refresh once
                
	webiopi().refreshGPIO(true);
    });

    function mousedown() {
        webiopi().digitalWrite(17, 0);
        webiopi().digitalWrite(27, 0);
        webiopi().digitalWrite(22, 0);
        webiopi().digitalWrite(5, 0);
        webiopi().digitalWrite(6, 0);
    }

    function mouseup() {

    }

    </script>
    <style type="text/css">
        button {
            display: block;
            margin: 35px 5px 5px 5px;
            width: 70%;
            height: 70%;
            font-size: 48pt;
            font-weight: bold;
            color: white;
        }

        #gpio17.LOW {
            background-color: Black;
        }

        #gpio17.HIGH {
            background-color: Blue;
        }

        #gpio27.LOW {
            background-color: Black;
        }

        #gpio27.HIGH {
            background-color: Blue;
        }

        #gpio22.LOW {
            background-color: Black;
        }

        #gpio22.HIGH {
            background-color: Green;
        }

        #gpio5.LOW {
            background-color: Black;
        }

        #gpio5.HIGH {
            background-color: Red;
        }

        #gpio6.LOW {
            background-color: Black;
        }

        #gpio6.HIGH {
            background-color: Yellow;
        }

        #gpio13.LOW {
            background-color: Black;
        }

        #gpio13.HIGH {
            background-color: Purple;
        }

        #gpio19.LOW {
            background-color: Black;
        }

        #gpio19.HIGH {
            background-color: Blue;
        }
    </style>
</head>
<body>
    <div id="controls" align="center"></div>
</body>
</html>
Fichier Python:

Code : Tout sélectionner

import webiopi
import datetime
# from datetime import datetime, isoweekday

GPIO = webiopi.GPIO

# Assignation des sorties
# GPIO pin using BCM numbering
# SONDES = GPIO 4 (PIN 7)
TERRASSE = 17  # (PIN 11)
PISCINEBLANC = 27 # (PIN 13)
PISCINECOULEURS = 22 # (PIN 15)
ABRISJARDIN = 5 #  (PIN 29)
CUISINE = 6 #  (PIN 31)
FILTRATION = 13 #  (PIN 33)
DOMESOLAIRE = 19 # (PIN 35)
PRESENCE = 26 #  (PIN 37)

# Règle1
actif_1 = 1
sortie1_1 = 1
sortie2_1 = 1
sortie3_1 = 1
sortie4_1 = 1
sortie5_1 = 1
sortie6_1 = 1
sortie7_1 = 1
Lu_1 = 0
Ma_1 = 1
Me_1 = 0
Je_1 = 0
Ve_1 = 0
Sa_1 = 0
Di_1 = 0
jour_debut_1 = 1
mois_debut_1 = 5
heure_debut_1 = 0
minutes_debut_1 = 31
jour_fin_1 = 30
mois_fin_1 = 10
heure_fin_1 = 0
minutes_fin_1 = 33

# Règle2
actif_2 = 1
sortie1_2 = 1
sortie2_2 = 0
sortie3_2 = 0
sortie4_2 = 0
sortie5_2 = 0
sortie6_2 = 0
sortie7_2 = 0
Lu_2 = 1
Ma_2 = 0
Me_2 = 1
Je_2 = 0
Ve_2 = 0
Sa_2 = 1
Di_2 = 1
jour_debut_2 = 1
mois_debut_2 = 5
heure_debut_2 = 20
minutes_debut_2 = 16
jour_fin_2 = 30
mois_fin_2 = 9
heure_fin_2 = 20
minutes_fin_2 = 17

#Règle3
actif_3 = 0
sortie1_3 = 0
sortie2_3 = 0
sortie3_3 = 0
sortie4_3 = 0
sortie5_3 = 0
sortie6_3 = 0
sortie7_3 = 0
Lu_3 = 0
Ma_3 = 0
Me_3 = 0
Je_3 = 0
Ve_3 = 0
Sa_3 = 0
Di_3 = 0
jour_debut_3 = 1
mois_debut_3 = 1
heure_debut_3 = 0
minutes_debut_3 = 0
jour_fin_3 = 1
mois_fin_3 = 1
heure_fin_3 = 0
minutes_fin_3 = 0

#Règle4
actif_4 = 0
sortie1_4 = 0
sortie2_4 = 0
sortie3_4 = 0
sortie4_4 = 0
sortie5_4 = 0
sortie6_4 = 0
sortie7_4 = 0
Lu_4 = 0
Ma_4 = 0
Me_4 = 0
Je_4 = 0
Ve_4 = 0
Sa_4 = 0
Di_4 = 0
jour_debut_4 = 1
mois_debut_4 = 1
heure_debut_4 = 0
minutes_debut_4 = 0
jour_fin_4 = 1
mois_fin_4 = 1
heure_fin_4 = 0
minutes_fin_4 = 0

#Règle5
actif_5 = 0
sortie1_5 = 0
sortie2_5 = 0
sortie3_5 = 0
sortie4_5 = 0
sortie5_5 = 0
sortie6_5 = 0
sortie7_5 = 0
Lu_5 = 0
Ma_5 = 0
Me_5 = 0
Je_5 = 0
Ve_5 = 0
Sa_5 = 0
Di_5 = 0
jour_debut_5 = 1
mois_debut_5 = 1
heure_debut_5 = 0
minutes_debut_5 = 0
jour_fin_5 = 1
mois_fin_5 = 1
heure_fin_5 = 0
minutes_fin_5 = 0

#RègleRAZ
actif_RAZ = 1
sortie1_RAZ = 1
sortie2_RAZ = 1
sortie3_RAZ = 1
sortie4_RAZ = 1
sortie5_RAZ = 1
sortie6_RAZ = 0
sortie7_RAZ = 0
heure_RAZ = 8
minutes_RAZ = 0

# setup function is automatically called at WebIOPi startup
def setup():
   # set the GPIO used by the light to output
   GPIO.setFunction(TERRASSE, GPIO.OUT)
   GPIO.setFunction(PISCINEBLANC, GPIO.OUT)
   GPIO.setFunction(PISCINECOULEURS, GPIO.OUT)
   GPIO.setFunction(ABRISJARDIN, GPIO.OUT)
   GPIO.setFunction(CUISINE, GPIO.OUT)
   GPIO.setFunction(FILTRATION, GPIO.OUT)
   GPIO.setFunction(DOMESOLAIRE, GPIO.OUT)
   GPIO.setFunction(PRESENCE, GPIO.OUT)

    # retrieve current datetime
   now = datetime.datetime.now()
   act_day = datetime.date.isocalendar(now)[2]

    # Initialisation des sorties relais 1-7 (la sortie 8 tenant compte de l'état des sorties 1-5 sera piloté automatiquement).
   # Initialisation règle 1:

   # Initialisation règle 2:

   # Initialisation règle 3:

   # Initialisation règle 4:

   # Initialisation règle 5:

# loop function is repeatedly called by WebIOPi 
def loop():
   # retrieve current datetime
   now = datetime.datetime.now()
   act_day = datetime.date.isocalendar(now)[2]
   
   # Gestion des règles:
   if (now.second <= 10):
      # Gestion Règle 1:
      if (actif_1 == 1):
         # Vérification si jour actuel programmé dans règle 1:
          if (((act_day == 1) and (Lu_1 == 1)) or ((act_day == 2) and (Ma_1 == 1)) or ((act_day == 3) and (Me_1 == 1)) or ((act_day == 4) and (Je_1 == 1)) or ((act_day == 5) and (Ve_1 == 1)) or ((act_day == 6) and (Sa_1 == 1)) or ((act_day == 7) and (Di_1 == 1))):
              # Vérification si période programmée active:
            # Vérification du mois/jour en cours
            if    (((now.month > mois_debut_1) and (now.month < mois_fin_1)) or ((now.month == mois_debut_1) and (mois_debut_1 != mois_fin_1) and (now.day >=  jour_debut_1)) or ((now.month == mois_fin_1) and (mois_debut_1 != mois_fin_1) and (now.day <= jour_fin_1)) or ((now.month == mois_debut_1) and (mois_debut_1 == mois_fin_1) and (now.day >=  jour_debut_1)and (now.day <=  jour_fin_1))):
                # Vérification plage horaire marche:
               if ((now.hour == heure_debut_1) and (now.minute == minutes_debut_1)):
                  if (sortie1_1 == 1):
                     # Activation sortie TERRASSE (sortie 1)
                     if (GPIO.digitalRead(TERRASSE) == GPIO.LOW):
                        GPIO.digitalWrite(TERRASSE, GPIO.HIGH)
                  # Vérification si sortie 2 sélectionnée dans règle 2:
                  if (sortie2_1 == 1):
                     # Activation sortie PISCINEBLANC (sortie 2)
                     if (GPIO.digitalRead(PISCINEBLANC) == GPIO.LOW):
                        GPIO.digitalWrite(PISCINEBLANC, GPIO.HIGH)
                  # Vérification si sortie 3 sélectionnée dans règle 2:
                  if (sortie3_1 == 1):
                     # Activation sortie PISCINECOULEURS (sortie 3)
                     if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.LOW):
                        GPIO.digitalWrite(PISCINECOULEURS, GPIO.HIGH)
                  # Vérification si sortie 4 sélectionnée dans règle 2:
                  if (sortie4_1 == 1):
                     # Activation sortie ABRISJARDIN (sortie 4)
                     if (GPIO.digitalRead(ABRISJARDIN) == GPIO.LOW):
                        GPIO.digitalWrite(ABRISJARDIN, GPIO.HIGH)
                  # Vérification si sortie 5 sélectionnée dans règle 2:
                  if (sortie5_1 == 1):
                     # Activation sortie CUISINE (sortie 5)
                     if (GPIO.digitalRead(CUISINE) == GPIO.LOW):
                        GPIO.digitalWrite(CUISINE, GPIO.HIGH)
                  # Vérification si sortie 6 sélectionnée dans règle 2:
                  if (sortie6_1 == 1):
                     # Activation sortie FILTRATION (sortie 6)
                     if (GPIO.digitalRead(FILTRATION) == GPIO.LOW):
                        GPIO.digitalWrite(FILTRATION, GPIO.HIGH)
                  # Vérification si sortie 7 sélectionnée dans règle 2:
                  if (sortie7_1 == 1):
                     # Activation sortie DOMESOLAIRE (sortie 7) si FILTRATION inactive (sortie 6)
                     if ((GPIO.digitalRead(DOMESOLAIRE) == GPIO.LOW) and (GPIO.digitalRead(FILTRATION) == GPIO.LOW)):
                        GPIO.digitalWrite(DOMESOLAIRE, GPIO.HIGH)
               # Vérification plage horaire arrêt
               if ((now.hour == heure_fin_1) and (now.minute == minutes_fin_1)):
                  # Vérification si sortie 1 sélectionnée dans règle 2:
                  if (sortie1_1 == 1):
                  # Désactivation sortie TERRASSE (sortie 1)
                     if (GPIO.digitalRead(TERRASSE) == GPIO.HIGH):
                        GPIO.digitalWrite(TERRASSE, GPIO.LOW)
                  # Vérification si sortie 2 sélectionnée dans règle 2:
                  if (sortie2_1 == 1):
                     # Désactivation sortie PISCINEBLANC (sortie 2)
                     if (GPIO.digitalRead(PISCINEBLANC) == GPIO.HIGH):
                        GPIO.digitalWrite(PISCINEBLANC, GPIO.LOW)
                  # Vérification si sortie 3 sélectionnée dans règle 2:
                  if (sortie3_1 == 1):
                     # Désactivation sortie PISCINECOULEURS (sortie 3)
                     if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.HIGH):
                        GPIO.digitalWrite(PISCINECOULEURS, GPIO.LOW)
                  # Vérification si sortie 4 sélectionnée dans règle 2:
                  if (sortie4_1 == 1):
                     # Désactivation sortie ABRISJARDIN (sortie 4)
                     if (GPIO.digitalRead(ABRISJARDIN) == GPIO.HIGH):
                        GPIO.digitalWrite(ABRISJARDIN, GPIO.LOW)
                  # Vérification si sortie 5 sélectionnée dans règle 2:
                  if (sortie5_1 == 1):
                     # Désactivation sortie CUISINE (sortie 5)
                     if (GPIO.digitalRead(CUISINE) == GPIO.HIGH):
                        GPIO.digitalWrite(CUISINE, GPIO.LOW)
                  # Vérification si sortie 6 sélectionnée dans règle 2:
                  if (sortie6_1 == 1):
                     # Désactivation sortie FILTRATION (sortie 6)
                     if (GPIO.digitalRead(FILTRATION) == GPIO.HIGH):
                        GPIO.digitalWrite(FILTRATION, GPIO.LOW)
                  # Vérification si sortie 7 sélectionnée dans règle 2:
                  if (sortie7_1 == 1):
                     # Désactivation sortie DOMESOLAIRE (sortie 7)
                     if (GPIO.digitalRead(DOMESOLAIRE) == GPIO.HIGH):
                        GPIO.digitalWrite(DOMESOLAIRE, GPIO.LOW)

      # Gestion Règle 2:
      if (actif_2 == 1):
         # Vérification si jour actuel programmé dans règle 2:
         if (((act_day == 1) and (Lu_2 == 1)) or ((act_day == 2) and (Ma_2 == 1)) or ((act_day == 3) and (Me_2 == 1)) or ((act_day == 4) and (Je_2 == 1)) or ((act_day == 5) and (Ve_2 == 1)) or ((act_day == 6) and (Sa_2 == 1)) or ((act_day == 7) and (Di_2 == 1))):
            # Vérification si période programmée active:
            # Vérification du mois/jour en cours
            if    (((now.month > mois_debut_2) and (now.month < mois_fin_2)) or ((now.month == mois_debut_2) and (mois_debut_2 != mois_fin_2) and (now.day >=  jour_debut_2)) or ((now.month == mois_fin_2) and (mois_debut_2 != mois_fin_2) and (now.day <= jour_fin_2)) or ((now.month == mois_debut_2) and (mois_debut_2 == mois_fin_2) and (now.day >=  jour_debut_2)and (now.day <=  jour_fin_2))):
               # Vérification plage horaire marche
               if ((now.hour == heure_debut_2) and (now.minute == minutes_debut_2)):
                  # Vérification si sortie 1 sélectionnée dans règle 2:
                  if (sortie1_2 == 1):
                     # Activation sortie TERRASSE (sortie 1)
                     if (GPIO.digitalRead(TERRASSE) == GPIO.LOW):
                        GPIO.digitalWrite(TERRASSE, GPIO.HIGH)
                  # Vérification si sortie 2 sélectionnée dans règle 2:
                  if (sortie2_2 == 1):
                     # Activation sortie PISCINEBLANC (sortie 2)
                     if (GPIO.digitalRead(PISCINEBLANC) == GPIO.LOW):
                        GPIO.digitalWrite(PISCINEBLANC, GPIO.HIGH)
                  # Vérification si sortie 3 sélectionnée dans règle 2:
                  if (sortie3_2 == 1):
                     # Activation sortie PISCINECOULEURS (sortie 3)
                     if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.LOW):
                        GPIO.digitalWrite(PISCINECOULEURS, GPIO.HIGH)
                  # Vérification si sortie 4 sélectionnée dans règle 2:
                  if (sortie4_2 == 1):
                     # Activation sortie ABRISJARDIN (sortie 4)
                     if (GPIO.digitalRead(ABRISJARDIN) == GPIO.LOW):
                        GPIO.digitalWrite(ABRISJARDIN, GPIO.HIGH)
                  # Vérification si sortie 5 sélectionnée dans règle 2:
                  if (sortie5_2 == 1):
                     # Activation sortie CUISINE (sortie 5)
                     if (GPIO.digitalRead(CUISINE) == GPIO.LOW):
                        GPIO.digitalWrite(CUISINE, GPIO.HIGH)
                  # Vérification si sortie 6 sélectionnée dans règle 2:
                  if (sortie6_2 == 1):
                     # Activation sortie FILTRATION (sortie 6)
                     if (GPIO.digitalRead(FILTRATION) == GPIO.LOW):
                        GPIO.digitalWrite(FILTRATION, GPIO.HIGH)
                  # Vérification si sortie 7 sélectionnée dans règle 2:
                  if (sortie7_2 == 1):
                     # Activation sortie DOMESOLAIRE (sortie 7) si FILTRATION inactive (sortie 6)
                     if ((GPIO.digitalRead(DOMESOLAIRE) == GPIO.LOW) and (GPIO.digitalRead(FILTRATION) == GPIO.LOW)):
                        GPIO.digitalWrite(DOMESOLAIRE, GPIO.HIGH)
               # Vérification plage horaire arrêt
               if ((now.hour == heure_fin_2) and (now.minute == minutes_fin_2)):
                  # Vérification si sortie 1 sélectionnée dans règle 2:
                  if (sortie1_2 == 1):
                  # Désactivation sortie TERRASSE (sortie 1)
                     if (GPIO.digitalRead(TERRASSE) == GPIO.HIGH):
                        GPIO.digitalWrite(TERRASSE, GPIO.LOW)
                  # Vérification si sortie 2 sélectionnée dans règle 2:
                  if (sortie2_2 == 1):
                     # Désactivation sortie PISCINEBLANC (sortie 2)
                     if (GPIO.digitalRead(PISCINEBLANC) == GPIO.HIGH):
                        GPIO.digitalWrite(PISCINEBLANC, GPIO.LOW)
                  # Vérification si sortie 3 sélectionnée dans règle 2:
                  if (sortie3_2 == 1):
                     # Désactivation sortie PISCINECOULEURS (sortie 3)
                     if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.HIGH):
                        GPIO.digitalWrite(PISCINECOULEURS, GPIO.LOW)
                  # Vérification si sortie 4 sélectionnée dans règle 2:
                  if (sortie4_2 == 1):
                     # Désactivation sortie ABRISJARDIN (sortie 4)
                     if (GPIO.digitalRead(ABRISJARDIN) == GPIO.HIGH):
                        GPIO.digitalWrite(ABRISJARDIN, GPIO.LOW)
                  # Vérification si sortie 5 sélectionnée dans règle 2:
                  if (sortie5_2 == 1):
                     # Désactivation sortie CUISINE (sortie 5)
                     if (GPIO.digitalRead(CUISINE) == GPIO.HIGH):
                        GPIO.digitalWrite(CUISINE, GPIO.LOW)
                  # Vérification si sortie 6 sélectionnée dans règle 2:
                  if (sortie6_2 == 1):
                     # Désactivation sortie FILTRATION (sortie 6)
                     if (GPIO.digitalRead(FILTRATION) == GPIO.HIGH):
                        GPIO.digitalWrite(FILTRATION, GPIO.LOW)
                  # Vérification si sortie 7 sélectionnée dans règle 2:
                  if (sortie7_2 == 1):
                     # Désactivation sortie DOMESOLAIRE (sortie 7)
                     if (GPIO.digitalRead(DOMESOLAIRE) == GPIO.HIGH):
                        GPIO.digitalWrite(DOMESOLAIRE, GPIO.LOW)

      # Gestion Règle 3:
      if (actif_3 == 1):
         # Vérification si jour actuel programmé dans règle 3:
         if (((act_day == 1) and (Lu_3 == 1)) or ((act_day == 2) and (Ma_3 == 1)) or ((act_day == 3) and (Me_3 == 1)) or ((act_day == 4) and (Je_3 == 1)) or ((act_day == 5) and (Ve_3 == 1)) or ((act_day == 6) and (Sa_3 == 1)) or ((act_day == 7) and (Di_3 == 1))):
            # Vérification si période programmée active:
            # Vérification du mois/jour en cours
            if    (((now.month > mois_debut_3) and (now.month < mois_fin_3)) or ((now.month == mois_debut_3) and (mois_debut_3 != mois_fin_3) and (now.day >=  jour_debut_3)) or ((now.month == mois_fin_3) and (mois_debut_3 != mois_fin_3) and (now.day <= jour_fin_3)) or ((now.month == mois_debut_3) and (mois_debut_3 == mois_fin_3) and (now.day >=  jour_debut_3)and (now.day <=  jour_fin_3))):
               # Vérification plage horaire marche:
               if ((now.hour == heure_debut_3) and (now.minute == minutes_debut_3)):
                  # Vérification si sortie 1 sélectionnée dans règle 3:
                  if (sortie1_3 == 1):
                     # Activation sortie TERRASSE (sortie 1)
                     if (GPIO.digitalRead(TERRASSE) == GPIO.LOW):
                        GPIO.digitalWrite(TERRASSE, GPIO.HIGH)
                  # Vérification si sortie 2 sélectionnée dans règle 3:
                  if (sortie2_3 == 1):
                     # Activation sortie PISCINEBLANC (sortie 2)
                     if (GPIO.digitalRead(PISCINEBLANC) == GPIO.LOW):
                        GPIO.digitalWrite(PISCINEBLANC, GPIO.HIGH)
                  # Vérification si sortie 3 sélectionnée dans règle 3:
                  if (sortie3_3 == 1):
                     # Activation sortie PISCINECOULEURS (sortie 3)
                     if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.LOW):
                        GPIO.digitalWrite(PISCINECOULEURS, GPIO.HIGH)
                  # Vérification si sortie 4 sélectionnée dans règle 3:
                  if (sortie4_3 == 1):
                     # Activation sortie ABRISJARDIN (sortie 4)
                     if (GPIO.digitalRead(ABRISJARDIN) == GPIO.LOW):
                        GPIO.digitalWrite(ABRISJARDIN, GPIO.HIGH)
                  # Vérification si sortie 5 sélectionnée dans règle 3:
                  if (sortie5_3 == 1):
                     # Activation sortie CUISINE (sortie 5)
                     if (GPIO.digitalRead(CUISINE) == GPIO.LOW):
                        GPIO.digitalWrite(CUISINE, GPIO.HIGH)
                  # Vérification si sortie 6 sélectionnée dans règle 3:
                  if (sortie6_3 == 1):
                     # Activation sortie FILTRATION (sortie 6)
                     if (GPIO.digitalRead(FILTRATION) == GPIO.LOW):
                        GPIO.digitalWrite(FILTRATION, GPIO.HIGH)
                  # Vérification si sortie 7 sélectionnée dans règle 3:
                  if (sortie7_3 == 1):
                     # Activation sortie DOMESOLAIRE (sortie 7) si FILTRATION inactive (sortie 6)
                     if ((GPIO.digitalRead(DOMESOLAIRE) == GPIO.LOW) and (GPIO.digitalRead(FILTRATION) == GPIO.LOW)):
                        GPIO.digitalWrite(DOMESOLAIRE, GPIO.HIGH)
               # Vérification plage horaire arrêt
               if ((now.hour == heure_fin_3) and (now.minute == minutes_fin_3)):
                  # Vérification si sortie 1 sélectionnée dans règle 3:
                  if (sortie1_3 == 1):
                  # Désactivation sortie TERRASSE (sortie 1)
                     if (GPIO.digitalRead(TERRASSE) == GPIO.HIGH):
                        GPIO.digitalWrite(TERRASSE, GPIO.LOW)
                  # Vérification si sortie 2 sélectionnée dans règle 3:
                  if (sortie2_3 == 1):
                     # Désactivation sortie PISCINEBLANC (sortie 2)
                     if (GPIO.digitalRead(PISCINEBLANC) == GPIO.HIGH):
                        GPIO.digitalWrite(PISCINEBLANC, GPIO.LOW)
                  # Vérification si sortie 3 sélectionnée dans règle 3:
                  if (sortie3_3 == 1):
                     # Désactivation sortie PISCINECOULEURS (sortie 3)
                     if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.HIGH):
                        GPIO.digitalWrite(PISCINECOULEURS, GPIO.LOW)
                  # Vérification si sortie 4 sélectionnée dans règle 3:
                  if (sortie4_3 == 1):
                     # Désactivation sortie ABRISJARDIN (sortie 4)
                     if (GPIO.digitalRead(ABRISJARDIN) == GPIO.HIGH):
                        GPIO.digitalWrite(ABRISJARDIN, GPIO.LOW)
                  # Vérification si sortie 5 sélectionnée dans règle 3:
                  if (sortie5_3 == 1):
                     # Désactivation sortie CUISINE (sortie 5)
                     if (GPIO.digitalRead(CUISINE) == GPIO.HIGH):
                        GPIO.digitalWrite(CUISINE, GPIO.LOW)
                  # Vérification si sortie 6 sélectionnée dans règle 3:
                  if (sortie6_3 == 1):
                     # Désactivation sortie FILTRATION (sortie 6)
                     if (GPIO.digitalRead(FILTRATION) == GPIO.HIGH):
                        GPIO.digitalWrite(FILTRATION, GPIO.LOW)
                  # Vérification si sortie 7 sélectionnée dans règle 3:
                  if (sortie7_3 == 1):
                     # Désactivation sortie DOMESOLAIRE (sortie 7)
                     if (GPIO.digitalRead(DOMESOLAIRE) == GPIO.HIGH):
                        GPIO.digitalWrite(DOMESOLAIRE, GPIO.LOW)

      # Gestion Règle 4:
      if (actif_4 == 1):
         # Vérification si jour actuel programmé dans règle 4:
         if (((act_day == 1) and (Lu_4 == 1)) or ((act_day == 2) and (Ma_4 == 1)) or ((act_day == 3) and (Me_4 == 1)) or ((act_day == 4) and (Je_4 == 1)) or ((act_day == 5) and (Ve_4 == 1)) or ((act_day == 6) and (Sa_4 == 1)) or ((act_day == 7) and (Di_4 == 1))):
            # Vérification si période programmée active:
            # Vérification du mois/jour en cours
            if    (((now.month > mois_debut_4) and (now.month < mois_fin_4)) or ((now.month == mois_debut_4) and (mois_debut_4 != mois_fin_4) and (now.day >=  jour_debut_4)) or ((now.month == mois_fin_4) and (mois_debut_4 != mois_fin_4) and (now.day <= jour_fin_4)) or ((now.month == mois_debut_4) and (mois_debut_4 == mois_fin_4) and (now.day >=  jour_debut_4)and (now.day <=  jour_fin_4))):
               # Vérification plage horaire marche:
               if ((now.hour == heure_debut_4) and (now.minute == minutes_debut_4)):
                  # Vérification si sortie 1 sélectionnée dans règle 4:
                  if (sortie1_4 == 1):
                     # Activation sortie TERRASSE (sortie 1)
                     if (GPIO.digitalRead(TERRASSE) == GPIO.LOW):
                        GPIO.digitalWrite(TERRASSE, GPIO.HIGH)
                  # Vérification si sortie 2 sélectionnée dans règle 4:
                  if (sortie2_4 == 1):
                     # Activation sortie PISCINEBLANC (sortie 2)
                     if (GPIO.digitalRead(PISCINEBLANC) == GPIO.LOW):
                        GPIO.digitalWrite(PISCINEBLANC, GPIO.HIGH)
                  # Vérification si sortie 3 sélectionnée dans règle 4:
                  if (sortie3_4 == 1):
                     # Activation sortie PISCINECOULEURS (sortie 3)
                     if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.LOW):
                        GPIO.digitalWrite(PISCINECOULEURS, GPIO.HIGH)
                  # Vérification si sortie 4 sélectionnée dans règle 4:
                  if (sortie4_4 == 1):
                     # Activation sortie ABRISJARDIN (sortie 4)
                     if (GPIO.digitalRead(ABRISJARDIN) == GPIO.LOW):
                        GPIO.digitalWrite(ABRISJARDIN, GPIO.HIGH)
                  # Vérification si sortie 5 sélectionnée dans règle 4:
                  if (sortie5_4 == 1):
                     # Activation sortie CUISINE (sortie 5)
                     if (GPIO.digitalRead(CUISINE) == GPIO.LOW):
                        GPIO.digitalWrite(CUISINE, GPIO.HIGH)
                  # Vérification si sortie 6 sélectionnée dans règle 4:
                  if (sortie6_4 == 1):
                     # Activation sortie FILTRATION (sortie 6)
                     if (GPIO.digitalRead(FILTRATION) == GPIO.LOW):
                        GPIO.digitalWrite(FILTRATION, GPIO.HIGH)
                  # Vérification si sortie 7 sélectionnée dans règle 4:
                  if (sortie7_4 == 1):
                     # Activation sortie DOMESOLAIRE (sortie 7) si FILTRATION inactive (sortie 6)
                     if ((GPIO.digitalRead(DOMESOLAIRE) == GPIO.LOW) and (GPIO.digitalRead(FILTRATION) == GPIO.LOW)):
                        GPIO.digitalWrite(DOMESOLAIRE, GPIO.HIGH)
               # Vérification plage horaire arrêt
               if ((now.hour == heure_fin_4) and (now.minute == minutes_fin_4)):
                  # Vérification si sortie 1 sélectionnée dans règle 4:
                  if (sortie1_4 == 1):
                     # Désactivation sortie TERRASSE (sortie 1)
                     if (GPIO.digitalRead(TERRASSE) == GPIO.HIGH):
                        GPIO.digitalWrite(TERRASSE, GPIO.LOW)
                  # Vérification si sortie 2 sélectionnée dans règle 4:
                  if (sortie2_4 == 1):
                     # Désactivation sortie PISCINEBLANC (sortie 2)
                     if (GPIO.digitalRead(PISCINEBLANC) == GPIO.HIGH):
                        GPIO.digitalWrite(PISCINEBLANC, GPIO.LOW)
                  # Vérification si sortie 3 sélectionnée dans règle 4:
                  if (sortie3_4 == 1):
                     # Désactivation sortie PISCINECOULEURS (sortie 3)
                     if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.HIGH):
                        GPIO.digitalWrite(PISCINECOULEURS, GPIO.LOW)
                  # Vérification si sortie 4 sélectionnée dans règle 4:
                  if (sortie4_4 == 1):
                     # Désactivation sortie ABRISJARDIN (sortie 4)
                     if (GPIO.digitalRead(ABRISJARDIN) == GPIO.HIGH):
                        GPIO.digitalWrite(ABRISJARDIN, GPIO.LOW)
                  # Vérification si sortie 5 sélectionnée dans règle 4:
                  if (sortie5_4 == 1):
                     # Désactivation sortie CUISINE (sortie 5)
                     if (GPIO.digitalRead(CUISINE) == GPIO.HIGH):
                        GPIO.digitalWrite(CUISINE, GPIO.LOW)
                  # Vérification si sortie 6 sélectionnée dans règle 4:
                  if (sortie6_4 == 1):
                     # Désactivation sortie FILTRATION (sortie 6)
                     if (GPIO.digitalRead(FILTRATION) == GPIO.HIGH):
                        GPIO.digitalWrite(FILTRATION, GPIO.LOW)
                  # Vérification si sortie 7 sélectionnée dans règle 4:
                  if (sortie7_4 == 1):
                     # Désactivation sortie DOMESOLAIRE (sortie 7)
                     if (GPIO.digitalRead(DOMESOLAIRE) == GPIO.HIGH):
                        GPIO.digitalWrite(DOMESOLAIRE, GPIO.LOW)

      # Gestion Règle 5:
      if (actif_5 == 1):
         # Vérification si jour actuel programmé dans règle 5:
         if (((act_day == 1) and (Lu_5 == 1)) or ((act_day == 2) and (Ma_5 == 1)) or ((act_day == 3) and (Me_5 == 1)) or ((act_day == 4) and (Je_5 == 1)) or ((act_day == 5) and (Ve_5 == 1)) or ((act_day == 6) and (Sa_5 == 1)) or ((act_day == 7) and (Di_5 == 1))):
            # Vérification si période programmée active:
            # Vérification du mois/jour en cours
            if    (((now.month > mois_debut_5) and (now.month < mois_fin_5)) or ((now.month == mois_debut_5) and (mois_debut_5 != mois_fin_5) and (now.day >=  jour_debut_5)) or ((now.month == mois_fin_5) and (mois_debut_5 != mois_fin_5) and (now.day <= jour_fin_5)) or ((now.month == mois_debut_5) and (mois_debut_5 == mois_fin_5) and (now.day >=  jour_debut_5)and (now.day <=  jour_fin_5))):
               # Vérification plage horaire marche:
               if ((now.hour == heure_debut_5) and (now.minute == minutes_debut_5)):
                  # Vérification si sortie 1 sélectionnée dans règle 5:
                  if (sortie1_5 == 1):
                     # Activation sortie TERRASSE (sortie 1)
                     if (GPIO.digitalRead(TERRASSE) == GPIO.LOW):
                        GPIO.digitalWrite(TERRASSE, GPIO.HIGH)
                  # Vérification si sortie 2 sélectionnée dans règle 5:
                  if (sortie2_5 == 1):
                     # Activation sortie PISCINEBLANC (sortie 2)
                     if (GPIO.digitalRead(PISCINEBLANC) == GPIO.LOW):
                        GPIO.digitalWrite(PISCINEBLANC, GPIO.HIGH)
                  # Vérification si sortie 3 sélectionnée dans règle 5:
                  if (sortie3_5 == 1):
                     # Activation sortie PISCINECOULEURS (sortie 3)
                     if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.LOW):
                        GPIO.digitalWrite(PISCINECOULEURS, GPIO.HIGH)
                  # Vérification si sortie 4 sélectionnée dans règle 5:
                  if (sortie4_5 == 1):
                     # Activation sortie ABRISJARDIN (sortie 4)
                     if (GPIO.digitalRead(ABRISJARDIN) == GPIO.LOW):
                        GPIO.digitalWrite(ABRISJARDIN, GPIO.HIGH)
                  # Vérification si sortie 5 sélectionnée dans règle 5:
                  if (sortie5_5 == 1):
                     # Activation sortie CUISINE (sortie 5)
                     if (GPIO.digitalRead(CUISINE) == GPIO.LOW):
                        GPIO.digitalWrite(CUISINE, GPIO.HIGH)
                  # Vérification si sortie 6 sélectionnée dans règle 5:
                  if (sortie6_5 == 1):
                     # Activation sortie FILTRATION (sortie 6)
                     if (GPIO.digitalRead(FILTRATION) == GPIO.LOW):
                        GPIO.digitalWrite(FILTRATION, GPIO.HIGH)
                  # Vérification si sortie 7 sélectionnée dans règle 5:
                  if (sortie7_5 == 1):
                     # Activation sortie DOMESOLAIRE (sortie 7) si FILTRATION inactive (sortie 6)
                     if ((GPIO.digitalRead(DOMESOLAIRE) == GPIO.LOW) and (GPIO.digitalRead(FILTRATION) == GPIO.LOW)):
                        GPIO.digitalWrite(DOMESOLAIRE, GPIO.HIGH)
               # Vérification plage horaire arrêt
               if ((now.hour == heure_fin_5) and (now.minute == minutes_fin_5)):
                  # Vérification si sortie 1 sélectionnée dans règle 5:
                  if (sortie1_5 == 1):
                     # Désactivation sortie TERRASSE (sortie 1)
                     if (GPIO.digitalRead(TERRASSE) == GPIO.HIGH):
                        GPIO.digitalWrite(TERRASSE, GPIO.LOW)
                  # Vérification si sortie 2 sélectionnée dans règle 5:
                  if (sortie2_5 == 1):
                     # Désactivation sortie PISCINEBLANC (sortie 2)
                     if (GPIO.digitalRead(PISCINEBLANC) == GPIO.HIGH):
                        GPIO.digitalWrite(PISCINEBLANC, GPIO.LOW)
                  # Vérification si sortie 3 sélectionnée dans règle 5:
                  if (sortie3_5 == 1):
                     # Désactivation sortie PISCINECOULEURS (sortie 3)
                     if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.HIGH):
                        GPIO.digitalWrite(PISCINECOULEURS, GPIO.LOW)
                  # Vérification si sortie 4 sélectionnée dans règle 5:
                  if (sortie4_5 == 1):
                     # Désactivation sortie ABRISJARDIN (sortie 4)
                     if (GPIO.digitalRead(ABRISJARDIN) == GPIO.HIGH):
                        GPIO.digitalWrite(ABRISJARDIN, GPIO.LOW)
                  # Vérification si sortie 5 sélectionnée dans règle 5:
                  if (sortie5_5 == 1):
                     # Désactivation sortie CUISINE (sortie 5)
                     if (GPIO.digitalRead(CUISINE) == GPIO.HIGH):
                        GPIO.digitalWrite(CUISINE, GPIO.LOW)
                  # Vérification si sortie 6 sélectionnée dans règle 5:
                  if (sortie6_5 == 1):
                     # Désactivation sortie FILTRATION (sortie 6)
                     if (GPIO.digitalRead(FILTRATION) == GPIO.HIGH):
                        GPIO.digitalWrite(FILTRATION, GPIO.LOW)
                  # Vérification si sortie 7 sélectionnée dans règle 5:
                  if (sortie7_5 == 1):
                     # Désactivation sortie DOMESOLAIRE (sortie 7)
                     if (GPIO.digitalRead(DOMESOLAIRE) == GPIO.HIGH):
                        GPIO.digitalWrite(DOMESOLAIRE, GPIO.LOW)

   # Protection pompe DOMESOLAIRE (sortie 7):
   if (GPIO.digitalRead(FILTRATION) == GPIO.HIGH):
      GPIO.digitalWrite(DOMESOLAIRE, GPIO.LOW)

   # Gestion sortie PRESENCE (sortie 8)   
   # Désactivation détecteur de présence
   if ((GPIO.digitalRead(TERRASSE) == GPIO.HIGH) or (GPIO.digitalRead(PISCINEBLANC) == GPIO.HIGH) or (GPIO.digitalRead(PISCINECOULEURS) == GPIO.HIGH) or (GPIO.digitalRead(ABRISJARDIN) == GPIO.HIGH) or (GPIO.digitalRead(CUISINE) == GPIO.HIGH)):
      if (GPIO.digitalRead(PRESENCE) == GPIO.LOW):
         GPIO.digitalWrite(PRESENCE, GPIO.HIGH)
   # Activation détecteur de présence
   if ((GPIO.digitalRead(TERRASSE) == GPIO.LOW) and (GPIO.digitalRead(PISCINEBLANC) == GPIO.LOW) and (GPIO.digitalRead(PISCINECOULEURS) == GPIO.LOW) and (GPIO.digitalRead(ABRISJARDIN) == GPIO.LOW) and (GPIO.digitalRead(CUISINE) == GPIO.LOW)): 
      if (GPIO.digitalRead(PRESENCE) == GPIO.HIGH):
         GPIO.digitalWrite(PRESENCE, GPIO.LOW)

   # Gestion sortie PISCINECOULEURS (sortie 3), si TERRASSE à 1.
   # Désactivation détecteur de présence
   if ((GPIO.digitalRead(TERRASSE) == GPIO.HIGH)):
      GPIO.digitalWrite(PISCINECOULEURS, GPIO.HIGH)

   # Gestion RAZ
   if (actif_RAZ == 1):
            if ((now.hour == heure_RAZ) and (now.minute == minutes_RAZ)):
               # Vérification si sortie 1 sélectionnée dans règle RAZ:
               if (sortie1_RAZ == 1):
                  # Désactivation sortie TERRASSE (sortie 1)
                  if (GPIO.digitalRead(TERRASSE) == GPIO.HIGH):
                     GPIO.digitalWrite(TERRASSE, GPIO.LOW)
               # Vérification si sortie 2 sélectionnée dans règle RAZ:
               if (sortie2_RAZ == 1):
                  # Désactivation sortie PISCINEBLANC (sortie 2)
                  if (GPIO.digitalRead(PISCINEBLANC) == GPIO.HIGH):
                     GPIO.digitalWrite(PISCINEBLANC, GPIO.LOW)
               # Vérification si sortie 3 sélectionnée dans règle RAZ:
               if (sortie3_RAZ == 1):
                  # Désactivation sortie PISCINECOULEURS (sortie 3)
                  if (GPIO.digitalRead(PISCINECOULEURS) == GPIO.HIGH):
                     GPIO.digitalWrite(PISCINECOULEURS, GPIO.LOW)
               # Vérification si sortie 4 sélectionnée dans règle RAZ:
               if (sortie4_RAZ == 1):
                  # Désactivation sortie ABRISJARDIN (sortie 4)
                  if (GPIO.digitalRead(ABRISJARDIN) == GPIO.HIGH):
                     GPIO.digitalWrite(ABRISJARDIN, GPIO.LOW)
               # Vérification si sortie 5 sélectionnée dans règle RAZ:
               if (sortie5_RAZ == 1):
                  # Désactivation sortie CUISINE (sortie 5)
                  if (GPIO.digitalRead(CUISINE) == GPIO.HIGH):
                     GPIO.digitalWrite(CUISINE, GPIO.LOW)
               # Vérification si sortie 6 sélectionnée dans règle RAZ:
               if (sortie6_RAZ == 1):
                  # Désactivation sortie FILTRATION (sortie 6)
                  if (GPIO.digitalRead(FILTRATION) == GPIO.HIGH):
                     GPIO.digitalWrite(FILTRATION, GPIO.LOW)
               # Vérification si sortie 7 sélectionnée dans règle RAZ:
               if (sortie7_RAZ == 1):
                  # Désactivation sortie DOMESOLAIRE (sortie 7)
                  if (GPIO.digitalRead(DOMESOLAIRE) == GPIO.HIGH):
                     GPIO.digitalWrite(DOMESOLAIRE, GPIO.LOW)

   # gives CPU some time before looping again
   webiopi.sleep(0.1)

# destroy function is called at WebIOPi shutdown
def destroy():
   GPIO.digitalWrite(TERRASSE, GPIO.LOW)
   GPIO.digitalWrite(PISCINEBLANC, GPIO.LOW)
   GPIO.digitalWrite(PISCINECOULEURS, GPIO.LOW)
   GPIO.digitalWrite(ABRISJARDIN, GPIO.LOW)
   GPIO.digitalWrite(CUISINE, GPIO.LOW)
   GPIO.digitalWrite(FILTRATION, GPIO.LOW)
   GPIO.digitalWrite(DOMESOLAIRE, GPIO.LOW)
   GPIO.digitalWrite(PRESENCE, GPIO.LOW)
Il reste toujours à mettre en place les sondes de températures et les programmer...
J'ai aussi joué sur la couleur des boutons... il faudra voir pour choisir un "standard" sympa.
Bien sur, il n'y a toujours pas de sauvegarde dans un fichier "à part" pour les paramètres.
Et pas encore d'interface WEB pour paramétrer cela...
Encore et toujours beaucoup de boulot...
Toutes les initialisations sont encore à faire... mais je crois que je vais encore une fois reprendre la programmation, et modifier pas mal de chose, pour éviter les cas particuliers...
exemple:
Règle 1:
début le 05/02 à 20:00 fin le 20/02 à 2:00
actuellement, je vais bien démarrer une dernière fois le 20/02 à 20h... mais la fin étant le 21/02 (le lendemain du dernier jour de ma règle), elle ne sera pas prise en compte...
J'envisage donc de plutôt partir sur des calculs de durées...
L'heure de début est connue, calculer la durée jusqu'à l'heure de fin, et arrêter lorsqu'il est "heure de début + durée calculée".
Cela réduira sans doute pas mal mes boucles, et permettra aussi une programmation plus simple des initialisations.

Topodoco
Messages : 62
Enregistré le : mer. 16 mars 2016 23:08

Re: Pilotage pompe et éclairage

Message par Topodoco » ven. 20 mai 2016 20:07

Bon bah comme dit, je voulais éviter les cas particuliers dans mes règles.
Du coup, plutôt que de continuer à comparer des valeurs de mois/jours/heures/minutes, j'ai voulu créer des "variable de temps" (on dit comme ça ?)
L'idée était de mettre dans une seule variable toutes les infos précédentes.
Avec 1 variable de début et 1 de fin pour chaque règle, il me suffisait de vérifier si le jour en cours se trouve entre les 2 variables crées.
Pour le code il faut taper ceci:

Code : Tout sélectionner

import datetime
from datetime import datetime
...
now = datetime.datetime.now()
act_day = datetime.date.isocalendar(now)[2]
act_year = datetime.date.isocalendar(now)[0]
...
# Vérification si début et fin de la règle_1 dans la même année (ex: juin - sept.)
if mois_debut_1 < mois_fin_1:
	annee_debut_1 = act_year
# Vérification si début et fin de la règle_1 chevauchent 2 années (ex: nov.-mars)
if mois_debut_1 > mois_fin_1:
	if mois_debut_1 > mois_en_cours:
		annee_debut_1 = act_year -1
		annee_fin_1 = act_year
	if mois_debut_1 > mois_en_cours:
		annee_debut_1 = act_year
		annee_fin_1 = act_year +1
# Vérification si début et fin de la règle_1 chevauchent 2 jours (ex: 23:00-07:00)
if (heure_debut_1 > heure_fin_1) or (heure_debut_1 == heure_fin_1 and ((minutes_debut_1 > minutes_fin_1))):
	jour_fin_1 = jour_fin_1 + 1
			
# Création dates de début et de fin règle_1
debut_1 = datetime(annee_debut_1,mois_debut_1,jour_debut_1,heure_debut_1,minutes_debut_1)
fin_1 = datetime(annee_fin_1,mois_fin_1,jour_fin_1,heure_fin_1,minutes_fin_1)
...
Tout à l'air de fonctionner en Python, par contre, dès que je met la ligne:

Code : Tout sélectionner

from datetime import datetime
dans le script, l'interface Web de Webiopi n'est plus accessible...
Puisque ce n'est pas spécialement un problème "Que d'eau, que d'eau !", mais à mon avis plus un souci de Python, j'ai créé un sujet spécifique ici: viewtopic.php?f=38&t=2608&p=16365#p16365
Si vous avez des explications ou des idées, trouvé mon erreur... je suis à votre écoute ! :?

Répondre

Retourner vers « Que d'eau, que d'eau ! »