Created
June 29, 2021 10:48
-
-
Save sondt2709/ac9f9d0af954f9edc824347cfa8c64de to your computer and use it in GitHub Desktop.
Trigger TP-Link Tapo P100 to turn ON/OFF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const connection = require('tp-link-tapo-connect') | |
const run = async (email, password, ip, action) => { | |
const cloudToken = await connection.cloudLogin(email, password) | |
const devices = await connection.listDevicesByType(cloudToken, 'SMART.TAPOPLUG') | |
const deviceToken = ip | |
? await connection.loginDeviceByIp(email, password, ip) | |
: await connection.loginDevice(email, password, devices[0]) | |
const getDeviceInfoResponse = await connection.getDeviceInfo(deviceToken) | |
console.log(getDeviceInfoResponse) | |
if (action) { | |
await connection.turnOn(deviceToken) | |
} else { | |
await connection.turnOff(deviceToken) | |
} | |
} | |
module.exports = run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment