@demirdeniz/node-red-contrib-tuya-api
Version:
access tuya devices via cloud api and local sockets
113 lines (109 loc) • 5.14 kB
HTML
<script type="text/javascript">
RED.nodes.registerType("tuya-local-dsocket", {
category: "Tuya",
defaults: {
devName : { value: "", required: true},
devIp: { value: "", required: false},
devId: { value: "", required: false },
devKey: { value: "", required: false},
protocolVer: { value: "3.3", required: true},
pollingInterval: { value: "50", required: true },
renameSchema: { value: "" },
filterCB: { value: "" },
},
inputs: 1,
outputs: 1,
icon: "tuya1.png",
color: "#e2d96e",
label: function() {
return this.devName || this.devIp || "tuya-local-dsocket";
}
});
</script>
<!-- -->
<script type="text/x-red" data-template-name="tuya-local-dsocket">
<div class="form-row">
<label for="node-input-devName"><i class="icon-tag"></i> Device name</label>
<input type="text" id="node-input-devName" placeholder="Node name">
</div>
<div class="form-row">
<label for="node-input-devIp"><i class="fa fa-server"></i> IP Address</label>
<input type="text" id="node-input-devIp" placeholder="">
</div>
<div class="form-row">
<label for="node-input-devId"><i class="fa fa-id-badge"></i> ID</label>
<input type="text" id="node-input-devId" placeholder="82180808c44f33a6743a">
</div>
<div class="form-row">
<label for="node-input-devKey"><i class="fa fa-key"></i> Key</label>
<input type="text" id="node-input-devKey" placeholder="acb2ad7c747d1dac">
</div>
<div class="form-row">
<label for="node-input-protocolVer"><i class="fa fa-list-ul"></i> Version</label>
<input type="text" id="node-input-protocolVer" placeholder="">
</div>
<div class="form-row">
<label for="node-input-pollingInterval"><i class="fa fa-list-ul"></i> Polling interval</label>
<input type="number" id="node-input-pollingInterval" placeholder="">
</div>
<div class="form-row">
<label for="node-input-renameSchema"><i class="fa fa-list-ul"></i> Rename Schema</label>
<input type="text" id="node-input-renameSchema" placeholder='{"1":"state"}'>
</div>
<div class="form-row">
<label for="node-input-filterCB"><i class="fa fa-list-ul"></i> Filter commandByte</label>
<input type="text" id="node-input-filterCB" placeholder="7,10">
</div>
</script>
<script type="text/x-red" data-help-name="tuya-local-dsocket">
<p>Connects to a Tuya device via active tcp socket using tuyapi library.
Can receive commands to control and send status update in real time</p>
<h3>Config</h3>
<dl class="message-properties">
<dt>Name<span class="optional">string</span></dt>
<dd>Name to show in NodeRED</dd>
<dt class="property-type">IP address<span class="property-type">string</span></dt>
<dd>IP address or hostname of the device, optional,overide in msg.ip</dd>
<dt class="property-type">Device ID<span class="property-type">string</span></dt>
<dd>Device ID obtained for the device, overide in msg.id</dd>
<dt class="property-type">Device key<span class="property-type">string</span></dt>
<dd>Device local key obtained for the device, override in msg.key</dd>
<dt class="property-type">Version<span class="property-type">string</span></dt>
<dd>Tuya protocol version 3.3 is normal, some devices want 3.1 which encrypts only set commands</dd>
<dt class="property-type">Polling interval<span class="property-type">number</span></dt>
<dd>Status polling interval in seconds (0 = disabled)</dd>
<dt class="property-type">Rename schema<span class="property-type">JSON</span></dt>
<dd>Rename schema. Rename dps keys to friendly strings</dd>
<dt class="property-type">Filter commandByte<span class="property-type">string</span></dt>
<dd>Comma separated integers of commandBytes values to filter out</dd>
</dl>
<h3>Inputs</h3>
<dl class="message-properties">
<dt class="optional">
payload<span class="property-type">boolean</span>
</dt>
<dd>Changes the state dps['1'] to msg.payload</dd>
<dt class="optional">
payload<span class="property-type">JSON</span>
</dt>
<dd>Change a specific dps property or multiple ones.</dd>
<dd>ex: {"set": true|false,"dps": 2}</dd>
<dd>ex: {"multiple":true,"data":{1:true,3:false }}</dd>
<dt class="optional">
payload<span class="property-type">string</span>
</dt>
<dd><b>connect</b> Connect the device</dd>
<dd><b>disconnect</b> Disconnect the device</dd>
<dd><b>toggle</b> Toggle the state of dps['1']</dd>
<dd><b>request</b> Request the state of the device, this includes all properties</dd>
</dl>
<h3>Output</h3>
<dl class="message-properties">
<code>msg.payload</code> The state report of the device.</p>
<code>msg.commandByte</code>Integer representing the commandByte of the result
(e.g. 7=requested response, 8=proactive update from device), more info on different
values<a href="https://github.com/codetheweb/tuyapi/blob/c72cda1238068d496a7d4017275d3d3d0c8c29c8/lib/message-parser.js#L12-L45">here</a></p>
<code>msg.data</code> The device information including the object key "available"
which is true if the device is online, false otherwise</p>
</dl>
</script>