-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.php
More file actions
51 lines (37 loc) · 1.26 KB
/
Copy pathexample.php
File metadata and controls
51 lines (37 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Tapo\P100;
use Tapo\P110;
use Tapo\L530;
use Tapo\MeasureInterval;
// --- P100 / P105 Smart Plug ---
$plug = new P100('192.168.1.100', 'your@email.com', 'your_password');
// Turn on/off
$plug->turnOn();
$plug->turnOff();
// Toggle current state
$plug->toggleState();
// Turn on after 10 seconds
$plug->turnOnWithDelay(10);
// Get device info
$info = $plug->getDeviceInfo();
print_r($info);
// Get device name (decoded from base64)
echo "Device name: " . $plug->getDeviceName() . "\n";
// --- P110 Smart Plug with Energy Monitoring ---
$meter = new P110('192.168.1.101', 'your@email.com', 'your_password');
$meter->turnOn();
print_r($meter->getEnergyUsage());
// Energy data for a time range
$start = mktime(0, 0, 0, 1, 1, 2024);
$end = mktime(0, 0, 0, 12, 31, 2024);
print_r($meter->getEnergyData($start, $end, MeasureInterval::DAYS));
// --- L530 Color Bulb ---
$bulb = new L530('192.168.1.102', 'your@email.com', 'your_password');
$bulb->turnOn();
$bulb->setBrightness(50);
$bulb->setColorTemp(4000);
$bulb->setColor(120, 80); // hue, saturation
// --- Force a specific protocol ---
// Use 'new' for modern firmware, 'old' for legacy devices
$plug = new P100('192.168.1.100', 'your@email.com', 'your_password', 'old');