Raspberrypi GPS trigger project


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.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)

This is the 2nd python script.

import datetime
import time
import RPi.GPIO as GPIO
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’]:

First, this is really a “How to program in Python” question… of which I am unsure the Blynk libraries are fully operational with direct pin control for that yet???

As for the App being OUTPUT and the script being INPUT… that is correct… the App (via the server) outputs a signal to the RPi which, as set for INPUT, will receive it (assuming you have set up code for virtual pin usage).

EDIT: this last answer rattled around in my head, so I revisited it… If you enter a region, the App should “trigger” GP9… however that will depend in direct pin control working (that aforementioned onoff addon)… however you WILL want that pin on the RPI set as an OUTPUT in your script if you want it to control a physical device. But as for triggering an internal code function, then I would suggest using Virtual Pins in both the App and as a BLYNK_WRITE(vPIN) type function in your script instead - but exactly how to do that in Python is beyond me.