If i run python3 motionsensor.py it works but if i run it through a systemd service it gives this error:
Dec 06 16:36:05 raspberrypi python3[2244]: pygame 2.1.2 (SDL 2.26.5, Python 3.11.2)
Dec 06 16:36:05 raspberrypi python3[2244]: Hello from the pygame community.
https://www.pygame.org/contribute.html
Dec 06 16:36:05 raspberrypi python3[2244]: Traceback (most recent call last):
Dec 06 16:36:05 raspberrypi python3[2244]: File "/home/yoni/scripts/motionsensor.py", line 22, in <module>
Dec 06 16:36:05 raspberrypi python3[2244]: pygame.mixer.init()
Dec 06 16:36:05 raspberrypi python3[2244]: pygame.error: ALSA: Couldn't open audio device: Unknown error 524
this is my systemdfile:
[Unit]
Description=Motion Detector Service
After=network.target apache2.service
[Service]
ExecStart=/usr/bin/python3 /home/yoni/scripts/motionsensor.py
WorkingDirectory=/home/yoni/scripts
StandardOutput=inherit
StandardError=inherit
Restart=always
User=yoni
SendSIGHUP = no
[Install]
WantedBy=multi-user.target
thank you in advance!