A powerful and easy-to-use PHP library to control your IKEA Tradfri smart lights through the Gateway.
Inspired by hvanderlaan/ikea-smartlight (Python).
- PHP 8.3 or higher
coap-client(can be run via Docker)- IKEA Tradfri Gateway
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"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))();// 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);
}$groups = $api->getGroups();
if ($groups->count() > 0) {
$group = $groups->first();
echo "Controlling group: " . $group->getName() . "
";
// Switch off the entire group
$group->switchOff();
}- 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
For more detailed information, please refer to:
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE.md file for details.