-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_kasa.php
More file actions
44 lines (30 loc) · 987 Bytes
/
Copy pathexample_kasa.php
File metadata and controls
44 lines (30 loc) · 987 Bytes
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
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Tapo\Kasa\HS100;
use Tapo\Kasa\HS110;
// --- HS100 Smart Plug ---
$plug = new HS100('192.168.1.100');
// Turn on/off
$plug->turnOn();
$plug->turnOff();
// Toggle current state
$plug->toggleState();
// Get current relay state (true = on, false = off)
$isOn = $plug->getStatus();
echo "Plug is " . ($isOn ? 'ON' : 'OFF') . "\n";
// Get full device info
$info = $plug->getDeviceInfo();
print_r($info);
// Get device name (alias)
echo "Device name: " . $plug->getDeviceName() . "\n";
// --- HS110 Smart Plug with Energy Monitoring ---
$meter = new HS110('192.168.1.101');
$meter->turnOn();
// Real-time energy usage (voltage, current, power)
print_r($meter->getEnergyUsage());
// Daily energy stats for a specific month/year
print_r($meter->getEnergyDaily(6, 2026));
// Monthly energy stats for a year
print_r($meter->getEnergyMonthly(2026));
// --- Custom port / timeout ---
$plug = new HS100('192.168.1.100', 9999, 5);