10-18-2019, 02:55 PM
(10-18-2019, 12:04 PM)skrimo Wrote: relay.py script
import RPi.GPIO as GPIO import time channel = 26 # GPIO setup GPIO.setmode(GPIO.BCM) GPIO.setup(channel, GPIO.OUT) def motor_on(pin): GPIO.output(pin, GPIO.HIGH) # Turn fan on def motor_off(pin): GPIO.output(pin, GPIO.LOW) # Turn fan off if __name__ == '__main__': try: motor_on(channel) except KeyboardInterrupt: GPIO.cleanup()
switch.sh script
#!/bin/bash #this is the GPIO pin used for monitoring ACC state GPIOpin1=23 #this has NOTHING to do with 3 relay system GPIOpin2=24 #Enter the shutdown delay in minutes delay=58 echo "$GPIOpin1" > /sys/class/gpio/export echo "in" > /sys/class/gpio/gpio$GPIOpin1/direction echo "$GPIOpin2" > /sys/class/gpio/export echo "out" > /sys/class/gpio/gpio$GPIOpin2/direction echo "1" > /sys/class/gpio/gpio$GPIOpin2/value let minute=$delay*60 SD=0 SS=0 SS2=0 while [ 1 = 1 ]; do power=$(cat /sys/class/gpio/gpio$GPIOpin1/value) uptime=$(</proc/uptime) uptime=${uptime%%.*} current=$uptime if [ $power = 1 ] && [ $SD = 0 ] then SD=1 && kodi-send --action="pause" sleep 10 echo 1 > /sys/class/backlight/rpi_backlight/bl_power SS=${uptime%%.*} fi if [ $power = 1 ] && [ $SD = 1 ] then SS2=${uptime%%.*} fi if [ "$((uptime - SS))" -gt "$minute" ] && [ $SD = 1 ] && [ $power = 1 ] then poweroff SD=3 fi if [ "$((uptime - SS2))" -gt 1 ] && [ $SD = 1 ] then SD=0 && echo 0 > /sys/class/backlight/rpi_backlight/bl_power kodi-send --action="play" fi sleep 1 done
this works great for my setup:
- Raspberry pi3b+ before and Raspberry pi4b now
- Official 7" touchscreen
Thanks Skirmo, I really preciate it. I am pretty new to RBP projects, could you guide me a little on how to install the scripts? Im sorry for bothering you so much recently. :/