Skip to main content
Glama
aldilaff
by aldilaff

wyze_turn_off_device

Turn off a Wyze smart light device using its MAC address to control lighting remotely through the MCP Wyze Server.

Instructions

Turn off a Wyze light device

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
device_macYes

Implementation Reference

  • The wyze_turn_off_device tool handler function, decorated with @mcp.tool() for registration in FastMCP. It authenticates with Wyze API, finds the device by MAC address, verifies it's a supported light type, and calls the Wyze SDK's bulbs.turn_off method.
    @mcp.tool()
    def wyze_turn_off_device(device_mac: str) -> Dict[str, str]:
        """Turn off a Wyze light device"""
        try:
            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.turn_off(device_mac=device_mac, device_model=device_model)
                    else:
                        return {"status": "error", "message": f"Device type '{device_type}' is not a supported light device"}
                    
                    return {"status": "success", "message": f"Device {device.nickname} turned off"}
            
            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 initialize and return the Wyze SDK Client instance using environment variables for authentication. Used by all Wyze tool handlers including wyze_turn_off_device.
    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