Contenidos
Obtener el identificador universally unique identifier (UUID)
Obtener el token y el deviceID que tiene la bombilla mediante Node.js
El token es un valor que establece una relación entre la bombilla y la aplicación Kasa. El deviceID es el identificador de la bombilla.
Para obtener el token y el deviceID de la bombilla es necesario el identificador universal obtenido en el paso anterior además del correo electrónico y la contraseña con la que se dió de alta en Kasa.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
const { login } = require("tplink-cloud-api"); const uuidV4 = require("uuid/v4"); const TPLINK_PASS = "aaaaa234aaaaaa"; const TPLINK_TERM = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"; async function main() { // log in to cloud, return a connected tplink object const tplink = await login(TPLINK_USER, TPLINK_PASS, TPLINK_TERM); // get a list of raw json objects (must be invoked before .get* works) const dl = await tplink.getDeviceList(); let myPlug = tplink.getHS100("bombilla"); console.log("token,deviceID"); console.log(tplink.getToken()+","+myPlug.getDeviceId()); } main(); |
Apagar y encender la Bombilla Inteligente TP-Link Kasa Regulable KL110 desde PowerShell
Es necesario indicar el token y el deviceID.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
$Token = "adsfsadf-adsfasdf" # URI del servicio appServerUrl: 'https://eu-wap.tplinkcloud.com' $URI = 'https://eu-wap.tplinkcloud.com/?token='+$Token # Cabeceras $Cabeceras = @{ 'Content-type' = 'application/json' } # Parámetros para encender y apagar # Encender ## '{"method":"passthrough", "params": {"deviceId": "asdfsadf", "requestData": "{\"smartlife.iot.smartbulb.lightingservice\":{\"transition_light_state\": {\"on_off\": 1,\"transition_period\": 0}}}"}}' # Apagar ## '{"method":"passthrough", "params": {"deviceId": "asdfsadf", "requestData": "{\"smartlife.iot.smartbulb.lightingservice\":{\"transition_light_state\": {\"on_off\": 0,\"transition_period\": 0}}}"}}' $Body = '{"method":"passthrough", "params": {"deviceId": "asdfsadf", "requestData": "{\"smartlife.iot.smartbulb.lightingservice\":{\"transition_light_state\": {\"on_off\": 0,\"transition_period\": 0}}}"}}' # Preparar la petición y obtener respuesta $Respuesta = Invoke-RestMethod -Method Post -Uri $URI -Headers $Cabeceras -Body $Body # Convertir respuesta en formato JSON y ver el resultado de la petición anterior ConvertTo-Json $Respuesta.result |