After cloning the repository, create the virtual environment
Please note, this readme assumes the repository was cloned to /var/bin/kasa-controller
python3 -m venv lc
source lc/bin/activate
pip install -r requirements.txt
This repository was tested on Python 3.9, but an earlier of python should work.
Make sure that the virtual environment is named lc
since that is what the startup
script uses.
To inject this into the system path, edit /etc/profile
and add the following line
below the existing PATH
manipulation:
PATH="$PATH:/var/bin/kasa-controller";export PATH
To make the script run after the last uesr logs out, you need to edit
/etc/pam.d/sshd
. Add the following line:
# Execute the login/logoff scripts
session optional pam_exec.so quiet /etc/pam_session.sh
Then, symlink the pam_session.sh
file in this repository to /etc/pam_session.sh
:
ln -s /var/bin/kasa-controller/pam_session.sh /etc/pam_session.sh
Lastly, make sure that both kasa
and pam_session.sh
are given executable
permissions:
chmod a+x kasa pam_session.sh
The main Python file, KasaControl.py
takes in one positional argument and one
optional argument. The positional argument tells the program whether to turn the
device on
or off
. The optional argument tells the program what level of
debugging to provide. Additionally, an IP address can be provided with the -ip
flag. If an IP address is not provided, the program will read the environment
variable KASA_DEVICE_IP_ADDR
. You can optionally make a .env
file in the
repository directory:
echo KASA_CONTROL_IP_ADDR=XX.XX.XX.XX >> .env # replace XX.XX.XX.XX with your IP address
usage: kasa [-h] [--verbose] [-ip IP] {on,off}
positional arguments:
{on,off}
optional arguments:
-h, --help show this help message and exit
--verbose, -v
-ip IP IP address of smart plug