Skip to main content
Glama
aldilaff
by aldilaff

wyze_set_brightness

Adjust Wyze smart light brightness levels from 0 to 100 percent using device MAC address for precise lighting control.

Instructions

Set brightness for a Wyze light (0-100)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
device_macYes
brightnessYes

Implementation Reference

  • The core handler function for the 'wyze_set_brightness' tool, decorated with @mcp.tool() for automatic registration. Validates input brightness (0-100), retrieves Wyze client, finds device by MAC, confirms light type support, and executes brightness adjustment via wyze-sdk's bulbs.set_brightness method. Handles various errors gracefully.
    @mcp.tool()
    def wyze_set_brightness(device_mac: str, brightness: int) -> Dict[str, str]:
        """Set brightness for a Wyze light (0-100)"""
        try:
            if not 0 <= brightness <= 100:
                return {"status": "error", "message": "Brightness must be between 0 and 100"}
            
            client = get_wyze_client()
            devices = client.devices_list()
            
            for device in devices:
                if device.mac == device_mac:
                    # Get device type - try multiple approaches
                    device_type = (getattr(device, 'product_type', None) or 
                                  getattr(device, 'type', None) or
                                  (hasattr(device, 'product') and getattr(device.product, 'type', None)) or
                                  'Unknown')
                    
                    device_model = (getattr(device, 'product_model', None) or
                                   getattr(device, 'model', None) or
                                   (hasattr(device, 'product') and getattr(device.product, 'model', None)) or
                                   'Unknown')
                    
                    if device_type in ['Light', 'Bulb', 'MeshLight', 'LightStrip']:
                        client.bulbs.set_brightness(
                            device_mac=device_mac, 
                            device_model=device_model, 
                            brightness=brightness
                        )
                        return {"status": "success", "message": f"Set {device.nickname} brightness to {brightness}%"}
                    else:
                        return {"status": "error", "message": f"Device {device.nickname} does not support brightness control"}
            
            return {"status": "error", "message": f"Device with MAC {device_mac} not found"}
        except WyzeClientConfigurationError as e:
            return {"status": "error", "message": f"Configuration error: {str(e)}"}
        except WyzeRequestError as e:
            return {"status": "error", "message": f"API error: {str(e)}"}
        except Exception as e:
            return {"status": "error", "message": f"Unexpected error: {str(e)}"}
  • Helper function to lazily initialize and retrieve the global Wyze SDK Client instance, using environment variables for authentication. Essential for all Wyze API calls in the tools.
    def get_wyze_client() -> Client:
        """Get or create Wyze client instance with auto-login if credentials available"""
        global _wyze_client
        
        if _wyze_client is None:
            # Get credentials from environment
            email = os.getenv("WYZE_EMAIL")
            password = os.getenv("WYZE_PASSWORD")
            key_id = os.getenv("WYZE_KEY_ID")
            api_key = os.getenv("WYZE_API_KEY")
            
            if not all([email, password, key_id, api_key]):
                raise WyzeClientConfigurationError(
                    "Missing required environment variables: WYZE_EMAIL, WYZE_PASSWORD, WYZE_KEY_ID, WYZE_API_KEY"
                )
            
            _wyze_client = Client(
                email=email,
                password=password,
                key_id=key_id,
                api_key=api_key
            )
        
        return _wyze_client

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aldilaff/mcp-wyze-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server