Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1234

Python • UPS Shutdown Python Script

$
0
0
Hello,

I have a X1200 UPS for my Raspberry Pi 5 and can get it to shut off once on battery power. I would like, however, for it to only do so after being on the battery for a set amount of time, say 10 seconds. Can anyone give me some help on how to integrate that into my script?

Link to UPS website: https://wiki.geekworm.com/X1200

Code:

#!/usr/bin/env python3#This python script is only suitable for UPS Shield X1200, X1201 and X1202import gpiodimport timefrom subprocess import callPLD_PIN = 6chip = 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 outagefinally: pld_line.release()

Statistics: Posted by DocServo — Tue Jun 11, 2024 9:28 pm



Viewing all articles
Browse latest Browse all 1234

Trending Articles