Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Time event
#6
Awesome, il give a try. THANK !

Work great ! thank.
complete code if you need some light for your plant:

#A2.1
import RPi.GPIO as GPIO
import datetime
import time
time.ctime()
time.strftime("%a, %d %b %Y %H:%M:%S")

h = int(time.strftime('%H'))

light = 21

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

if h>=7 and h<21:
    GPIO.setup(light, GPIO.OUT)
    GPIO.output(light, GPIO.LOW)
    now = datetime.datetime.now()
    path = '/media/pi/34BF-2414/log.txt'
    log = open(path,'a')
    log.write(now.strftime('\n' + "%Y-%m-%d %H:%M"))
    log.write('  Main light ON')
    log.close()
else:
    
    GPIO.output(light, GPIO.HIGH)
    now = datetime.datetime.now()
    path = '/media/pi/34BF-2414/log.txt'
    log = open(path,'a')
    log.write(now.strftime('\n' + "%Y-%m-%d %H:%M"))
    log.write('  Main light OFF')
    log.close()
Reply


Messages In This Thread
Time event - by xxl1087 - Feb-06-2018, 07:33 PM
RE: Time event - by Larz60+ - Feb-06-2018, 07:38 PM
RE: Time event - by buran - Feb-07-2018, 09:31 AM
RE: Time event - by xxl1087 - Feb-08-2018, 01:44 AM
RE: Time event - by zykbee - Feb-08-2018, 02:11 AM
RE: Time event - by xxl1087 - Feb-11-2018, 08:15 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020