kasa-smart-hub

Virtual Smart Hub for TP-Link Kasa Smart Home

Usage no npm install needed!

<script type="module">
  import kasaSmartHub from 'https://cdn.skypack.dev/kasa-smart-hub';
</script>

README

Build Status Test Coverage Dependabot Status Dependencies NPM Downloads Semantic-Release Gardener

kasa-smart-hub

Virtual Smart Hub for TP-Link Kasa Smart Home

Designed to be run on a LAN server, e.g. on a Raspberry Pi.

How to

Install as global npm packages. Then create configuration file and start with

kasa-smart-hub /path/to/config.json

Config

Configuration can be in multiple formats. Most likely you want to use config.js or config.json.

logFile

Where events logs are stored

links

Object that contains "linked" switches that are always executed together.

timer

Used to automatically switch off devices

__default

Default fallback timer. Can be set to zero to disable.

Config Example

const path = require('path');

module.exports = {
  logFile: path.join(__dirname, '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'
};

Configure Raspberry Pi Auto Start

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

Acknowledgements

This project relies on tplink-smarthome-api. Documentation for that project can be found here.