CommentStreams:349c3b14b8ade3fe3331b162fd247b6a
OK so I got pretty close by modifying the included pld.py script. I can get it to shutdown when on battery with a delay. However, it will execute the second the pi is on battery. I would rather it be on battery for say 10 seconds so random power drops don't shut it down. Any idea on how to implement this?
- !/usr/bin/env python3
- This python script is only suitable for UPS Shield X1200, X1201 and X1202
import gpiod import time from subprocess import call
PLD_PIN = 6 chip = gpiod.Chip('gpiochip4') pld_line = chip.get_line(PLD_PIN) pld_line.request(consumer="PLD", type=gpiod.LINE_REQ_DIR_IN) try:
while True:
pld_state = pld_line.get_value()
if pld_state == 1:
pass
else:
time.sleep(1)
call("sudo nohup shutdown -h now", shell=True) #uncomment to implement shutdown when power outage
finally:
pld_line.release()