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:01] – [Chromium Start] 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 36: Line 37:
   * UI Tools \\ ''sudo apt update && sudo apt upgrade -y && sudo apt install -y flameshot terminator cutecom jstest-gtk xclip''   * UI Tools \\ ''sudo apt update && sudo apt upgrade -y && sudo apt install -y flameshot terminator cutecom jstest-gtk xclip''
   * Nutzloses Zeug \\ ''sudo apt autoremove -y modem* cups* avahi* triggerhappy* rpi-connect openvpn xscreensaver''   * Nutzloses Zeug \\ ''sudo apt autoremove -y modem* cups* avahi* triggerhappy* rpi-connect openvpn xscreensaver''
 +
 +===== ser2net =====
 +  * Der Zigbee Stick hängt am Display über USB. Damit der in HA genutzt werden kann nutzen wir ser2net. 
 +  * -> https://www.drklipper.de/doku.php?id=haussteuerung:zigbee2mqtt
 +
  
 ===== Browser ===== ===== Browser =====
Line 120: Line 126:
 </code> </code>
   * ''sudo systemctl enable x11vnc.service''   * ''sudo systemctl enable x11vnc.service''
-==== Display ==== 
  
-  * Venv einrichten  +===== Fullscreen ===== 
-    ''sudo apt -y update && sudo apt-get install -y build-essential cmake make gcc pkg-config python3-dev python3-virtualenv libsystemd-dev libopenblas-dev'' +  für Fullscreen Kontroller brauchen wir die HA Integration "Browser Mod" (Installieren über HACS) \\ https://github.com/thomasloven/hass-browser_mod 
-    ''cd ~ && mkdir -p DisplayOnOff && cd DisplayOnOff '' +  auf dem Endgerät dann die Seite öffnen \\ http://192.168.30.28:8123/browser-mod 
-    * ''python -m venv . && source bin/activate'' +    * Register aktivieren  
-    * ''pip3 install %%--%%upgrade pip && pip3 install RPi.GPIO pynput smbus paho-mqtt psutil'' +    * sinnvollen Namen in Browser ID eingeben ''WZ_Display_10Zoll'' 
-  * Compile VL53 Lib ...  +  * Jetzt sollte der Browser als Device in HA auftauchen  
-    ''sudo apt-get install build-essential python-dev'' +  Wir brauchen BroiwserMod um JavaScript auszuführen um Fullscreen Toggel hinzubekommen 
-    * ''cd ~'' +  Das Ausblenden von HA Elementen passiert mit ''kiosk-mode'' \\ https://github.com/NemesisRE/kiosk-mode 
-    * ''git clone https://github.com/pimoroni/VL53L0X_rasp_python.git'' +  * Konfig vom kiosk-mode passiert im YAML Modus des Dashboards! \\ <code> 
-    * ''cd VL53L0X-python'' +kiosk_mode: 
-    * ''make'' +  user_settings: 
-    * VL53L0X.py in den Scriptordner kopieren ...  +    - users: 
-  * Tests starten ...  +        - wohnzimmer 
- +      hide_sidebar: true 
-==== Tests ==== +      hide_header: false 
-=== VL === +      hide_assistant: true 
- +</code> Das muss am Anfang ergänzt werdenDamit wird für den User ''wohnzimmer'' die Sidebar und der Assistant abgeschaltet.  
- +  * Den Fullscreen Button kann man so erstellen:  
-   +    * Button mit Interaktion -> Aktion ausführen -> javascript 
- +    * Target Browser auswählen -> WZ Display (dafür braucht man browser_mod) 
-===== Motion Detect ===== +    * Code : <code javascript> 
-  * Sensor : VL53L0X +  if (!document.fullscreenElement) { 
- +    document.documentElement.requestFullscreen(); 
-  * Altes Script \\ <code Motiondetect.py>import sys+  } else { 
 +    document.exitFullscreen(); 
 +  } 
 +</code> 
 +===== Display On / Off ===== 
 +Das Display kann über den GPIO Pin 36 vom Raspberry Pi an- und abgeschaltet werden. Das geht über ein einfaches toggeln. Am Ende macht das Python Script (gestartet als Service) aber noch einiges mehr... <code python> 
 +import RPi.GPIO as GPIO
 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 178: 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 +
-        #os.system('DISPLAY=:0 xdotool key "shift"'+
-        ###subprocess.call("DISPLAY=:0 xset s reset", shell=True) +
-        #subprocess.call("DISPLAY=:0 xset dpms force on", shell=True) +
-        #subprocess.call("DISPLAY=:0 xset dpms 120 120 120", shell=True)+
  
-    time.sleep(0.1) +==== Service ==== 
- +  * Aktivieren \\ ''sudo systemctl enable display.service'' \\ ''sudo systemctl daemon-reload'' \\ ''sudo systemctl start display.service'' 
-tof.stop_ranging() +  * Log ansehen \\ ''journalctl -u display.service -f'' 
-tof.close() +  * ''sudo nano /lib/systemd/system/display.service'' \\ <code display.service>
-</code> +
-  * Service \\ <code display.service+
-pi@SHome-Display-VPN-DNS:$ cat lib/systemd/system/display.service+
 [Unit] [Unit]
-Description=Display Controller +Description=Smart Display Controller (venv/User Mode) 
- +# Wir warten, bis das Netzwerk und die Grafikoberfläche da sind 
 +After=network-online.target graphical.target 
 +Wants=network-online.target 
 [Service] [Service]
 +# --- User Context ---
 +User=pi
 +Group=pi
 +
 +# --- Arbeitsverzeichnis ---
 +# Setzt das Verzeichnis, damit relative Pfade funktionieren
 +WorkingDirectory=/home/pi/DisplayHA
 +
 +# --- Environment ---
 +# Diese Variablen sind wichtig für DDC/CI oder xrandr Interaktionen
 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.1766811677.txt.gz · Last modified: by dominik

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki