Ich nutze einen Raspberry P5 mit Bookworm. Darauf läuft pihole, Magic Mirror und iobroker. Daran über HDMI angeschlossen ist ein Bildschirm welcher sich nur einschalten soll, wenn eine Bewegung erkannt wird und nach einer gewissen zeit wieder abschalten soll. Das ganze soll über die Deaktivierung des HDMI Signals passieren. Lange Zeit hatte ich das über den Magic Mirror und ein Modul gelöst. Da sich der Entwickler zurück gezogen hat und ich nach einer "stand alone" Lösung suche, wollte ich das per script lösen. Nach viel suchen und testen von scripten stoße ich an meine Grenzen. Ich bin Neuling in python und wollte euch daher um Hilfe bitten. Ich versuche mal so viele Informationen wie möglich hier zu schreiben:
die alte config datei mit eventuell Hinweisen (das Modul ist deaktiviert da es eh nicht mehr funktioniert):
Code: Alles auswählen
{
module: 'MMM-Pir',
position: 'top_center',
config: {
Display: {
timeout: 3 * 60 * 1000,
style: 4,
colorFrom: "#FF0000",
colorTo: "#00FF00",
mode: 3,
counter: true,
waylandDisplayName: "wayland-0",
lastPresence: false,
lastPresenceTimeFormat: "LL H:mm",
availability: true,
autoDimmer: false,
xrandrForceRotation: "normal",
wrandrForceMode: null,
relayGPIOPin: 0,
ddcutil: {
powerOnCode: "01",
powerOffCode: "04",
skipSetVcpCheck: false
}
},
Pir: {
mode: 0,
gpio: 23
},
},
},
Code: Alles auswählen
import RPi.GPIO as GPIO
import time
from threading import Timer
import subprocess
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN)
SHUTOFF_DELAY = 120 # in seconds, how long the monitor will be on until next button press or PIR detection
timer = False
monitor_is_on = True
def monitor_off():
global monitor_is_on
#subprocess.call("sh /home/pi/monitor_on.sh", shell=True)
monitor_is_on = False
def monitor_on():
global monitor_is_on
#subprocess.call("sh /home/pi/monitor_off.sh", shell=True)
#subprocess.call(['fbset -depth 8'], shell=True)
#subprocess.call(['fbset -depth 16'], shell=True)
#subprocess.call(['xrefresh'], shell=True)
monitor_is_on = True
while True:
time.sleep(1.0)
movement = GPIO.input(23)
if movement:
if timer:
print ("Monitor an")
timer.cancel()
timer = False
if not monitor_is_on:
print ("Monitor aus")
monitor_on()
else:
if not timer:
print ("start timer")
timer = Timer(1*1, monitor_off)
timer.start()

Inhalt der monitor_off.sh:
Code: Alles auswählen
wlr-randr --output HDMI-A-1 --off
Code: Alles auswählen
wlr-randr --output HDMI-A-1 --on
- Raspberry PI5 mit Bookworm
- Sensor - HC-SR501
- zum testen nutze ich Thonny und das terminal
Starte ich das script über das terminal kommt dann der Fehler:
Code: Alles auswählen
sudo python3 hdmi_1.py
start timer
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
failed to connect to display
Code: Alles auswählen
pi@raspberrypi:~ $ wlr-randr --output HDMI-A-1 --off
pi@raspberrypi:~ $ wlr-randr --output HDMI-A-1 --on
failed to apply configuration