# IKEA Tradfri PHP API

Codacy Badge QA Codacy Badge codecov Release PHP Version Latest Stable Version Total Downloads License

A powerful PHP library to control IKEA Tradfri smart lights via the Gateway.


# ๐Ÿš€ Quick Start

# 1. Requirements

  • PHP 8.4+
  • coap-client (available via Docker)

# 2. Generate Security Key

Use the Docker Coap-Client to get your credentials:

BASH
docker run --rm webproject/coap-client 
  -m post -u "Client_identity" -k "<GATEWAY_SECRET>" 
  -e '{"9090":"php-api-user"}' 
  "coaps://<GATEWAY_IP>:5684/15011/9063"

# ๐Ÿ’ป Usage

# Initialize API

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

$api = (new GatewayServiceFactory(
    new CoapGatewayAuthConfigDto(
        username: 'php-api-user',
        apiKey: 'GENERATED_API_KEY',
        gatewayIp: '192.168.1.10',
        gatewaySecret: 'GATEWAY_SECRET'
    )
))();

# Control Devices

PHP
// Switch on all lights and dim to 80%
foreach ($api->getLights() as $light) {
    $light->switchOn()->dim(80);
}

// Switch off a specific group
$api->getGroups()->first()?->switchOff();

# ๐Ÿ“– Documentation

# ๐Ÿค Contributing

Feel free to submit Pull Requests.

# ๐Ÿ“„ License

MIT License.

NORMAL โއ main README.md bun ยท astro ยท workers UTF-8 100%