L900-Color Sync (Screen Sync in Real Time)

L900-Color Sync (Screen Sync in Real Time)

L900-Color Sync (Screen Sync in Real Time)
L900-Color Sync (Screen Sync in Real Time)
a week ago - last edited a week ago
Model: Tapo L900-5  
Hardware Version:
Firmware Version:

TP Link Screen Sync The provided Python script controls a TP-Link Tapo L900-5 smart light strip, dynamically adjusting its color and brightness based on the average color of the user's screen. It also includes a GUI for manual brightness control and toggling the device on/off. Below is a detailed description of its functionality:

Device Discovery (discover_tapo_l900): Scans the local network to find the Tapo L900-5 device Uses the ApiClient from the tapo library to authenticate with the device using provided email and password credentials. Returns the IP address of the discovered device or None if no device is found after retries.

 

 

Color Extraction and Processing (get_average_screen_color, get_weighted_avg_color, apply_gamma_correction): Captures the screen using the mss library and resizes the image to 150x150 pixels for performance. Computes a weighted average color from the screen, prioritizing brighter pixels (using a power factor of 1.8). Applies gamma correction (gamma = 1.6) to enhance color vibrancy. Converts the average RGB color to HSV, boosts saturation (by 1.5x, capped at 1.0), and adjusts brightness based on the user-set level (minimum 60, maximum 100). Returns hue (0-360), saturation (10-100), and brightness (60-100) for the light strip. Smooth Color Transitions (lerp, update_colors): Uses linear interpolation (lerp) to smoothly transition between the current and target hue, saturation, and brightness values. Handles hue wrap-around (e.g., from 359° to 0°) to ensure the shortest path for color changes. Applies a smoothing factor of 0.2 for gradual transitions, updated at 120Hz (every ~8.33ms).

 

 

Device Control (set_tapo_color, _toggle_device): Sets the light strip’s color using the Tapo API, applying the calculated hue, saturation, and brightness if the device is on. Toggles the device on or off via the API based on user input from the GUI. Graphical User Interface (create_gui, update_brightness, toggle_device, on_closing): Creates a Tkinter GUI with a brightness slider (1-100%) and a toggle button to turn the light strip on or off. Updates the button text dynamically to reflect the device’s state. Handles window closure by turning off the device and exiting the program. Runs in a separate thread to avoid blocking the main async loop.

Main Loop (main): Initializes the asyncio event loop and discovers the Tapo L900-5 device. Authenticates with the device using the ApiClient and turns it on. Continuously captures the screen’s average color, updates the light strip with smoothed color values, and refreshes at 120Hz. Handles errors by turning off the device and logging the issue. Program Execution (run_gui, if name == "main"): Starts the GUI in a separate daemon thread. Runs the main async loop to control the light strip.

Overall Purpose: The script creates an ambient lighting system where the Tapo L900-5 light strip mirrors the average color of the user’s screen with vibrant, smoothly transitioning colors. The GUI allows manual control over brightness and power state, while the script ensures efficient network discovery and responsive updates.

  0      
  0      
#1
Options
1 Accepted Solution
Re:L900-Color Sync (Screen Sync in Real Time)-Solution
a week ago - last edited a week ago

  @DK1100i Note: Use the Credentials used to Register the Device

Recommended Solution
  0  
  0  
#3
Options
1 Reply
Re:L900-Color Sync (Screen Sync in Real Time)-Solution
a week ago - last edited a week ago

  @DK1100i Note: Use the Credentials used to Register the Device

Recommended Solution
  0  
  0  
#3
Options

Information

Helpful: 0

Views: 127

Replies: 1