I was making a battery notifier script for my raspberry pi3. The script is executing when I do
/usr/bin/python /home/pi/Documents/shutdown.py
and showing the popup notifications. However the service is not executing it or not showing the notification. I can see the python process if I do sudo systemctl status battery-notifier.service.
battery-notifer.service
[Unit]
Description=Battery Notifier
[Service]
Type=simple
WorkingDirectory=/home/pi/Documents
ExecStart=/usr/bin/python /home/pi/Documents/shutdown.py
[Install]
WantedBy=multi-user.target
shutdown.py
import raspiupshat
import statistics
import subprocess
from time import sleep
raspiupshat.init()
while(True):
voltagesList = []
sleep(0.5)
currentVoltage = raspiupshat.getv()
voltagesList.append(currentVoltage)
medianVoltage = statistics.median(voltagesList)
if(medianVoltage>4):
subprocess.Popen(["notify-send","Battery Full!"])
This is the status of the service when I do sudo systemctl status battery-notifier.service:
● battery-notifier.service - Battery Notifier
Loaded: loaded (/lib/systemd/system/battery-notifier.service; enabled)
Active: active (running) since Sat 2017-07-15 04:05:18 UTC; 48min ago
Main PID: 28384 (python)
CGroup: /system.slice/battery-notifier.service
└─28384 /usr/bin/python /home/pi/Documents/shutdown.py
Jul 15 04:05:18 raspberrypi systemd[1]: Started Battery Notifier.