### Full Home Automation Script Example Source: https://context7.com/fishbigger/tapop100/llms.txt A comprehensive example demonstrating multiple device types and operations in a home automation scenario, including setup, control, and monitoring. ```python from PyP100 import PyP100, PyP110, PyL530 import time # Configuration TAPO_EMAIL = "your_email@example.com" TAPO_PASSWORD = "your_password" # Device IP addresses LIVING_ROOM_PLUG = "192.168.1.100" ENERGY_MONITOR = "192.168.1.101" BEDROOM_BULB = "192.168.1.102" def setup_device(device_class, ip): """Helper function to initialize and authenticate a device""" device = device_class(ip, TAPO_EMAIL, TAPO_PASSWORD) device.handshake() device.login() return device # Control living room plug plug = setup_device(PyP100.P100, LIVING_ROOM_PLUG) print(f"Living room plug: {plug.getDeviceName()}") plug.turnOn() # Monitor energy usage energy_plug = setup_device(PyP110.P110, ENERGY_MONITOR) energy_data = energy_plug.getEnergyUsage() current_power = energy_data["result"]["current_power"] / 1000 print(f"Current power consumption: {current_power}W") ``` -------------------------------- ### Full Home Automation Script Example Source: https://context7.com/fishbigger/tapop100/llms.txt A comprehensive example demonstrating the integration of multiple Tapo devices in a home automation script. ```APIDOC ## Full Home Automation Script ### Description This script demonstrates controlling a smart plug, monitoring energy usage, and interacting with a smart bulb within a home automation context. ### Request Example (Python) ```python from PyP100 import PyP100, PyP110, PyL530 import time # Configuration TAPO_EMAIL = "your_email@example.com" TAPO_PASSWORD = "your_password" # Device IP addresses LIVING_ROOM_PLUG = "192.168.1.100" ENERGY_MONITOR = "192.168.1.101" BEDROOM_BULB = "192.168.1.102" def setup_device(device_class, ip): """Helper function to initialize and authenticate a device""" device = device_class(ip, TAPO_EMAIL, TAPO_PASSWORD) device.handshake() device.login() return device # Control living room plug plug = setup_device(PyP100.P100, LIVING_ROOM_PLUG) print(f"Living room plug: {plug.getDeviceName()}") plug.turnOn() # Monitor energy usage energy_plug = setup_device(PyP110.P110, ENERGY_MONITOR) energy_data = energy_plug.getEnergyUsage() current_power = energy_data["result"]["current_power"] / 1000 print(f"Current power consumption: {current_power}W") # Control bedroom bulb (example: set to blue) # bulb = setup_device(PyL530.L530, BEDROOM_BULB) # bulb.setColor(240, 100) # Blue color # print("Bedroom bulb set to blue") # Example of scheduling turn off for the plug # plug.turnOffWithDelay(600) # Turn off in 10 minutes # print("Living room plug will turn off in 10 minutes") ``` ``` -------------------------------- ### Install PyP100 via pip Source: https://github.com/fishbigger/tapop100/blob/main/README.md Use the standard package manager to install the library. ```bash pip install PyP100 ``` -------------------------------- ### Get Energy Usage Data from P110 Source: https://context7.com/fishbigger/tapop100/llms.txt Retrieves energy usage data including current power draw, today's usage, and monthly statistics. The current power is returned in milliwatts. ```python from PyP100 import PyP110 p110 = PyP110.P110("192.168.1.101", "email@example.com", "password") p110.handshake() p110.login() # Get energy usage data energy = p110.getEnergyUsage() print(energy) # Example output: # { # "error_code": 0, # "result": { # "current_power": 15000, # Current power in milliwatts (15W) # "today_runtime": 720, # Runtime today in minutes # "month_runtime": 21600, # Runtime this month in minutes # "today_energy": 500, # Energy today in watt-hours # "month_energy": 15000, # Energy this month in watt-hours # ... # } # } # Calculate current power in watts current_watts = energy["result"]["current_power"] / 1000 print(f"Current power: {current_watts}W") ``` -------------------------------- ### Initialize and Connect to P100/P105 Source: https://context7.com/fishbigger/tapop100/llms.txt Establishes a secure connection to a smart plug. Handshake and login must be performed before executing commands. ```python from PyP100 import PyP100 # Initialize connection to smart plug ip_address = "192.168.1.100" email = "your_email@example.com" password = "your_password" p100 = PyP100.P100(ip_address, email, password) # Establish secure connection p100.handshake() p100.login() print("Connected to smart plug successfully!") ``` -------------------------------- ### Initialize and Connect to P110 Energy Monitoring Plug Source: https://context7.com/fishbigger/tapop100/llms.txt Initializes connection to a P110 energy monitoring plug. This class extends P100 with energy monitoring capabilities. ```python from PyP100 import PyP110 # Initialize connection to P110 energy monitoring plug p110 = PyP110.P110("192.168.1.101", "email@example.com", "password") p110.handshake() p110.login() print("Connected to P110 energy monitoring plug") ``` -------------------------------- ### Control Tapo Plugs Source: https://github.com/fishbigger/tapop100/blob/main/README.md Initialize a P100 plug object and perform authentication before executing power control or status commands. ```python from PyP100 import PyP100 p100 = PyP100.P100("192.168.X.X", "email@gmail.com", "Password123") #Creates a P100 plug object p100.handshake() #Creates the cookies required for further methods p100.login() #Sends credentials to the plug and creates AES Key and IV for further methods p100.turnOn() #Turns the connected plug on p100.turnOff() #Turns the connected plug off p100.toggleState() #Toggles the state of the connected plug p100.turnOnWithDelay(10) #Turns the connected plug on after 10 seconds p100.turnOffWithDelay(10) #Turns the connected plug off after 10 seconds p100.getDeviceInfo() #Returns dict with all the device info of the connected plug p100.getDeviceName() #Returns the name of the connected plug set in the app ``` -------------------------------- ### Initialize and Connect to L530/L510E Smart Bulb Source: https://context7.com/fishbigger/tapop100/llms.txt Initializes connection to a Tapo smart bulb (L530/L510E) for controlling color and brightness features. This class extends P100. ```python from PyP100 import PyL530 # Initialize connection to smart bulb bulb = PyL530.L530("192.168.1.102", "email@example.com", "password") bulb.handshake() bulb.login() print("Connected to smart bulb") ``` -------------------------------- ### Control Tapo Bulbs Source: https://github.com/fishbigger/tapop100/blob/main/README.md Initialize a bulb object to access standard power controls plus brightness, color temperature, and color settings. ```python from PyP100 import PyL530 l530 = PyL530.L530("192.168.X.X", "email@gmail.com", "Password123") l530.handshake() #Creates the cookies required for further methods l530.login() #Sends credentials to the plug and creates AES Key and IV for further methods #All the bulbs have the same basic functions as the plugs and additionally allow for the following functions. l530.setBrightness(50) #Sets the brightness of the connected bulb to 50% brightness l530.setColorTemp(2700) #Sets the color temperature of the connected bulb to 2700 Kelvin (Warm White) l530.setColor(30, 80) #Sets the color of the connected bulb to Hue: 30°, Saturation: 80% (Orange) ``` -------------------------------- ### Schedule Living Room Plug to Turn Off Source: https://context7.com/fishbigger/tapop100/llms.txt Schedule a living room plug to turn off after a specified delay in seconds. This is useful for automated power management. ```python plug.turnOffWithDelay(3600) print("Living room plug scheduled to turn off in 1 hour") ``` -------------------------------- ### Set Bedroom Bulb to Warm Dim Light Source: https://context7.com/fishbigger/tapop100/llms.txt Use this snippet to set the brightness and color temperature of a bedroom bulb. Ensure the bulb is properly set up and authenticated. ```python bulb = setup_device(PyL530.L530, BEDROOM_BULB) bulb.setBrightness(30) bulb.setColorTemp(2700) print("Bedroom bulb set to warm dim light") ``` -------------------------------- ### Monitor Energy Usage Source: https://github.com/fishbigger/tapop100/blob/main/README.md Use the P110 class to access energy monitoring data in addition to standard plug functionality. ```python from PyP100 import PyP110 p110 = PyP110.P110("192.168.X.X", "email@gmail.com", "Password123") p110.handshake() #Creates the cookies required for further methods p110.login() #Sends credentials to the plug and creates AES Key and IV for further methods #The P110 has all the same basic functions as the plugs and additionally allow for energy monitoring. p110.getEnergyUsage() #Returns dict with all of the energy usage of the connected plug ``` -------------------------------- ### Control Smart Plug Power State Source: https://context7.com/fishbigger/tapop100/llms.txt Methods for turning the plug on, off, or toggling its current state. ```python from PyP100 import PyP100 p100 = PyP100.P100("192.168.1.100", "email@example.com", "password") p100.handshake() p100.login() # Turn the plug on p100.turnOn() print("Device turned on") ``` ```python from PyP100 import PyP100 p100 = PyP100.P100("192.168.1.100", "email@example.com", "password") p100.handshake() p100.login() # Turn the plug off p100.turnOff() print("Device turned off") ``` ```python from PyP100 import PyP100 p100 = PyP100.P100("192.168.1.100", "email@example.com", "password") p100.handshake() p100.login() # Toggle the current state p100.toggleState() print("Device state toggled") ``` -------------------------------- ### getDeviceList Source: https://context7.com/fishbigger/tapop100/llms.txt Returns a list of all Tapo devices registered to the user's TP-Link account via the cloud API. ```APIDOC ## getDeviceList ### Description Returns a list of all Tapo devices registered to your TP-Link account via the cloud API. ### Parameters - **email** (string) - Required - Tapo account email - **password** (string) - Required - Tapo account password ### Response - **deviceList** (array) - List of registered devices including deviceId, deviceName, and deviceType ``` -------------------------------- ### Schedule Device Power Source: https://context7.com/fishbigger/tapop100/llms.txt Uses countdown rules to schedule power actions after a specified delay. ```python from PyP100 import PyP100 p100 = PyP100.P100("192.168.1.100", "email@example.com", "password") p100.handshake() p100.login() # Turn on after 60 seconds delay_seconds = 60 p100.turnOnWithDelay(delay_seconds) print(f"Device will turn on in {delay_seconds} seconds") ``` -------------------------------- ### Retrieve Device Information Source: https://context7.com/fishbigger/tapop100/llms.txt Fetches technical details or the human-readable name of the device. ```python from PyP100 import PyP100 p100 = PyP100.P100("192.168.1.100", "email@example.com", "password") p100.handshake() p100.login() # Get device information info = p100.getDeviceInfo() print(info) # Example output: # { # "error_code": 0, # "result": { # "device_id": "...", # "fw_ver": "1.0.0", # "hw_ver": "1.0", # "type": "SMART.TAPOPLUG", # "model": "P100", # "mac": "AA-BB-CC-DD-EE-FF", # "device_on": true, # "on_time": 12345, # "nickname": "TGl2aW5nIFJvb20=", # ... # } # } ``` ```python from PyP100 import PyP100 p100 = PyP100.P100("192.168.1.100", "email@example.com", "password") p100.handshake() p100.login() # Get the device name name = p100.getDeviceName() print(f"Device name: {name}") # Example output: Device name: Living Room Plug ``` -------------------------------- ### Set Smart Bulb Color Temperature Source: https://context7.com/fishbigger/tapop100/llms.txt Sets the color temperature of the bulb in Kelvin (typically 2500K-6500K range). Automatically turns on the bulb. ```python from PyP100 import PyL530 bulb = PyL530.L530("192.168.1.102", "email@example.com", "password") bulb.handshake() bulb.login() # Set warm white (2700K) bulb.setColorTemp(2700) print("Color temperature set to warm white") # Set cool daylight (6500K) bulb.setColorTemp(6500) print("Color temperature set to daylight") ``` -------------------------------- ### Adjust Smart Bulb Brightness Source: https://context7.com/fishbigger/tapop100/llms.txt Sets the bulb brightness level from 0-100. Automatically turns on the bulb if it's off. ```python from PyP100 import PyL530 bulb = PyL530.L530("192.168.1.102", "email@example.com", "password") bulb.handshake() bulb.login() # Set brightness to 75% bulb.setBrightness(75) print("Brightness set to 75%") # Dim to 25% bulb.setBrightness(25) print("Brightness set to 25%") ``` -------------------------------- ### P100 Device Control Source: https://context7.com/fishbigger/tapop100/llms.txt Basic control for Tapo smart plugs, including turning devices on/off and scheduling turn-off with a delay. ```APIDOC ## P100 Device Control ### Description Provides basic control for Tapo smart plugs. ### Methods - `turnOffWithDelay(delay_seconds)`: Schedules the device to turn off after a specified delay. ### Parameters #### `turnOffWithDelay` - **delay_seconds** (int) - Required - The delay in seconds before the device turns off. ### Request Example (Python) ```python from PyP100 import PyP100 p100 = PyP100.P100("192.168.1.100", "email@example.com", "password") p100.handshake() p100.login() # Turn off after 30 minutes (1800 seconds) delay_seconds = 1800 p100.turnOffWithDelay(delay_seconds) print(f"Device will turn off in {delay_seconds} seconds") ``` ``` -------------------------------- ### P110 Energy Monitoring Smart Plug Source: https://context7.com/fishbigger/tapop100/llms.txt Control and retrieve energy usage data from P110 smart plugs. ```APIDOC ## P110 Energy Monitoring Smart Plug ### Description Extends P100 functionality with energy monitoring capabilities. ### Methods - `getEnergyUsage()`: Retrieves energy usage data. ### Parameters #### `getEnergyUsage` No parameters required. ### Response (Success - 200) - **current_power** (int) - Current power consumption in milliwatts. - **today_runtime** (int) - Runtime today in minutes. - **month_runtime** (int) - Runtime this month in minutes. - **today_energy** (int) - Energy consumed today in watt-hours. - **month_energy** (int) - Energy consumed this month in watt-hours. ### Request Example (Python) ```python from PyP100 import PyP110 p110 = PyP110.P110("192.168.1.101", "email@example.com", "password") p110.handshake() p110.login() energy = p110.getEnergyUsage() print(energy) # Calculate current power in watts current_watts = energy["result"]["current_power"] / 1000 print(f"Current power: {current_watts}W") ``` ### Response Example ```json { "error_code": 0, "result": { "current_power": 15000, "today_runtime": 720, "month_runtime": 21600, "today_energy": 500, "month_energy": 15000 } } ``` ``` -------------------------------- ### P100 Smart Plug Control Source: https://context7.com/fishbigger/tapop100/llms.txt Methods for controlling P100/P105 smart plugs including power state management and device information retrieval. ```APIDOC ## P100 Smart Plug Methods ### Methods - **handshake()**: Establishes secure connection. - **login()**: Authenticates the session. - **turnOn()**: Turns the plug on. - **turnOff()**: Turns the plug off. - **toggleState()**: Toggles the current power state. - **getDeviceInfo()**: Retrieves detailed device status (model, MAC, firmware, state). - **getDeviceName()**: Returns the decoded device nickname. - **turnOnWithDelay(seconds)**: Schedules the device to turn on after a delay. ### Parameters - **ip_address** (string) - Required - Local IP of the device - **email** (string) - Required - Tapo account email - **password** (string) - Required - Tapo account password ``` -------------------------------- ### Retrieve Registered Devices Source: https://context7.com/fishbigger/tapop100/llms.txt Fetches a list of all Tapo devices linked to the provided account via the cloud API. ```python from PyP100.PyP100 import getDeviceList email = "your_email@example.com" password = "your_password" # Get all devices registered to your account devices = getDeviceList(email, password) print(devices) # Example output: # { # "error_code": 0, # "result": { # "deviceList": [ # {"deviceId": "...", "deviceName": "Living Room Plug", "deviceType": "SMART.TAPOPLUG", ...} # ] # } # } ``` -------------------------------- ### Authenticate with TP-Link Cloud Source: https://context7.com/fishbigger/tapop100/llms.txt Retrieves an authentication token using Tapo account credentials for cloud-based operations. ```python from PyP100.PyP100 import getToken # Authenticate with TP-Link cloud email = "your_email@example.com" password = "your_password" token = getToken(email, password) print(f"Authentication token: {token}") ``` -------------------------------- ### Schedule Turn Off with Delay Source: https://context7.com/fishbigger/tapop100/llms.txt Schedules the device to turn off after a specified delay in seconds. Useful for sleep timers or timed operations. ```python from PyP100 import PyP100 p100 = PyP100.P100("192.168.1.100", "email@example.com", "password") p100.handshake() p100.login() # Turn off after 30 minutes (1800 seconds) delay_seconds = 1800 p100.turnOffWithDelay(delay_seconds) print(f"Device will turn off in {delay_seconds} seconds") ``` -------------------------------- ### getToken Source: https://context7.com/fishbigger/tapop100/llms.txt Retrieves an authentication token from the TP-Link cloud service using Tapo account credentials. ```APIDOC ## getToken ### Description Retrieves an authentication token from the TP-Link cloud service using your Tapo account credentials. ### Parameters - **email** (string) - Required - Tapo account email - **password** (string) - Required - Tapo account password ### Response - **token** (string) - Authentication token for cloud-based operations ``` -------------------------------- ### L530 Color Smart Bulb Control Source: https://context7.com/fishbigger/tapop100/llms.txt Control Tapo smart bulbs (L530/L510E) for color, brightness, and color temperature adjustments. ```APIDOC ## L530 Color Smart Bulb Control ### Description Provides control for Tapo smart bulbs, including color, brightness, and color temperature settings. ### Methods - `setBrightness(brightness)`: Sets the bulb brightness level. - `setColorTemp(kelvin)`: Sets the color temperature in Kelvin. - `setColor(hue, saturation)`: Sets the bulb color using HSV values. ### Parameters #### `setBrightness` - **brightness** (int) - Required - Brightness level from 0 to 100. #### `setColorTemp` - **kelvin** (int) - Required - Color temperature in Kelvin (e.g., 2500-6500). #### `setColor` - **hue** (int) - Required - Hue value from 0 to 360. - **saturation** (int) - Required - Saturation value from 0 to 100. ### Request Example (Python) ```python from PyP100 import PyL530 bulb = PyL530.L530("192.168.1.102", "email@example.com", "password") bulb.handshake() bulb.login() # Set brightness to 75% bulb.setBrightness(75) print("Brightness set to 75%") # Set warm white (2700K) bulb.setColorTemp(2700) print("Color temperature set to warm white") # Set red color (hue=0, saturation=100) bulb.setColor(0, 100) print("Color set to red") ``` ``` -------------------------------- ### Set Smart Bulb HSV Color Source: https://context7.com/fishbigger/tapop100/llms.txt Sets the bulb color using hue (0-360) and saturation (0-100) values. Automatically turns on the bulb and sets color temperature to 0 for accurate color display. ```python from PyP100 import PyL530 bulb = PyL530.L530("192.168.1.102", "email@example.com", "password") bulb.handshake() bulb.login() # Set red color (hue=0, saturation=100) bulb.setColor(0, 100) print("Color set to red") # Set blue color (hue=240, saturation=100) bulb.setColor(240, 100) print("Color set to blue") # Set green color (hue=120, saturation=100) bulb.setColor(120, 100) print("Color set to green") # Set purple color (hue=280, saturation=80) bulb.setColor(280, 80) print("Color set to purple") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.