Physical Button

In order to drive my neighbors a little less crazy this year I added a wireless physical button to my trigger my lightshow on demand as opposed to a schedule. I'm using this wireless RF button from amazon. https://www.amazon.com/Switch-Wireless-Control-1-Channel-Transmitters/dp/B071WM1YGS

The python script below is button.py and is saved to the ~/lightshowpi/py/ folder

#
#python script for button input to start lightshow
#

import RPi.GPIO as GPIO #Import Raspberry Pi GPIO library
from time import sleep
import subprocess

GPIO.setwarnings(True) #Warnings
GPIO.setmode(GPIO.BOARD) #Use physical pin numbering
GPIO.setup(40, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #Set pin 29  to be an input pint and set intial value to be pulled low (off)

while True: #Run Forever
        if GPIO.input(40) == GPIO.HIGH:
                print("Button was pushed!") #prints to screen if button was pressed. Test input event only without need of output device
                subprocess.call("sudo python /home/pi/lightshowpi/py/synchronized_lights.py --playlist=/home/pi/lightshowpi/music/2021/.playlist", shell=True)
                subprocess.call("sudo python /home/pi/lightshowpi/py/hardware_controller.py --state=on", shell=True)

I have the enabled/disabled the button via crontab per the below code. So far the only way I've found to "disable" the button script is to call another script as an interupt. Alternatively I believe that in my setup I could alterturnativly use another relay and outlet to power off the button receiver.

#edit cron by running "sudo crontab -e" without quotes
#cron runs in root, all called scripts require full paths ie /home/pi/lightshowpi/py/hardware_controller.py

# Always put this at the top
SYNCHRONIZED_LIGHTS_HOME=/home/pi/lightshowpi

# Start microweb on boot
@reboot $SYNCHRONIZED_LIGHTS_HOME/bin/start_microweb

################################
#EXPLANATION
#
#Lights turn on at 430pm
#button is enabled at 500pm
#lights on script is called at 800pm to disable button
#lights turn off at 1030pm
#
################################
#test event
#turn lights on, start button.py
#@reboot sudo python $SYNCHRONIZED_LIGHTS_HOME/py/hardware_controller.py --state=on && sudo python /home/pi/lightshowpi/py/button.py &

# Evening Start
# Turn on the lights at 4:30pm
#30 16 * * * sudo python $SYNCHRONIZED_LIGHTS_HOME/py/hardware_controller.py --state=on

# ENABLE button at 5:00pm
# turn lights on
# enable button script
00 17 * * * sudo python $SYNCHRONIZED_LIGHTS_HOME/py/hardware_controller.py --state=on && sudo python /home/pi/lightshowpi/py/button.py &

# DISENABLE button at 8:00pm
00 20 * * * sudo python $SYNCHRONIZED_LIGHTS_HOME/py/hardware_controller.py --state=on

#End of Night
# Turn off the lights at 10:30pm
30 22 * * * sudo python $SYNCHRONIZED_LIGHTS_HOME/py/hardware_controller.py --state=off

Crude edit of the lightshowpi wiring diagram showing my config below. I have a small resistor in the wireless relay switch on GPIO 21.

wiring diagram