fibaro_control_rgb_light
Control RGB lights with one command, including on/off, color, and brightness settings. Simplifies management of smart lighting through the Fibaro HC3 MCP Server.
Instructions
Complete control for RGB lights: turn on/off, set color, and brightness in one command. Use this when user wants to control multiple aspects of an RGB light at once (e.g., "turn on light 5 red color at 50% brightness").
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Turn light on or off | |
| brightness | No | Brightness level (0-100), optional | |
| color_name | No | Color name (e.g., "red", "green", "blue", "xanh lá", "tím") | |
| id | Yes | Device ID |
Implementation Reference
- src/index.ts:506-547 (handler)The main execution handler for the fibaro_control_rgb_light tool. Handles turning the light on/off, setting color from name using getColorRGB helper, and adjusting brightness, composing results from multiple client calls.case 'fibaro_control_rgb_light': { if (!this.fibaroClient) { throw new Error('Not connected to Fibaro HC3. Please check your configuration and restart the MCP server.'); } const deviceId = args?.id as number; const action = args?.action as string; const colorName = args?.color_name as string; const brightness = args?.brightness as number; const results = []; // First, turn on/off the light if (action === 'on') { await this.fibaroClient.turnOnDevice(deviceId); results.push(`Turned on device ${deviceId}`); } else if (action === 'off') { await this.fibaroClient.turnOffDevice(deviceId); results.push(`Turned off device ${deviceId}`); } // Set color if specified if (colorName && action === 'on') { const rgb = getColorRGB(colorName); await this.fibaroClient.setColor(deviceId, rgb.r, rgb.g, rgb.b, 0); results.push(`Set color to ${colorName} RGB(${rgb.r},${rgb.g},${rgb.b})`); } // Set brightness if specified if (brightness !== undefined && action === 'on') { await this.fibaroClient.setBrightness(deviceId, brightness); results.push(`Set brightness to ${brightness}%`); } return { content: [ { type: 'text', text: `Device ${deviceId}: ${results.join(', ')}`, }, ], }; }
- src/index.ts:272-300 (registration)Tool registration in the listTools response, including name, description, and input schema definition.{ name: 'fibaro_control_rgb_light', description: 'Complete control for RGB lights: turn on/off, set color, and brightness in one command. Use this when user wants to control multiple aspects of an RGB light at once (e.g., "turn on light 5 red color at 50% brightness").', inputSchema: { type: 'object', properties: { id: { type: 'number', description: 'Device ID', }, action: { type: 'string', enum: ['on', 'off'], description: 'Turn light on or off', }, color_name: { type: 'string', description: 'Color name (e.g., "red", "green", "blue", "xanh lá", "tím")', }, brightness: { type: 'number', description: 'Brightness level (0-100), optional', minimum: 0, maximum: 100, }, }, required: ['id', 'action'], }, },
- src/index.ts:272-300 (schema)Input schema for validating parameters: id (required), action (on/off required), color_name (optional), brightness (optional).{ name: 'fibaro_control_rgb_light', description: 'Complete control for RGB lights: turn on/off, set color, and brightness in one command. Use this when user wants to control multiple aspects of an RGB light at once (e.g., "turn on light 5 red color at 50% brightness").', inputSchema: { type: 'object', properties: { id: { type: 'number', description: 'Device ID', }, action: { type: 'string', enum: ['on', 'off'], description: 'Turn light on or off', }, color_name: { type: 'string', description: 'Color name (e.g., "red", "green", "blue", "xanh lá", "tím")', }, brightness: { type: 'number', description: 'Brightness level (0-100), optional', minimum: 0, maximum: 100, }, }, required: ['id', 'action'], }, },
- src/index.ts:12-41 (helper)Helper function that maps color names (English and Vietnamese) to RGB values, used exclusively in the fibaro_control_rgb_light handler.function getColorRGB(colorName: string): { r: number; g: number; b: number } { const colors: { [key: string]: { r: number; g: number; b: number } } = { 'red': { r: 255, g: 0, b: 0 }, 'green': { r: 0, g: 255, b: 0 }, 'blue': { r: 0, g: 0, b: 255 }, 'yellow': { r: 255, g: 255, b: 0 }, 'purple': { r: 128, g: 0, b: 128 }, 'pink': { r: 255, g: 192, b: 203 }, 'orange': { r: 255, g: 165, b: 0 }, 'cyan': { r: 0, g: 255, b: 255 }, 'magenta': { r: 255, g: 0, b: 255 }, 'white': { r: 255, g: 255, b: 255 }, 'black': { r: 0, g: 0, b: 0 }, 'lime': { r: 50, g: 205, b: 50 }, 'violet': { r: 238, g: 130, b: 238 }, // Vietnamese color names 'đỏ': { r: 255, g: 0, b: 0 }, 'xanh lá': { r: 0, g: 255, b: 0 }, 'xanh dương': { r: 0, g: 0, b: 255 }, 'vàng': { r: 255, g: 255, b: 0 }, 'tím': { r: 128, g: 0, b: 128 }, 'hồng': { r: 255, g: 192, b: 203 }, 'cam': { r: 255, g: 165, b: 0 }, 'trắng': { r: 255, g: 255, b: 255 }, 'đen': { r: 0, g: 0, b: 0 } }; const normalizedName = colorName.toLowerCase().trim(); return colors[normalizedName] || { r: 255, g: 255, b: 255 }; // default to white }