User Tools

Site Tools


haussteuerung:display_panel

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
haussteuerung:display_panel [2025/12/27 06:48] – [Updates] dominikhaussteuerung:display_panel [2025/12/27 08:11] (current) – [Service] dominik
Line 9: Line 9:
   * '' sudo raspi-config''   * '' sudo raspi-config''
     * I2C Aktivieren      * I2C Aktivieren 
 +    * 1Wire aktivieren
     * umstellen von Wayland auf X11     * umstellen von Wayland auf X11
     * Screen Blanking aus !     * Screen Blanking aus !
Line 153: Line 154:
   }   }
 </code> </code>
-==== Display ==== +===== Display On / Off ===== 
- +Das Display kann über den GPIO Pin 36 vom Raspberry Pi anund abgeschaltet werdenDas geht über ein einfaches toggelnAm Ende macht das Python Script (gestartet als Service) aber noch einiges mehr... <code python> 
-  * Venv einrichten  +import RPi.GPIO as GPIO
-    * ''sudo apt -y update && sudo apt-get install -y build-essential cmake make gcc pkg-config python3-dev python3-virtualenv libsystemd-dev libopenblas-dev'' +
-    * ''cd ~ && mkdir -p DisplayOnOff && cd DisplayOnOff '' +
-    * ''python -m venv . && source bin/activate'' +
-    * ''pip3 install %%--%%upgrade pip && pip3 install RPi.GPIO pynput smbus paho-mqtt psutil'' +
-  * Compile VL53 Lib ...  +
-    * ''sudo apt-get install build-essential python-dev'' +
-    * ''cd ~'' +
-    * ''git clone https://github.com/pimoroni/VL53L0X_rasp_python.git'' +
-    * ''cd VL53L0X-python'' +
-    * ''make'' +
-    * VL53L0X.py in den Scriptordner kopieren ...  +
-  * Tests starten ...  +
- +
-==== Tests ==== +
-=== VL === +
- +
- +
-   +
- +
-===== Motion Detect ===== +
-  * Sensor : VL53L0X +
- +
-  * Altes Script \\ <code Motiondetect.py>import sys+
 import time import time
-import VL53L0X 
-import os 
-import subprocess 
-import RPi.GPIO as GPIO 
-from pynput import mouse 
  
-def on_move(x, y): +# GPIO-Setup (BOARD-Modus für physische Pin-Nummern
-    global Display_Last_Action +GPIO.setmode(GPIO.BOARD
-    print('Pointer moved to {0}'.format((x, y))) +GPIO.setwarnings(False)
-    sys.stdout.flush(+
-    Display_Last_Action = time.time(+
-    print("Time %d" % (Display_Last_Action))+
  
-def on_click(x, y, button, pressed): +# Pin 36 (GPIO 16für Display ON/OFF 
-    global Display_Last_Action +GPIO.setup(36GPIO.OUT)
-    print('{0} at {1}'.format('Pressed' if pressed else 'Released'(x, y))) +
-    sys.stdout.flush() +
-    Display_Last_Action = time.time() +
-    print("Time %d" % (Display_Last_Action)) +
- +
-def on_scroll(x, y, dx, dy): +
-    global Display_Last_Action +
-    print('Scrolled {0} at {1}'.format('down' if dy < 0 else 'up', (x, y))) +
-    sys.stdout.flush() +
-    Display_Last_Action = time.time() +
-    print("Time %d" % (Display_Last_Action))+
  
 def toggleOnOff(): def toggleOnOff():
Line 211: Line 170:
     time.sleep(0.4)     time.sleep(0.4)
     GPIO.output(36, GPIO.LOW)     GPIO.output(36, GPIO.LOW)
-    print("Toggle Switch ...."+    print("Display toggled!")
-    sys.stdout.flush() +
-   +
-listener = mouse.Listener( +
-    on_move=on_move, +
-    on_click=on_click, +
-    on_scroll=on_scroll) +
-listener.start()+
  
-Last Time Event happend on Display  +Toggle ausführen 
-Display_Last_Action = time.time() +toggleOnOff() 
-Display_State       = True +</code>
-Display_Timeout_Sec = 180+
  
-# RPi.GPIO Layout verwenden (wie Pin-Nummern) +==== Funktionen ==== 
-GPIO.setmode(GPIO.BOARD) +  * Display an / aus 
-# RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(Falseto disable warnings. +  * Raspberry in HA mittels Autodiscover anmelden  
-GPIO.setwarnings(False)+  * Schalten des Displays über HA 
 +  * Melden von Bewegung an HA (MQTT
 +  * einfaches Systemn Monitoring (vor allem Temperatur)
  
-# Pin 36 (GPIO 16) auf Output setzen -> Display ON / OFF +==== Venv einrichten ==== 
-GPIO.setup(36, GPIO.OUT) +  * ''sudo apt -y update && sudo apt-get install -y build-essential cmake make gcc pkg-config python3-dev python3-virtualenv libsystemd-dev libopenblas-dev python3-setuptools'' 
-# Pin 38 (GPIO 20) auf Output setzen -> Brightness + +  * ''cd ~ && mkdir -p DisplayHA && cd DisplayHA'' 
-GPIO.setup(38, GPIO.OUT) +  * ''python -m venv && source bin/activate'' 
-# Pin 40 (GPIO 21) auf Output setzen -> Brightness - +  * ''pip3 install %%--%%upgrade pip && pip3 install RPi.GPIO pynput smbus paho-mqtt psutil setuptools''
-GPIO.setup(40, GPIO.OUT)+
  
-# Create a VL53L0X object +  * Compile VL53 Lib ...  
-tof = VL53L0X.VL53L0X(i2c_bus=1,i2c_address=0x29) +    * ''sudo apt-get install build-essential python-dev'' 
-tof.open() +    * ''cd ~ && git clone https://github.com/pimoroni/VL53L0X_rasp_python.git && cd VL53L0X_rasp_python'' 
-tof.start_ranging(VL53L0X.Vl53l0xAccuracyMode.BETTER)+    * ''pip install .'' 
 +    * VL53L0X.py in den Scriptordner kopieren ... \\ ''cp ~/VL53L0X_rasp_python/python/VL53L0X.py ~/DisplayHA/'' 
 +  * Tests starten ..
  
-while 1: 
-    # Distanz vom VL53L0X Sensor messen 
-    distance = tof.get_distance() 
-    #print("%d mm, %d cm" % (distance, (distance/10))) 
  
-    # Display ggf. abschalten  
-    if time.time()-Display_Last_Action >= Display_Timeout_Sec: 
-        if Display_State == True: 
-            #subprocess.call("DISPLAY=:0 xset dpms force off", shell=True) 
-            toggleOnOff() 
-            Display_State = False 
-            print("Display wird abgeschaltet ...") 
-            sys.stdout.flush() 
  
-    # Abstand vom Sensor pruefen +  
-    if distance < 900: +
-        print("DETECTED, %d cm , %d sec" % (distance/10, time.time()-Display_Last_Action )) +
-        sys.stdout.flush() +
-        Display_Last_Action = time.time() +
-        print("Time %d" % (Display_Last_Action))+
  
-    # Display ggf. wieder einschalten  +===== Motion Detect ===== 
-    if time.time()-Display_Last_Action < Display_Timeout_Sec: +  * Sensor : VL53L0X
-        if Display_State == False: +
-            #subprocess.call("DISPLAY=:0 xset dpms force on", shell=True) +
-            toggleOnOff() +
-            Display_State True +
-            print("Display wird eingeschaltet ..."+
-            sys.stdout.flush()+
  
-        # Display Einschalten +==== Service ==== 
-        #os.system('DISPLAY=:0 xdotool key "shift"') +  * Aktivieren \\ ''sudo systemctl enable display.service'' \\ ''sudo systemctl daemon-reload'' \\ ''sudo systemctl start display.service'' 
-        ###subprocess.call("DISPLAY=:0 xset s reset", shell=True) +  * Log ansehen \\ ''journalctl -u display.service -f'' 
-        #subprocess.call("DISPLAY=:0 xset dpms force on", shell=True+  * ''sudo nano /lib/systemd/system/display.service'' \\ <code display.service> 
-        #subprocess.call("DISPLAY=:0 xset dpms 120 120 120"shell=True)+[Unit] 
 +Description=Smart Display Controller (venv/User Mode
 +Wir wartenbis das Netzwerk und die Grafikoberfläche da sind 
 +After=network-online.target graphical.target 
 +Wants=network-online.target
  
-    time.sleep(0.1)+[Service] 
 +# --- User Context --- 
 +User=pi 
 +Group=pi
  
-tof.stop_ranging() +# --- Arbeitsverzeichnis --- 
-tof.close() +# Setzt das Verzeichnis, damit relative Pfade funktionieren 
-</code> +WorkingDirectory=/home/pi/DisplayHA 
-  * Service \\ <code display.service> + 
-pi@SHome-Display-VPN-DNS:/ $ cat lib/systemd/system/display.service +# --- Environment --- 
-[Unit] +# Diese Variablen sind wichtig für DDC/CI oder xrandr Interaktionen
-Description=Display Controller +
-  +
-[Service]+
 Environment=DISPLAY=:0 Environment=DISPLAY=:0
 Environment=XAUTHORITY=/home/pi/.Xauthority Environment=XAUTHORITY=/home/pi/.Xauthority
-ExecStart=/usr/bin/python /home/pi/DisplayOn/MotionDetect.py+# Erzwingt unbuffered Output, damit Logs sofort im Journal erscheinen 
 +Environment=PYTHONUNBUFFERED=1 
 + 
 +# --- ExecStart: Der Trick für das venv --- 
 +# Statt 'source bin/activate' rufen wir direkt das Python im venv auf. 
 +# PASSE DEN PFAD ZUM VENV AN, falls dein Ordner anders heißt (z.B. .venv)! 
 +ExecStart=/home/pi/DisplayHA/bin/python /home/pi/DisplayHA/SmartDisplay.py 
 + 
 +# --- Restart Verhalten ---
 Restart=always Restart=always
-RestartSec=30s +RestartSec=10s 
-KillMode=process +
-TimeoutSec=infinity +
- +
 [Install] [Install]
 WantedBy=graphical.target WantedBy=graphical.target
- 
 </code> </code>
  
haussteuerung/display_panel.1766814494.txt.gz · Last modified: by dominik

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki