AI Newsletter Digest improvements: fixed QP soft line break decoding, URL extraction, and content cleaning
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"version": 1,
|
||||
"registry": "https://clawhub.ai",
|
||||
"slug": "mijia",
|
||||
"installedVersion": "0.1.0",
|
||||
"installedAt": 1772222803001
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
# Mijia Smart Home Control
|
||||
|
||||
A skill/plugin for AI coding agents to control Xiaomi Mijia smart home devices through natural language commands.
|
||||
|
||||

|
||||
|
||||
Works with:
|
||||
- [OpenClaw](https://openclaw.ai/) - Open source AI coding agent
|
||||
- [Claude Code](https://github.com/anthropics/claude-code)
|
||||
- [OpenCode](https://github.com/opencode-ai/opencode)
|
||||
- [Droid](https://github.com/anthropics/droid)
|
||||
- Other AI coding assistants that support custom skills/tools
|
||||
|
||||
## Features
|
||||
|
||||
- Control Xiaomi Mijia smart devices via natural language
|
||||
- Support for desk lamps, smart plugs, and other Mijia devices
|
||||
- Brightness and color temperature adjustment
|
||||
- Multiple lighting modes (reading, computer, night, etc.)
|
||||
- Easy to extend for additional device types
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Python 3.13+
|
||||
- [uv](https://github.com/astral-sh/uv) package manager
|
||||
- Xiaomi account with Mijia devices
|
||||
|
||||
## Installation
|
||||
|
||||
1. Clone this repository:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/user/mijia-skill.git
|
||||
cd mijia-skill
|
||||
```
|
||||
|
||||
2. Install dependencies:
|
||||
|
||||
```bash
|
||||
uv sync
|
||||
```
|
||||
|
||||
3. Configure your device ID:
|
||||
|
||||
```bash
|
||||
export MIJIA_LAMP_DID="your_device_id"
|
||||
```
|
||||
|
||||
4. First run will prompt for Xiaomi account login via QR code.
|
||||
|
||||
## Finding Your Device ID
|
||||
|
||||
Use the [mijia-api](https://github.com/Do1e/mijia-api) library to find your device IDs:
|
||||
|
||||
```python
|
||||
from mijiaAPI import mijiaAPI
|
||||
|
||||
api = mijiaAPI()
|
||||
api.login() # Scan QR code to login
|
||||
devices = api.get_device_list()
|
||||
for device in devices:
|
||||
print(f"{device['name']}: {device['did']}")
|
||||
```
|
||||
|
||||
## Environment Variables
|
||||
|
||||
| Variable | Description |
|
||||
|----------|-------------|
|
||||
| `MIJIA_LAMP_DID` | Device ID for the desk lamp |
|
||||
|
||||
## Usage
|
||||
|
||||
### CLI Commands
|
||||
|
||||
```bash
|
||||
# Check status
|
||||
uv run python scripts/lamp_cli.py status
|
||||
|
||||
# Power control
|
||||
uv run python scripts/lamp_cli.py on
|
||||
uv run python scripts/lamp_cli.py off
|
||||
uv run python scripts/lamp_cli.py toggle
|
||||
|
||||
# Brightness (1-100%)
|
||||
uv run python scripts/lamp_cli.py brightness 50
|
||||
|
||||
# Color temperature (2700-6500K)
|
||||
uv run python scripts/lamp_cli.py temp 4000
|
||||
|
||||
# Lighting modes
|
||||
uv run python scripts/lamp_cli.py mode reading # Reading mode
|
||||
uv run python scripts/lamp_cli.py mode computer # Computer mode
|
||||
uv run python scripts/lamp_cli.py mode night # Night reading
|
||||
uv run python scripts/lamp_cli.py mode antiblue # Anti-blue light
|
||||
uv run python scripts/lamp_cli.py mode work # Work mode
|
||||
uv run python scripts/lamp_cli.py mode candle # Candle effect
|
||||
uv run python scripts/lamp_cli.py mode twinkle # Twinkle alert
|
||||
```
|
||||
|
||||
### Natural Language Examples
|
||||
|
||||
Once integrated with your AI coding agent, you can use natural language:
|
||||
|
||||
- "Turn on the light" / "Turn off the light"
|
||||
- "Make it brighter" / "Make it dimmer"
|
||||
- "Set brightness to 80%"
|
||||
- "Switch to reading mode"
|
||||
- "Warm light please" / "Cool white light"
|
||||
- "What's the lamp status?"
|
||||
|
||||
## Integration
|
||||
|
||||
### Claude Code
|
||||
|
||||
Copy the skill to your Claude Code skills directory:
|
||||
|
||||
```bash
|
||||
cp -r . ~/.clawdbot/skills/mijia
|
||||
```
|
||||
|
||||
### Other AI Agents
|
||||
|
||||
Add the `SKILL.md` content to your agent's system prompt or tool configuration. The skill provides:
|
||||
- Device control commands
|
||||
- Natural language mapping table
|
||||
- Usage instructions
|
||||
|
||||
## Extending
|
||||
|
||||
You can extend this skill to support more device types. See `scripts/lamp_cli.py` for an example implementation.
|
||||
|
||||
The [mijia-api](https://github.com/Do1e/mijia-api) library supports:
|
||||
- Smart plugs
|
||||
- Air purifiers
|
||||
- Vacuum cleaners
|
||||
- Rice cookers
|
||||
- Door locks
|
||||
- And more Mijia devices
|
||||
|
||||
## Credits
|
||||
|
||||
Built on top of [mijia-api](https://github.com/Do1e/mijia-api) by Do1e.
|
||||
|
||||
## License
|
||||
|
||||
MIT License
|
||||
@@ -0,0 +1,100 @@
|
||||
---
|
||||
name: mijia
|
||||
description: Control Xiaomi Mijia smart home devices. Use this skill when the user wants to control desk lamps, smart plugs, or other Mijia devices. Supports turning lights on/off, adjusting brightness, setting color temperature, switching modes, and more.
|
||||
invocable: true
|
||||
---
|
||||
|
||||
# Mijia Smart Home Control
|
||||
|
||||
Control Xiaomi Mijia smart devices via the mijiaAPI.
|
||||
|
||||
## Setup
|
||||
|
||||
Before using this skill, you need to:
|
||||
|
||||
1. Install dependencies:
|
||||
```bash
|
||||
cd /path/to/mijia-skill
|
||||
uv sync
|
||||
```
|
||||
|
||||
2. Set your device ID as an environment variable:
|
||||
```bash
|
||||
export MIJIA_LAMP_DID="your_device_id"
|
||||
```
|
||||
|
||||
3. First run will prompt for Xiaomi account login via QR code.
|
||||
|
||||
## Finding Device IDs
|
||||
|
||||
To find your device IDs, use the mijia-api library:
|
||||
|
||||
```python
|
||||
from mijiaAPI import mijiaAPI
|
||||
api = mijiaAPI()
|
||||
api.login()
|
||||
devices = api.get_device_list()
|
||||
for d in devices:
|
||||
print(f"{d['name']}: {d['did']}")
|
||||
```
|
||||
|
||||
## How to Use
|
||||
|
||||
Skill path: `~/.clawdbot/skills/mijia`
|
||||
|
||||
### Lamp Control Commands
|
||||
|
||||
```bash
|
||||
# Navigate to skill directory
|
||||
cd ~/.claude/skills/mijia
|
||||
|
||||
# Check status
|
||||
uv run python scripts/lamp_cli.py status
|
||||
|
||||
# Turn on/off
|
||||
uv run python scripts/lamp_cli.py on
|
||||
uv run python scripts/lamp_cli.py off
|
||||
uv run python scripts/lamp_cli.py toggle
|
||||
|
||||
# Adjust brightness (1-100%)
|
||||
uv run python scripts/lamp_cli.py brightness 50
|
||||
|
||||
# Adjust color temperature (2700-6500K)
|
||||
uv run python scripts/lamp_cli.py temp 4000
|
||||
|
||||
# Set mode
|
||||
uv run python scripts/lamp_cli.py mode reading # Reading mode
|
||||
uv run python scripts/lamp_cli.py mode computer # Computer mode
|
||||
uv run python scripts/lamp_cli.py mode night # Night reading
|
||||
uv run python scripts/lamp_cli.py mode antiblue # Anti-blue light
|
||||
uv run python scripts/lamp_cli.py mode work # Work mode
|
||||
uv run python scripts/lamp_cli.py mode candle # Candle effect
|
||||
uv run python scripts/lamp_cli.py mode twinkle # Twinkle alert
|
||||
```
|
||||
|
||||
## Natural Language Understanding
|
||||
|
||||
When the user says the following, execute the corresponding command:
|
||||
|
||||
| User Says | Command |
|
||||
|-----------|---------|
|
||||
| Turn on the light / open lamp | `scripts/lamp_cli.py on` |
|
||||
| Turn off the light / close lamp | `scripts/lamp_cli.py off` |
|
||||
| Toggle the light | `scripts/lamp_cli.py toggle` |
|
||||
| Brighter / more bright | Check status first, then increase by 20-30% |
|
||||
| Dimmer / less bright | Check status first, then decrease by 20-30% |
|
||||
| Full brightness / maximum | `scripts/lamp_cli.py brightness 100` |
|
||||
| Minimum brightness | `scripts/lamp_cli.py brightness 1` |
|
||||
| Warm light | `scripts/lamp_cli.py temp 2700` |
|
||||
| Cool light / white light | `scripts/lamp_cli.py temp 6500` |
|
||||
| Reading mode | `scripts/lamp_cli.py mode reading` |
|
||||
| Computer mode | `scripts/lamp_cli.py mode computer` |
|
||||
| Night mode | `scripts/lamp_cli.py mode night` |
|
||||
| Lamp status / what's the light status | `scripts/lamp_cli.py status` |
|
||||
|
||||
## Before Executing
|
||||
|
||||
1. Navigate to skill directory: `cd ~/.clawdbot/skills/mijia`
|
||||
2. Ensure `MIJIA_LAMP_DID` environment variable is set
|
||||
3. Run with uv: `uv run python scripts/lamp_cli.py <command>`
|
||||
4. Report the result to the user after execution
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"ownerId": "kn7cpk0s04wpxzfp5m4eefgzj98024p8",
|
||||
"slug": "mijia",
|
||||
"version": "0.1.0",
|
||||
"publishedAt": 1769910345187
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
[project]
|
||||
name = "mijia-skill"
|
||||
version = "0.1.0"
|
||||
description = "Claude Code skill for controlling Xiaomi Mijia smart home devices"
|
||||
requires-python = ">=3.13"
|
||||
dependencies = [
|
||||
"mijiaapi>=3.0.5",
|
||||
]
|
||||
|
||||
[project.urls]
|
||||
Homepage = "https://github.com/user/mijia-skill"
|
||||
Repository = "https://github.com/user/mijia-skill"
|
||||
@@ -0,0 +1,151 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Desk lamp control CLI for Mijia devices."""
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
from mijiaAPI import mijiaAPI, mijiaDevice
|
||||
|
||||
# Get device ID from environment variable
|
||||
LAMP_DID = os.environ.get("MIJIA_LAMP_DID")
|
||||
|
||||
if not LAMP_DID:
|
||||
print("Error: MIJIA_LAMP_DID environment variable not set")
|
||||
print("Please set it with: export MIJIA_LAMP_DID='your_device_id'")
|
||||
sys.exit(1)
|
||||
|
||||
def get_lamp(api: mijiaAPI) -> mijiaDevice:
|
||||
"""Get the lamp device."""
|
||||
return mijiaDevice(api, did=LAMP_DID)
|
||||
|
||||
def cmd_on(args, api):
|
||||
"""Turn on the lamp."""
|
||||
lamp = get_lamp(api)
|
||||
lamp.on = True
|
||||
print("Lamp turned on")
|
||||
|
||||
def cmd_off(args, api):
|
||||
"""Turn off the lamp."""
|
||||
lamp = get_lamp(api)
|
||||
lamp.on = False
|
||||
print("Lamp turned off")
|
||||
|
||||
def cmd_toggle(args, api):
|
||||
"""Toggle lamp power."""
|
||||
lamp = get_lamp(api)
|
||||
lamp.run_action('toggle')
|
||||
print("Lamp toggled")
|
||||
|
||||
def cmd_status(args, api):
|
||||
"""Show lamp status."""
|
||||
lamp = get_lamp(api)
|
||||
on_status = lamp.get('on')
|
||||
brightness = lamp.get('brightness')
|
||||
color_temp = lamp.get('color-temperature')
|
||||
|
||||
status = "On" if on_status else "Off"
|
||||
print(f"Status: {status}")
|
||||
print(f"Brightness: {brightness}%")
|
||||
print(f"Color Temperature: {color_temp}K")
|
||||
|
||||
def cmd_brightness(args, api):
|
||||
"""Set brightness."""
|
||||
lamp = get_lamp(api)
|
||||
lamp.brightness = args.value
|
||||
print(f"Brightness set to {args.value}%")
|
||||
|
||||
def cmd_temp(args, api):
|
||||
"""Set color temperature."""
|
||||
lamp = get_lamp(api)
|
||||
lamp.color_temperature = args.value
|
||||
print(f"Color temperature set to {args.value}K")
|
||||
|
||||
def cmd_mode(args, api):
|
||||
"""Set lighting mode."""
|
||||
modes = {
|
||||
'reading': 0,
|
||||
'computer': 1,
|
||||
'night': 2,
|
||||
'antiblue': 3,
|
||||
'work': 4,
|
||||
'candle': 5,
|
||||
'twinkle': 6
|
||||
}
|
||||
mode_names = {
|
||||
0: 'Reading',
|
||||
1: 'Computer',
|
||||
2: 'Night Reading',
|
||||
3: 'Anti-blue Light',
|
||||
4: 'Work',
|
||||
5: 'Candle',
|
||||
6: 'Twinkle'
|
||||
}
|
||||
|
||||
if args.value in modes:
|
||||
mode_val = modes[args.value]
|
||||
else:
|
||||
try:
|
||||
mode_val = int(args.value)
|
||||
if mode_val not in mode_names:
|
||||
raise ValueError()
|
||||
except ValueError:
|
||||
print(f"Invalid mode: {args.value}")
|
||||
print("Available modes: reading, computer, night, antiblue, work, candle, twinkle (0-6)")
|
||||
sys.exit(1)
|
||||
|
||||
lamp = get_lamp(api)
|
||||
lamp.set('mode', mode_val)
|
||||
print(f"Mode set to {mode_names[mode_val]}")
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Desk Lamp Control CLI')
|
||||
subparsers = parser.add_subparsers(dest='command', help='Commands')
|
||||
|
||||
# on
|
||||
subparsers.add_parser('on', help='Turn on the lamp')
|
||||
|
||||
# off
|
||||
subparsers.add_parser('off', help='Turn off the lamp')
|
||||
|
||||
# toggle
|
||||
subparsers.add_parser('toggle', help='Toggle lamp power')
|
||||
|
||||
# status
|
||||
subparsers.add_parser('status', help='Show lamp status')
|
||||
|
||||
# brightness
|
||||
p_brightness = subparsers.add_parser('brightness', help='Set brightness (1-100)')
|
||||
p_brightness.add_argument('value', type=int, choices=range(1, 101), metavar='1-100', help='Brightness value')
|
||||
|
||||
# temp
|
||||
p_temp = subparsers.add_parser('temp', help='Set color temperature (2700-6500K)')
|
||||
p_temp.add_argument('value', type=int, help='Color temperature (2700-6500)')
|
||||
|
||||
# mode
|
||||
p_mode = subparsers.add_parser('mode', help='Set lighting mode')
|
||||
p_mode.add_argument('value', help='Mode: reading/computer/night/antiblue/work/candle/twinkle or 0-6')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if not args.command:
|
||||
parser.print_help()
|
||||
sys.exit(1)
|
||||
|
||||
# Initialize API
|
||||
api = mijiaAPI()
|
||||
api.login()
|
||||
|
||||
# Execute command
|
||||
cmd_map = {
|
||||
'on': cmd_on,
|
||||
'off': cmd_off,
|
||||
'toggle': cmd_toggle,
|
||||
'status': cmd_status,
|
||||
'brightness': cmd_brightness,
|
||||
'temp': cmd_temp,
|
||||
'mode': cmd_mode
|
||||
}
|
||||
|
||||
cmd_map[args.command](args, api)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user