Python Forum

Full Version: running different script together
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi there,

I'm almost a complete newbie regarding python, and I'm struggling with a problem. I've got a google AIY voice kit running and want the raspberry to run the next script next to the google assistant script. At this moment I use a wemos esp easy to control some leds, but it's a bit inefficient to have a raspberry and a wemos in the same housing ( a model lighthouse) to control some leds....I've tried to insert the code in the assistant script but the script (see below) runs in a loop. I know it must be possible to run this script along the assistant script (they don't have to interact with eachother), but I have no clou on how to achieve that. Can anyone point me in the right direction?

#!/usr/bin/env python3

# execute doorled in lighthouse at specific times
import time
import os
import RPi.GPIO as GPIO
GPIO.setwarnings(False)


doorled = 17 
GPIO.setup(doorled,GPIO.OUT)
GPIO.output(doorled,GPIO.HIGH)

#Define define on time Change the value to what relay you want to respond to they are split into hours minutes and seconds.
doorledONH = 20
doorledONM = 10
doorledONS = 0


#Define doorled off time
doorledOFFH = 20
doorledOFFM = 15
doorledOFFS = 15


# start of doorled cycle
while True: 
    dt = list(time.localtime())#Get local time and store it in dt
    minute = dt[4]
    second = dt[5]
    time.sleep(0.5)
    os.system('clear')
      

#doorled Starts    
#doorled On Logic
    if hour == doorledONH: 				#Relay 1 On Hour setting
       if minute == doorledONM:				#Relay 1 On Minute setting
            if second == doorledONS:			#Relay 1 On Second setting
                GPIO.output(doorled, GPIO.LOW)		#Turn On Relay 1 if all above conditions are true
                
#doorled Off Logic
    if hour == doorledOFFH:				#Relay 1 Off Hour setting
        if minute == doorledOFFM:			#Relay 1 Off Minute setting
            if second == doorledOFFS:			#Relay 1 Off Second setting
                GPIO.output(doorled, GPIO.HIGH)	#Turn Off Relay 1 if all above conditions are true

# end of doorled cycle
 
Hi,

you can start as many process / Python scripts as you want (well, until you reach the limits of your hardware ;-) ). Simply open as many terminals as you need and start the scripts manually.
If you want them to start at the start of the system, write a systemd service unit for each script.

Regards, noisefloor
Thank you! I allready hoped it was as simple as that :)