UNPKG

node-red-contrib-tapo-new-api

Version:

Unofficial node-RED node for connecting to TP-Link Tapo devices with new API. Currently limited to the P100 & P105 & P110 smart plugs and L510E smart bulbs.

313 lines (299 loc) 18.1 kB
<!DOCTYPE html> <!-- Copyright JS Foundation and other contributors, http://js.foundation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <script type="text/javascript"> function mk_conf(NAME) { console.log("mk_conf"); const icons = { "status": "icon-status.png", "power": "icon.png", "on": "icon-turn-on.png", "off": "icon-turn-off.png", "toggle": "icon-toggle.png", "color": "icon-colour.png", "brightness": "icon-brightness.png", "components": "icon-components.png", "command": "icon-command.png", } const conf = { category: 'TAPO tplink', color: 'rgb( 63, 173, 181)', defaults: { name: { value: "" }, deviceIp: { value: "", required: false }, deviceAlias: { value: "", required: false }, deviceIpRange: { value: "", required: false }, searchMode: { value: "ip", required: true }, command: { value: "status", required: true }, version: { value: 3, required: true} }, credentials: { email: { type:"text" }, password: { type:"password" } }, inputs: 1, outputs: 1, align: "left", icon: function () { return this.command ? icons[this.command] : "icon-status.png"; }, paletteLabel: NAME, label: function () { return this.name || this._("resources.paletteLabel"); }, labelStyle: function () { return this.name ? "node_label_italic" : ""; }, paletteLabel: function () { return this._("resources.paletteLabel") || NAME; }, oneditprepare: function () { // use elementSizer to input common widget parameters // console.log("oneditprepare"); // searchMode $("#select-searchMode").change(function () { const searchMode = $("#select-searchMode").val(); $("#node-input-searchMode").val(searchMode); if ("ip" === searchMode) { document.getElementById('node-input-deviceIp').disabled = false; document.getElementById('node-input-deviceAlias').disabled = true; document.getElementById('node-input-deviceIpRange').disabled = true; } else { document.getElementById('node-input-deviceIp').disabled = true; document.getElementById('node-input-deviceAlias').disabled = false; document.getElementById('node-input-deviceIpRange').disabled = false; } }); $("#select-searchMode").val(this.searchMode); $("#select-searchMode").change(); // version $("#select-version").change(function () { const version = parseInt($("#select-version").val(),10); $("#node-input-version").val(version); }); $("#select-version").val(this.version.toString()); $("#select-version").change(); // command $("#select-command").change(function () { const command = $("#select-command").val(); $("#node-input-command").val(command); }); $("#select-command").val(this.command); $("#select-command").change(); }, oneditsave: function () { var that = this; }, }; return conf; } RED.nodes.registerType('tapo_new_actions', mk_conf('tapo_new_actions')); </script> <script type="text/html" data-template-name="tapo_new_actions"> <div id="list-property"> <!----------------------------------------------------------------------------> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="resources.labels.name"></span></label> <input type="text" id="node-input-name"> </div> <!----------------------------------------------------------------------------> <hr> <!----------------------------------------------------------------------------> <!-- email --> <div class="form-row"> <label for="node-input-email"><i class="fa fa-shield"></i><span data-i18n="resources.labels.email"></span></label> <input type="text" id="node-input-email" placeholder="tplink account email"> </div> <!-- password --> <div class="form-row"> <label for="node-input-password"><i class="fa fa-key"></i><span data-i18n="resources.labels.password"></span></label> <input type="password" id="node-input-password" placeholder="tplink account password"> </div> <!----------------------------------------------------------------------------> <hr> <!----------------------------------------------------------------------------> <!-- version --> <p><span data-i18n="resources.labels.version.description"></span></p> <div class="form-row"> <label for="select-version"><i class="fa fa fa-code"></i> <span data-i18n="resources.labels.version.title"></span></label> <select id="select-version"> <option value="1" data-i18n="resources.labels.version.v1"></option> <option value="2" data-i18n="resources.labels.version.v2"></option> <option value="3" data-i18n="resources.labels.version.auto"></option> </select> <input type="hidden" id="node-input-version"> </div> <div class="form-row"> <label for="select-command"><i class="fa fa fa-code"></i> <span data-i18n="resources.labels.command.title"></span></label> <select id="select-command"> <option value="status" data-i18n="resources.labels.command.status"></option> <option value="power" data-i18n="resources.labels.command.power"></option> <option value="on" data-i18n="resources.labels.command.on"></option> <option value="off" data-i18n="resources.labels.command.off"></option> <option value="toggle" data-i18n="resources.labels.command.toggle"></option> <option value="color" data-i18n="resources.labels.command.color"></option> <option value="brightness" data-i18n="resources.labels.command.brightness"></option> <option value="components" data-i18n="resources.labels.command.components"></option> <option value="command" data-i18n="resources.labels.command.command"></option> </select> <input type="hidden" id="node-input-command"> </div> <!----------------------------------------------------------------------------> <hr> <!----------------------------------------------------------------------------> <!-- Tapo device settings --> <p><b><span data-i18n="resources.labels.targetDeviceSettings"></span></b></p> <p><span data-i18n="resources.descriptions.targetDeviceSettings"></span></p> <!-- searchMode --> <div class="form-row"> <label for="select-searchMode"><i class="fa fa fa-adjust"></i> <span data-i18n="resources.labels.searchMode.title"></span></label> <select id="select-searchMode"> <option value="ip" data-i18n="resources.labels.searchMode.ip"></option> <option value="alias" data-i18n="resources.labels.searchMode.alias"></option> </select> <input type="hidden" id="node-input-searchMode"> </div> <p><b><span data-i18n="resources.labels.searchMode.description"></span></b></p> <!-- deviceIp --> <div class="form-row"> <label for="node-input-deviceIp"><i class="fa fa-map-marker"></i><span data-i18n="resources.labels.deviceIp"></span></label> <input type="text" id="node-input-deviceIp" placeholder="your tapo deviceIp(e.g: 192.168.0.100)"> </div> <!-- deviceAlias --> <div class="form-row"> <label for="node-input-deviceAlias"><i class="fa fa-tag"></i><span data-i18n="resources.labels.deviceAlias"></span></label> <input type="text" id="node-input-deviceAlias" placeholder="your tapo deviceAlias"> </div> <div class="form-row"> <label for="node-input-deviceIpRange"><i class="fa fa-map-marker"></i><span data-i18n="resources.labels.deviceIpRange"></span></label> <input type="text" id="node-input-deviceIpRange" placeholder="your tapo deviceIpRange(e.g: 192.168.0.0/24)"> </div> <!----------------------------------------------------------------------------> <hr> <!----------------------------------------------------------------------------> </div> </script> <script type="text/x-red" data-help-name="tapo_new_actions"> <p>Unofficial node-RED node for connecting to TP-Link Tapo devices with <b>new interface (Klap)</b> or the <b>previous one (PassThrough)</b>. It can select also <b>automatically (Auto)</b> the protocol to use.</p> <p>Currently supports:</p> <ul> <li> P100, P105, P110, P115 smart plugs</li> <li> L510E, L530E smart bulbs</li> <li> L900-10 smart strip</li> </ul> <h3>Inputs</h3> <dl class="message-properties"> <dt class="optional">msg.config <span class="property-type">object</span></dt> <dl class="message-properties"> <dt class="optional">command <span class="property-type">string</span></dt> <dd> If set this property overrides the one specified in the configuration node. It specifies the behaviour of this instance of <b>actions</b> button.</dd> <dd> It will be an string with one of the following values <code>type command_type = "status" | "power" | "on" | "off" | "toggle" | "color" | "brightness" | "components" | "command";</code></dd> </dl> <dl class="message-properties"> <dt class="optional">version <span class="property-type">number</span></dt> <dd> If set this property overrides the one specified in the configuration node. It defines the version of the protocol to use in this instance of <b>actions</b> button.</dd> <dd> It will be a number with one of the following values <code>enum TapoProtocolType = {PASSTHROUGH = 1, KLAP = 2, AUTO = 3}</code></dd> </dl> <dl class="message-properties"> <dt class="optional">verbose <span class="property-type">boolean</span></dt> <dd> When set to <b>true</b> the object <code>msg.payload.errorInf.track</code> will be included in the output in case of error.</dd> </dl> <dl class="message-properties"> <dt class="optional">terminal_random <span class="property-type">boolean</span></dt> <dd> When set to <b>true</b> the <code>terminal_uuid</code> will be randomly generated. Useful when deploying different buttons to attack same device.</dd> </dl> <dl class="message-properties"> <dt class="optional">email <span class="property-type">string</span></dt> <dd> If set this property overrides the one specified in the configuration node. It specifies the username of the <b>Tapo account</b>.</dd> <dd> It will only access to the <b>Tapo Cloud</b> if alias is used, but it is required in all cases to access the device locally.</dd> </dl> <dl class="message-properties"> <dt class="optional">password <span class="property-type">string</span></dt> <dd> If set this property overrides the one specified in the configuration node. It specifies the password of the <b>Tapo account</b>.</dd> <dd> It will only access to the <b>Tapo Cloud</b> if alias is used, but it is required in all cases to access the device locally.</dd> </dl> <dl class="message-properties"> <dt class="optional">searchMmode <span class="property-type">string</span></dt> <dd> If set this property overrides the one specified in the configuration node. It specifies the way to search for the device attach to the instance of <b>actions</b> node.</dd> <dd> It will be an string with one of the following values <code>type search_mode_type = "ip" | "alias";</code></dd> </dl> <dl class="message-properties"> <dt class="optional">deviceIp <span class="property-type">string</span></dt> <dd> If set this property overrides the one specified in the configuration node. It specifies the <b>ip</b> of the device.</dd> </dl> <dl class="message-properties"> <dt class="optional">deviceAlias <span class="property-type">string</span></dt> <dd> If set this property overrides the one specified in the configuration node. It specifies the <b>alias</b> of the device in the <b>Tapo Cloud</b>.</dd> </dl> <dl class="message-properties"> <dt class="optional">deviceIpRange <span class="property-type">string</span></dt> <dd> If set this property overrides the one specified in the configuration node. It restricts the search of IPs in the local network when <b>alias</b> is used.</dd> </dl> </dl> <dl class="message-properties"> <dt class="optional">msg.payload <span class="property-type">boolean/string/number</span></dt> <dl class="message-properties"> <dt class="optional">payload <span class="property-type">boolean</span></dt> <dd> If <code>msg.config.command = "power"</code> then this property sets the <code>device_on</code> property, thus turning on or off the device.</dd> </dl> <dl class="message-properties"> <dt class="optional">payload <span class="property-type">string</span></dt> <dd> If <code>msg.config.command = "color"</code> then this property sets the <code>color</code> property. It can be an hex value or one of the following string values:</dd> <dd> <code> "blue" | "red" | "yellow" | "green" | "white" | "daylightwhite" | "warmwhite" </code></dd> </dl> <dl class="message-properties"> <dt class="optional">payload <span class="property-type">number</span></dt> <dd> If <code>msg.config.command = "brightness"</code> then this property sets the <code>brightness_level</code> property. It wil be truncated to a number between 0 to 100.</dd> </dl> <dl class="message-properties"> <dt class="optional">payload <span class="property-type">object</span></dt> <dd> If <code>msg.config.command = "command"</code> then this property sets the <code>{"method": string, "params": {"key": value, ...}}</code> request.</dd> </dl> </dl> <h3>Outputs</h3> <dl class="message-properties"> <dt>payload <span class="property-type">object</span></dt> <dl class="message-properties"> <dt class="optional">result <span class="property-type">boolean</span></dt> <dd> Returns whether the command was successful or not.</dd> </dl> <dl class="message-properties"> <dt class="optional">tapoDeviceInfo <span class="property-type">object</span></dt> <dd> An object containing all the info properties retrieved from the device.</dd> </dl> <dl class="message-properties"> <dt class="optional">tapoEnergyUsage <span class="property-type">object</span></dt> <dd> In case the device can measure energy, this object will contain all the energy consumption information retrieved from the device.</dd> </dl> <dl class="message-properties"> <dt class="optional">tapoCommand <span class="property-type">object</span></dt> <dd> In case the <code>command</code> has been used, this is the resulting object of that request.</dd> </dl> <dl class="message-properties"> <dt class="optional">errorInf <span class="property-type">object</span></dt> <dd> Error object with the following properties:</dd> <dd> <code>{error_code: code of error, message: error description, agent: internal function failing, cause: root cause, track: tree of errors}</code></dd> </dl> </dl> <h3>Details</h3> <p> The node is used to connect to a single device using the appropriate Tapo protocol.<br> Once configured the node could execute different commands and ndoe icon will change accordingly.<br> The node configuration will configure the node statically, but a dynamic configuration may be done through <code>msg.config</code>.<br> The output will be a fully descriptive object with different properties, that also enables appropriate error management<br></p> <h3>References</h3> <ul> <li><a href="https://github.com/mbserran/node-red-contrib-tapo-new-api">GitHub</a> - the nodes github repository</li> </ul> </script> <style> </style>