webproject-xyz/ikea-tradfri-php-api

PHP library to control ikea tradfri hub

Installs: 46

Dependents: 0

Suggesters: 0

Security: 0

Stars: 10

Watchers: 1

Forks: 2

Open Issues: 7

pkg:composer/webproject-xyz/ikea-tradfri-php-api

4.1.5 2026-02-16 22:15 UTC

README

Codacy Badge QA Codacy Badge codecov Latest Stable Version License

A powerful and easy-to-use PHP library to control your IKEA Tradfri smart lights through the Gateway.

Inspired by hvanderlaan/ikea-smartlight (Python).

🚀 Quick Start

1. Requirements

  • PHP 8.3 or higher
  • coap-client (can be run via Docker)
  • IKEA Tradfri Gateway

2. Initial Setup

To communicate with the gateway, you need to generate a security key. The easiest way is using our Docker Coap-Client:

# Pull the client
docker pull webproject/coap-client:latest

# Generate your API User and Shared Key
docker run --rm --name coap-client webproject/coap-client 
  -m post 
  -u "Client_identity" 
  -k "<COAP_GATEWAY_SECRET>" 
  -e '{"9090":"php-api-user"}' 
  "coaps://<COAP_GATEWAY_IP>:5684/15011/9063"

💻 Usage Examples

Initialize the API

use IKEA\Tradfri\Dto\CoapGatewayAuthConfigDto;
use IKEA\Tradfri\Factory\GatewayServiceFactory;

$config = new CoapGatewayAuthConfigDto(
    username: 'php-api-user',
    apiKey: 'YOUR_GENERATED_API_KEY',
    gatewayIp: '192.168.1.xxx',
    gatewaySecret: 'SECRET_FROM_GATEWAY_BOTTOM'
);

$api = (new GatewayServiceFactory($config))();

Control a Light

// Get all lights
$lights = $api->getLights();

foreach ($lights as $light) {
    echo "Found light: " . $light->getName() . " (" . $light->getReadableState() . ")
";
    
    // Switch on and dim to 80%
    if (!$light->isOn()) {
        $light->switchOn();
    }
    $light->dim(80);
}

Control a Group

$groups = $api->getGroups();

if ($groups->count() > 0) {
    $group = $groups->first();
    echo "Controlling group: " . $group->getName() . "
";
    
    // Switch off the entire group
    $group->switchOff();
}

🛠 Features

  • List all devices (Lights, Motion Sensors, Remotes)
  • Control individual light bulbs (On/Off, Brightness, Color)
  • Manage Groups/Rooms
  • Docker support for CoAP communication
  • Modern PHP 8.3+ features

📖 Documentation

For more detailed information, please refer to:

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

This project is licensed under the MIT License - see the LICENSE.md file for details.