Search by

tandre / tapo-local

tandrezone

Local (LAN-only) control of TP-Link Tapo devices: plugs, bulbs, light strips, the H100 hub and its sensors/switches, and Tapo cameras.

Package info

github.com/tandrezone/tapo-sdk

pkg:composer/tandre/tapo-local

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-11-22 21:17 UTC

This package is auto-updated.

Last update: 2026-11-22 21:29:57 UTC


README

Control TP-Link Tapo devices from PHP over your local network only: no cloud calls, no extra dependencies (just ext-curl and ext-openssl).

Device Class Highlights
P100 plug Plug on/off/toggle, countdown
P110 plug EnergyPlug + current power, energy usage, history
L510 bulb Bulb on/off, brightness
L530 bulb ColorBulb + hue/saturation, RGB/hex, colour temperature
L900 strip LightStrip same as L530
H100 hub Hub child list, siren (playAlarm / stopAlarm)
T100 motion Child\MotionSensor isDetected(), trigger log, battery
T110 contact Child\ContactSensor isOpen(), trigger log, battery
S220 switch Child\LightSwitch on/off/toggle
C100 / C211 camera Camera\Camera privacy mode, LED, motion/person detection, alarm, night vision, flip, reboot, RTSP URL; C211: pan/tilt, presets, auto-tracking

Protocols are negotiated automatically:

  • KLAP (current plug/bulb/hub firmware), v1 and v2
  • securePassthrough (older firmware), RSA + AES with token
  • Cameras: the secure encrypt_type 3 login (nonce digest + AES + Tapo_tag) and the older hashed-password login

Install

composer require tandre/tapo-local

While it's not on Packagist you can use a path repository from another project:

"repositories": [{ "type": "path", "url": "/home/tandre/tapo" }],
"require": { "tandre/tapo-local": "*@dev" }

Credentials

  • Plugs, bulbs, hub: your Tapo app e-mail and password. Devices check them locally.
  • Cameras: username admin and your Tapo cloud password. This is the default when you call $tapo->camera($ip). The "Camera Account" from the app only works for RTSP/ONVIF; use it with getRtspUrl().
  • Newer firmware may only accept local logins after you enable Tapo app → Me → Third-Party Services → Third-Party Compatibility. If authentication fails on a device you know is set up correctly, turn that on first.

Give your devices fixed IPs (DHCP reservations) so the addresses don't change.

Usage

use Tandre\Tapo\Tapo;

$tapo = Tapo::create('you@example.com', 'secret');
// or Tapo::fromEnvironment()  (TAPO_USERNAME / TAPO_PASSWORD)

// Typed access (lazy: nothing is sent until the first call)
$tapo->plug('192.168.1.20')->turnOn();
$watts = $tapo->energyPlug('192.168.1.21')->getCurrentPower();
$tapo->bulb('192.168.1.30')->setBrightness(40);
$tapo->colorBulb('192.168.1.31')->setHexColor('#ff6600');
$tapo->colorBulb('192.168.1.31')->setColorTemperature(2700, 80);
$tapo->lightStrip('192.168.1.32')->setHueSaturation(200, 80, 60);

// Or let it detect the type from the model
$device = $tapo->connect('192.168.1.20');   // returns EnergyPlug for a P110, Hub for an H100…

// Raw access to anything not wrapped
$device->request('get_device_usage');
$device->getDeviceInfo();                    // nickname/ssid already base64-decoded

Hub and its sensors / switches

use Tandre\Tapo\Device\Hub;
use Tandre\Tapo\Device\Child\{MotionSensor, ContactSensor, LightSwitch};

$hub = $tapo->hub('192.168.1.40');

foreach ($hub->getChildren() as $child) {
    echo $child->getModel(), ' ', $child->getNickname(), PHP_EOL;
}

$door = $hub->getChild('Front door');        // by nickname or device_id
if ($door instanceof ContactSensor && $door->isOpen()) {
    $hub->playAlarm('Doorbell Ring 1', Hub::VOLUME_NORMAL, 5);
}

$hub->getChild('Hallway')->getTriggerLogs(10);   // last motion/open events
$hub->getChild('Kitchen light')->turnOn();       // S220 (each gang is its own child)

getChildren() returns the state from the hub's child list, so the isDetected(false), isOpen(false) and getInfo() calls cost nothing extra. Call getDeviceInfo(), or isOpen() without the argument, to refresh.

Cameras

use Tandre\Tapo\Camera\Camera;

$cam = $tapo->camera('192.168.1.50');          // admin + cloud password
// $tapo->camera('192.168.1.50', 'other-password');

$cam->getBasicInfo();
$cam->setPrivacyMode(true);
$cam->setLed(false);
$cam->setMotionDetection(true, Camera::SENSITIVITY_HIGH);
$cam->setPersonDetection(true);
$cam->setDayNightMode('auto');
$cam->startManualAlarm(); $cam->stopManualAlarm();
$cam->getLastAlarmInfo();

// C211 pan/tilt
$cam->move(30, 0);
$cam->getPresets();             // ['1' => 'Door', …]
$cam->goToPresetByName('Door');
$cam->savePreset('Window');
$cam->setAutoTracking(true);

// Anything else, using raw camera API calls
$cam->execute('getRecordPlan', ['record_plan' => ['name' => ['chn1_channel']]]);

echo $cam->getRtspUrl('camuser', 'campass', 1);  // rtsp://…/stream1 (HD), 2 = SD

If a firmware doesn't support a method you get a DeviceException. You can check for that with Camera::isUnsupported($e).

Discovery

foreach ($tapo->discover(3.0) as $d) {
    echo "$d->ip $d->model $d->deviceType $d->encryptType\n";
}

This needs ext-sockets. The probe is a UDP broadcast on port 20002 and doesn't cross subnets/VLANs. Under WSL2 or Docker in NAT mode it usually can't see the LAN, so use host networking or mirrored mode.

CLI

export TAPO_USERNAME=tandrezone@gmail.com TAPO_PASSWORD=Ever4iu87!
vendor/bin/tapo discover
vendor/bin/tapo info 192.168.1.20
vendor/bin/tapo toggle 192.168.1.20
vendor/bin/tapo color 192.168.1.31 '#00ff88'
vendor/bin/tapo power 192.168.1.21
vendor/bin/tapo children 192.168.1.40
vendor/bin/tapo child-on 192.168.1.40 "Kitchen light"
vendor/bin/tapo cam-privacy 192.168.1.50 on
vendor/bin/tapo raw 192.168.1.20 get_device_usage

Run vendor/bin/tapo help for every command.

Errors

All exceptions extend Tandre\Tapo\Exception\TapoException:

  • AuthenticationException: wrong credentials, or a camera that is temporarily locked.
  • DeviceException: the device answered with an error. The errorCode property is filled and ErrorCode::describe() gives a readable message.
  • TransportException: the device is unreachable, sent an HTTP error, or decryption failed.

Options

Tapo::create($user, $pass, [
    'timeout' => 10.0,
    'connect_timeout' => 5.0,
    'protocol' => Tapo::PROTOCOL_AUTO,   // or PROTOCOL_KLAP / PROTOCOL_PASSTHROUGH to skip detection
    'http' => $myHttpClient,             // any HttpClientInterface
]);

Sessions stay open for the lifetime of a device object. Reuse the object in long-running processes so you don't repeat the handshake on every call.

Tests

composer install && composer test

The tests run the client against in-memory fake KLAP, passthrough and camera servers. They check the handshakes, encryption, signatures, session renewal and the request formats.