Control lights, outlets, scenes, and other IKEA smart home devices through the Dirigera hub.
pip install dirigera
Check the router/DHCP client list for "Dirigera" and note its IP address.
If the agent is on the same LAN, try the IP discovery script. It can:
generate-token against candidates (interactive).python scripts/find_dirigera_ip.py
# or
python scripts/find_dirigera_ip.py --subnet 192.168.1.0/24
# verify with token (if you have it)
python scripts/find_dirigera_ip.py --token <dirigera-token>
# last resort: try generate-token against candidates
python scripts/find_dirigera_ip.py --try-generate-token
IMPORTANT: Token generation REQUIRES PHYSICAL USER ACTION. Follow this workflow:
Run the wrapper script in the background. It will automatically wait for the button press:
python scripts/generate_token_wrapper.py <dirigera-ip-address> &
The token will be saved to dirigera_token.txt by default. To specify a custom location:
python scripts/generate_token_wrapper.py <dirigera-ip-address> --output /path/to/token.txt &
CRITICAL: After starting the script, you MUST:
The user will:
The script will automatically detect the button press and save the token to the file.
After the user confirms, read the token from the file:
from pathlib import Path
token = Path("dirigera_token.txt").read_text().strip()
Or from a custom location:
TOKEN=$(cat /path/to/token.txt)
Then use the token to connect:
import dirigera
hub = dirigera.Hub(token=token, ip_address="<dirigera-ip>")
For manual use (not recommended for agents):
generate-token <dirigera-ip-address>
This requires interactive terminal access and doesn't save output automatically.
If you cannot find the hub IP address:
generate-token against them until one succeeds.python scripts/find_dirigera_ip.py --token .python scripts/find_dirigera_ip.py --try-generate-token and follow the prompt.import dirigera
hub = dirigera.Hub(
token="token",
ip_address="ip_address"
)
Device state is in .attributes, not top-level.
# CORRECT
light.attributes.is_on
light.attributes.light_level
# WRONG - raises AttributeError
light.is_on
light.light_level
Top-level: device.id, device.is_reachable, device.room
State: device.attributes.is_on, device.attributes.light_level
lights = hub.get_lights()
outlets = hub.get_outlets()
controllers = hub.get_controllers()
scenes = hub.get_scenes()
light = hub.get_light_by_name(lamp_name="bedroom light")
# Check reachability first
if light.is_reachable:
light.set_light(lamp_on=True)
light.set_light_level(light_level=75)
light.set_color_temperature(color_temp=2700) # Warm white
# Reload after changes
light.reload()
outlet = hub.get_outlet_by_name(outlet_name="living room")
outlet.set_on(outlet_on=True)
outlet.reload()
scene = hub.get_scene_by_name(scene_name="Sove tid")
scene.trigger()
# Verify device supports feature before using
if 'colorTemperature' in light.capabilities.can_receive:
light.set_color_temperature(color_temp=3000)
See references/patterns.md for room-based control, batch operations, status reports, and battery monitoring.
Use scripts/helpers.py for common operations: get lights by room, check battery levels, find unreachable devices.
See references/api.md for:
device.is_reachable before controldevice.reload() after control commands.attributes for all state access共 1 个版本