### Implement Home Automation with Sensibo Source: https://context7.com/andrey-git/pysensibo/llms.txt A comprehensive example showing how to fetch device data, monitor conditions, and adjust AC states based on temperature thresholds. ```python import asyncio import aiohttp from pysensibo import SensiboClient from pysensibo.exceptions import SensiboError, AuthenticationError async def home_automation_example(): """Complete home automation example using pysensibo.""" api_key = "your_api_key" async with aiohttp.ClientSession() as session: client = SensiboClient(api_key, session) try: # 1. Get all devices and their data data = await client.async_get_devices_data() for uid, device in data.parsed.items(): print(f"\n{'='*50}") print(f"Processing: {device.name} ({device.model})") print(f"{'='*50}") # Skip unavailable devices if not device.available: print(f" Device offline, skipping...") continue # 2. Check current conditions print(f" Current temp: {device.temp}°{device.temp_unit}") print(f" Current humidity: {device.humidity}%") print(f" HVAC state: {device.state}") print(f" Device on: {device.device_on}") # 3. Auto-adjust based on temperature if device.temp and device.temp > 28: print(f" Hot! Turning on cooling...") await client.async_set_ac_state_property( uid=uid, name="on", value=True, ac_state=device.ac_states ) await client.async_set_ac_state_property( uid=uid, name="mode", value="cool", ac_state=device.ac_states ) await client.async_set_ac_state_property( uid=uid, name="targetTemperature", value=24, ac_state=device.ac_states ) elif device.temp and device.temp < 18: print(f" Cold! Turning on heating...") await client.async_set_ac_state_property( uid=uid, name="on", value=True, ac_state=device.ac_states ) await client.async_set_ac_state_property( uid=uid, name="mode", value="heat", ac_state=device.ac_states ) # 4. Check filter status if device.filter_clean: print(f" WARNING: Filter needs cleaning!") # 5. Check for firmware updates if device.update_available: print(f" Update available: {device.fw_ver} -> {device.fw_ver_available}") # 6. List active schedules if device.schedules: print(f" Active schedules:") for sched_id, schedule in device.schedules.items(): status = "enabled" if schedule.enabled else "disabled" print(f" - {schedule.name}: {schedule.time} ({status})") except AuthenticationError: print("Invalid API key!") except SensiboError as e: print(f"API error: {e}") # Run the automation asyncio.run(home_automation_example()) ``` -------------------------------- ### Get User Information Source: https://context7.com/andrey-git/pysensibo/llms.txt Retrieve user account details using the async_get_me method. Requires an initialized SensiboClient. ```python async def get_user_info(client: SensiboClient): user_info = await client.async_get_me() print(f"User info: {user_info}") # Returns: {'status': 'success', 'result': {'id': 'user_id', 'email': 'user@email.com', ...}} # Example usage async with aiohttp.ClientSession() as session: client = SensiboClient("your_api_key", session) await get_user_info(client) ``` -------------------------------- ### Get All Devices (Raw Data) Source: https://context7.com/andrey-git/pysensibo/llms.txt Fetch raw device data from the Sensibo API. Supports filtering specific fields for efficiency. ```python async def get_raw_devices(client: SensiboClient): # Get all fields all_devices = await client.async_get_devices(fields="*") # Get specific fields only minimal_devices = await client.async_get_devices( fields="id,room,acState,measurements" ) for device in all_devices.get("result", []): print(f"Device ID: {device['id']}") print(f"Room: {device['room']['name']}") print(f"Temperature: {device['measurements'].get('temperature')}°") ``` -------------------------------- ### GET /devices/{uid} Source: https://context7.com/andrey-git/pysensibo/llms.txt Retrieve data for a specific Sensibo device by its unique ID. ```APIDOC ## GET /devices/{uid} ### Description Retrieve data for a specific device by its unique ID using the async_get_device method. ### Method GET ### Endpoint /devices/{uid} ### Parameters #### Path Parameters - **uid** (string) - Required - The unique identifier of the device. #### Query Parameters - **fields** (string) - Optional - Comma-separated list of fields to retrieve (e.g., "*" or "id,acState,measurements"). ### Response #### Success Response (200) - **result** (object) - The device data object containing room, measurements, and AC state information. ``` -------------------------------- ### Get Parsed Device Data with Dataclasses Source: https://context7.com/andrey-git/pysensibo/llms.txt Retrieve device data using strongly-typed dataclasses for easy access to device properties. Handles potential API and authentication errors. ```python from pysensibo import SensiboClient, SensiboData, SensiboDevice from pysensibo.exceptions import SensiboError, AuthenticationError async def get_devices_data(client: SensiboClient) -> SensiboData: try: data: SensiboData = await client.async_get_devices_data() # Access raw API response print(f"Raw response: {data.raw}") # Access parsed devices for device_id, device in data.parsed.items(): print(f"\n=== {device.name} ===") print(f" ID: {device.id}") print(f" MAC: {device.mac}") print(f" Model: {device.model}") print(f" Firmware: {device.fw_ver}") print(f" Available: {device.available}") print(f" Temperature: {device.temp}°{device.temp_unit}") print(f" Humidity: {device.humidity}%") print(f" Feels Like: {device.feelslike}°") print(f" HVAC Mode: {device.hvac_mode}") print(f" Device On: {device.device_on}") print(f" Target Temp: {device.target_temp}°") print(f" Fan Mode: {device.fan_mode}") print(f" Swing Mode: {device.swing_mode}") print(f" Available HVAC Modes: {device.hvac_modes}") print(f" Available Fan Modes: {device.fan_modes}") print(f" Update Available: {device.update_available}") # Air quality sensors (AirQ/Element models) if device.tvoc is not None: print(f" TVOC: {device.tvoc}") if device.co2 is not None: print(f" CO2: {device.co2}") if device.pm25 is not None: print(f" PM2.5: {device.pm25}") return data except AuthenticationError: print("Invalid API key") raise except SensiboError as e: print(f"API error: {e}") raise ``` -------------------------------- ### Robust API Call with Error Handling Source: https://context7.com/andrey-git/pysensibo/llms.txt Handle API errors and authentication failures gracefully using Pysensibo's exception classes. This example demonstrates try-except blocks for AuthenticationError, SensiboError, and general exceptions. ```python from pysensibo import SensiboClient from pysensibo.exceptions import SensiboError, AuthenticationError async def robust_api_call(api_key: str): async with aiohttp.ClientSession() as session: client = SensiboClient(api_key, session) try: data = await client.async_get_devices_data() return data except AuthenticationError: # Invalid API key (HTTP 401 or 403) print("ERROR: Invalid API key. Get your key from https://home.sensibo.com/me/api") raise except SensiboError as e: # General API error (non-200 response or JSON parsing error) print(f"ERROR: API call failed: {e}") raise except Exception as e: # Network error, timeout, etc. (library auto-retries 3 times) print(f"ERROR: Network or unexpected error: {e}") raise ``` -------------------------------- ### Initialize SensiboClient Source: https://context7.com/andrey-git/pysensibo/llms.txt Initialize the SensiboClient with your API key. It's recommended to reuse an aiohttp ClientSession for efficiency. An optional timeout can be specified. ```python import asyncio import aiohttp from pysensibo import SensiboClient async def main(): # Create client with existing session (recommended for connection reuse) async with aiohttp.ClientSession() as session: client = SensiboClient( api_key="your_api_key_from_home.sensibo.com/me/api", session=session, timeout=300 # Optional: timeout in seconds (default: 5 minutes) ) # Or create client without session (creates its own) client_standalone = SensiboClient(api_key="your_api_key") # Use client for API calls devices = await client.async_get_devices_data() print(f"Found {len(devices.parsed)} devices") asyncio.run(main()) ``` -------------------------------- ### Configure Pure Device Settings Source: https://context7.com/andrey-git/pysensibo/llms.txt Configure Pure Boost settings for Sensibo Pure air purifier devices. Ensure the device is of 'pure' model before configuring. ```python async def configure_pure_device(client: SensiboClient, device_uid: str): # Get device to check if it's a Pure data = await client.async_get_devices_data() device = data.parsed[device_uid] if device.model == "pure": print(f"Pure Boost Enabled: {device.pure_boost_enabled}") print(f"Pure Sensitivity: {device.pure_sensitivity}") print(f"Air Quality (PM2.5 AQI): {device.pm25_pure}") # PureAQI enum # Configure Pure Boost pure_config = { "enabled": True, "sensitivity": "m", # n=normal, l=low, m=medium, h=high "ac_integration": True, "geo_integration": False, "measurements_integration": True, "prime_integration": False } await client.async_set_pureboost(uid=device_uid, data=pure_config) print("Pure Boost configured") ``` -------------------------------- ### Retrieve Device Data with Python Source: https://context7.com/andrey-git/pysensibo/llms.txt Fetches device information using async_get_device. Supports retrieving all fields or a specific subset. ```python async def get_single_device(client: SensiboClient, device_uid: str): # Get all fields for specific device device = await client.async_get_device(uid=device_uid, fields="*") # Get specific fields only device_minimal = await client.async_get_device( uid=device_uid, fields="id,acState,measurements" ) result = device.get("result", {}) print(f"Device: {result.get('room', {}).get('name')}") print(f"Temperature: {result.get('measurements', {}).get('temperature')}") return device # Usage device_uid = "ABC123xyz" # Your device UID await get_single_device(client, device_uid) ``` -------------------------------- ### Manage Climate React Settings with Python Source: https://context7.com/andrey-git/pysensibo/llms.txt Configures and toggles Climate React smart mode using dedicated async methods. ```python async def manage_climate_react(client: SensiboClient, device_uid: str): # Get current Climate React settings climate_react = await client.async_get_climate_react(uid=device_uid) print(f"Current Climate React: {climate_react}") # Configure Climate React climate_react_config = { "enabled": True, "type": "temperature", # or "feelsLike" "lowTemperatureThreshold": 18, "highTemperatureThreshold": 26, "lowTemperatureState": { "on": True, "mode": "heat", "targetTemperature": 22, "fanLevel": "auto", "swing": "stopped" }, "highTemperatureState": { "on": True, "mode": "cool", "targetTemperature": 24, "fanLevel": "auto", "swing": "rangeFull" } } # Set Climate React configuration await client.async_set_climate_react(uid=device_uid, data=climate_react_config) print("Climate React configured") # Enable Climate React await client.async_enable_climate_react(uid=device_uid, data={"enabled": True}) print("Climate React enabled") # Disable Climate React await client.async_enable_climate_react(uid=device_uid, data={"enabled": False}) print("Climate React disabled") ``` -------------------------------- ### POST /devices/{uid}/acStates Source: https://context7.com/andrey-git/pysensibo/llms.txt Set the complete AC state for a device, replacing all properties at once. ```APIDOC ## POST /devices/{uid}/acStates ### Description Set the complete AC state for a device using async_set_ac_states. This replaces all AC state properties at once. ### Method POST ### Endpoint /devices/{uid}/acStates ### Parameters #### Path Parameters - **uid** (string) - Required - The unique identifier of the device. #### Request Body - **ac_state** (object) - Required - The complete AC state object including on, mode, targetTemperature, temperatureUnit, fanLevel, and swing. ### Response #### Success Response (200) - **status** (string) - Status of the request. - **result** (object) - Contains the updated acState and changedProperties. ``` -------------------------------- ### Climate React API Source: https://context7.com/andrey-git/pysensibo/llms.txt Manage Climate React smart mode settings including thresholds and state configurations. ```APIDOC ## GET/POST /devices/{uid}/climateReact ### Description Get, set, and enable/disable Climate React settings for automatic temperature adjustment. ### Method GET, POST ### Endpoint /devices/{uid}/climateReact ### Parameters #### Path Parameters - **uid** (string) - Required - The unique identifier of the device. #### Request Body - **data** (object) - Required - Configuration object including enabled, type, temperature thresholds, and associated AC states. ``` -------------------------------- ### Set Full AC State with Python Source: https://context7.com/andrey-git/pysensibo/llms.txt Updates the complete AC state using async_set_ac_states. This operation replaces all existing AC state properties. ```python async def set_full_ac_state(client: SensiboClient, device_uid: str): # Define complete AC state ac_state = { "on": True, "mode": "cool", "targetTemperature": 24, "temperatureUnit": "C", "fanLevel": "medium", "swing": "rangeFull" } result = await client.async_set_ac_states(uid=device_uid, ac_state=ac_state) print(f"AC state updated: {result}") # Returns: {'status': 'success', 'result': {'acState': {...}, 'changedProperties': [...]}} # Turn off the AC off_state = { "on": False, "mode": "cool", "targetTemperature": 24, "temperatureUnit": "C", "fanLevel": "medium", "swing": "rangeFull" } await client.async_set_ac_states(uid=device_uid, ac_state=off_state) ``` -------------------------------- ### Calibrate Sensors Source: https://context7.com/andrey-git/pysensibo/llms.txt Adjust temperature and humidity offsets to improve reading accuracy. ```python async def calibrate_sensors(client: SensiboClient, device_uid: str): # Calibrate temperature (offset in degrees) await client.async_set_calibration( uid=device_uid, data={"temperature": -1.5} # Reduce reported temp by 1.5 degrees ) print("Temperature calibration set") # Calibrate humidity (offset in percentage) await client.async_set_calibration( uid=device_uid, data={"humidity": 5.0} # Increase reported humidity by 5% ) print("Humidity calibration set") # Calibrate both at once await client.async_set_calibration( uid=device_uid, data={ "temperature": 0.5, "humidity": -2.0 } ) print("Both calibrations set") ``` -------------------------------- ### Manage AC Timers Source: https://context7.com/andrey-git/pysensibo/llms.txt Use these methods to retrieve, create, and remove one-time timers for AC state changes. ```python from datetime import datetime, timedelta async def manage_timer(client: SensiboClient, device_uid: str): # Get current timer timer = await client.async_get_timer(uid=device_uid) print(f"Current timer: {timer}") # Set a timer to turn off AC in 2 hours target_time = datetime.utcnow() + timedelta(hours=2) timer_data = { "minutesFromNow": 120, "acState": { "on": False, "mode": "cool", "targetTemperature": 24, "temperatureUnit": "C", "fanLevel": "auto" } } result = await client.async_set_timer(uid=device_uid, data=timer_data) print(f"Timer set: {result}") # Delete the timer await client.async_del_timer(uid=device_uid) print("Timer deleted") ``` -------------------------------- ### Read Motion Sensor Data Source: https://context7.com/andrey-git/pysensibo/llms.txt Access motion sensor data from Sensibo Sky Plus devices. This includes checking room occupancy and individual sensor details like temperature, humidity, and battery status. ```python async def read_motion_sensors(client: SensiboClient, device_uid: str): data = await client.async_get_devices_data() device = data.parsed[device_uid] # Check room occupancy (if motion sensors present) print(f"Room Occupied: {device.room_occupied}") # Access individual motion sensors if device.motion_sensors: for sensor_id, sensor in device.motion_sensors.items(): print(f"\n=== Motion Sensor: {sensor_id} ===") print(f" Model: {sensor.model}") print(f" Alive: {sensor.alive}") print(f" Motion Detected: {sensor.motion}") print(f" Temperature: {sensor.temperature} °") print(f" Humidity: {sensor.humidity} %") print(f" Battery Voltage: {sensor.battery_voltage}") print(f" RSSI: {sensor.rssi}") print(f" Is Main Sensor: {sensor.is_main_sensor}") print(f" Firmware: {sensor.fw_ver} ({sensor.fw_type})") ``` -------------------------------- ### Update Single AC Property with Python Source: https://context7.com/andrey-git/pysensibo/llms.txt Modifies individual AC settings using async_set_ac_state_property while maintaining current state context. ```python async def set_single_property(client: SensiboClient, device_uid: str): # First get current state data = await client.async_get_devices_data() device = data.parsed[device_uid] current_state = device.ac_states # Turn on the AC result = await client.async_set_ac_state_property( uid=device_uid, name="on", value=True, ac_state=current_state ) print(f"Turned on: {result}") # Change temperature await client.async_set_ac_state_property( uid=device_uid, name="targetTemperature", value=22, ac_state=current_state ) # Change fan level await client.async_set_ac_state_property( uid=device_uid, name="fanLevel", value="high", ac_state=current_state ) # Change mode await client.async_set_ac_state_property( uid=device_uid, name="mode", value="heat", ac_state=current_state ) # Set with assumed state (for state correction) await client.async_set_ac_state_property( uid=device_uid, name="on", value=False, ac_state=current_state, assumed_state=True # Adds "StateCorrectionByUser" reason ) ``` -------------------------------- ### Manage AC Schedules Source: https://context7.com/andrey-git/pysensibo/llms.txt Methods for handling recurring schedules, including creation, retrieval, toggling enabled status, and deletion. ```python async def manage_schedules(client: SensiboClient, device_uid: str): # Get all schedules schedules = await client.async_get_schedules(uid=device_uid) print(f"All schedules: {schedules}") # Create a new schedule - turn on AC at 8:00 AM on weekdays new_schedule = { "targetTimeLocal": "08:00", "recurringDays": ["monday", "tuesday", "wednesday", "thursday", "friday"], "acState": { "on": True, "mode": "cool", "targetTemperature": 24, "temperatureUnit": "C", "fanLevel": "auto", "swing": "rangeFull" } } result = await client.async_set_schedule(uid=device_uid, data=new_schedule) schedule_id = result.get("result", {}).get("id") print(f"Schedule created with ID: {schedule_id}") # Get specific schedule schedule = await client.async_get_schedule(uid=device_uid, schedule_id=schedule_id) print(f"Schedule details: {schedule}") # Disable the schedule await client.async_enable_schedule( uid=device_uid, schedule_id=schedule_id, data={"isEnabled": False} ) print("Schedule disabled") # Re-enable the schedule await client.async_enable_schedule( uid=device_uid, schedule_id=schedule_id, data={"isEnabled": True} ) print("Schedule enabled") # Delete the schedule await client.async_del_schedule(uid=device_uid, schedule_id=schedule_id) print("Schedule deleted") ``` -------------------------------- ### PATCH /devices/{uid}/acState/{property} Source: https://context7.com/andrey-git/pysensibo/llms.txt Update a single AC property while preserving other existing settings. ```APIDOC ## PATCH /devices/{uid}/acState/{property} ### Description Change a single AC property while preserving other settings using async_set_ac_state_property. ### Method PATCH ### Endpoint /devices/{uid}/acState/{property} ### Parameters #### Path Parameters - **uid** (string) - Required - The unique identifier of the device. #### Request Body - **name** (string) - Required - The property name to change. - **value** (any) - Required - The new value for the property. - **ac_state** (object) - Required - The current state of the AC. - **assumed_state** (boolean) - Optional - If true, adds 'StateCorrectionByUser' reason. ``` -------------------------------- ### Reset Filter Notification Source: https://context7.com/andrey-git/pysensibo/llms.txt Check filter status and reset the notification after maintenance. ```python async def reset_filter(client: SensiboClient, device_uid: str): # Check if filter needs cleaning from device data data = await client.async_get_devices_data() device = data.parsed[device_uid] if device.filter_clean: print(f"Filter needs cleaning! Last reset: {device.filter_last_reset}") # Reset the filter notification result = await client.async_reset_filter(uid=device_uid) print(f"Filter reset: {result}") else: print("Filter is clean") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.