Hello,
I’m busy with an hobby project. I want to trigger a light when i enter a specific location.
Blynk is up and running on my raspberry pi.
Also installed the blynk app on my smartphone,created a new project and added the GPS trigger widget as you can see on the screenshot.
So when i enter the loacation i want to trigger GPIO9.
I made a python script who is calculating the sunrise and sunset time so the light is only triggered when i’m enter the location after sunset and before sunrise.
The question is how can i made the python script ‘listen’ to the GP9 pin to trigger the light.
The GP9 pin in the blynk app is set to output but at the same time the GP9 is set to input @ the python script? this doesn’t work for me.
Hopefully someone can give me a hint.
Here is the first python script who is listening the the GP9 pin and triggers the 2nd python script who is calculating the sunset and sunrise time ant triggers the relay.
import RPi.GPIO as GPIO
import time
import os
var = 1
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(9, GPIO.IN, pull_up_down = GPIO.PUD_DOWN )
while var == 1 :
def Start(channel):
os.system(“python /home/pi/calculate_light.py”)
GPIO.add_event_detect(9, GPIO.BOTH, callback = Start, bouncetime = 1000)
time.sleep(1)
This is the 2nd python script.
import datetime
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
from astral import Astral
import subprocess
city_name = ‘Brussels’
a = Astral()
a.solar_depression = ‘civil’
city = a[city_name]
timezone = city.timezone
sun = city.sun(date=datetime.date.today(), local=True)
tzinfo = sun[‘dawn’].tzinfo
print(‘Dawn: %s’ % str(sun[‘dawn’]))
print(‘Sunrise: %s’ % str(sun[‘sunrise’]))
print(‘Noon: %s’ % str(sun[‘noon’]))
print(‘Sunset: %s’ % str(sun[‘sunset’]))
print(‘Dusk: %s’ % str(sun[‘dusk’]))
now = datetime.datetime.now(tzinfo)
mydate = datetime.datetime(2017, 10, 15, 5, 8, 24, 78915, tzinfo)
if sun[‘dawn’] < now < sun[‘dusk’]:
GPIO.setup(23,GPIO.OUT)
GPIO.output(23,GPIO.HIGH)
time.sleep(2)
GPIO.setup(23,GPIO.LOW)