Virtual Smart Hub for TP-Link Kasa Smart Home
Designed to be run on a LAN server, e.g. on a Raspberry Pi.
Install as global npm packages. Then create configuration file and start with
kasa-smart-hub /path/to/config.json
Configuration can be in multiple formats. Most likely you want to use config.js
or config.json
.
Where events logs are stored
Object that contains "linked" switches that are always executed together.
Used to automatically switch off devices
Default fallback timer. Can be set to zero to disable.
import path from 'path';
import fs from 'smart-fs';
export default {
logFile: path.join(fs.dirname(import.meta.url), 'kasa-logs.txt'),
links: {
'kitchen-lights': [
// when either of these is switched on / off the other one will also switch on / off
'Kitchen Counter Lights',
'Kitchen Ceiling Light'
]
},
timer: {
__default: 8 * 60 * 60, // switch off everything after eight hours
'Bathroom Fan': 60 * 60 // switch off after one hour
},
on: {
'Plant Light': ['We 21:00'] // switch on every Wednesday at 9pm
},
off: {
TV: ['02:00'] // switch off every day at 2am
},
timezone: 'America/Vancouver'
};
Ensure you are running a recent node version. Install with
npm install -g kasa-smart-hub
Place
[Service]
WorkingDirectory=/home/pi/kasa-smart-hub
ExecStart=kasa-smart-hub start /home/pi/kasa-smart-hub/config.js
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=
User=pi
Group=pi
[Install]
WantedBy=multi-user.target
in /etc/systemd/system/kasa-smart-hub.service
.
Ensure it is readable/writeable/executable by the appropriate user.
Now enable service with sudo systemctl enable kasa-smart-hub
To start the service right away run sudo systemctl start kasa-smart-hub
This project relies on tplink-smarthome-api. Documentation for that project can be found here.