UNPKG

node-red-contrib-etekcity-smartplug

Version:

etekcity smartplug

121 lines (110 loc) 4.97 kB
<script type="text/javascript"> RED.nodes.registerType('etekcity', { category: 'switch', color: '#f37a33', defaults: { name: {value: ''}, account: {value: '', type: 'vesync-account'}, device: {value: 'none', required:true}, current: {value: ''} }, inputs: 1, outputs: 1, icon: 'plug_circle_sm.png', label: function () { return this.name || 'etekcity plug'; }, paletteLabel: 'etekcity plug', align: 'left', oneditprepare: function() { var node = this; function updateDevices() { $('#node-input-device option').remove(); $('<option value="none">Select Device</option>').appendTo('#node-input-device'); $.getJSON('etekcityDevices',function(data) { data.sort(function(a, b) { return a.name > b.name; }); data.sort(); $.each(data, function(i, device) { $('<option value="' + device.id + '">'+device.name+'</option>').appendTo('#node-input-device'); }); if(node.device) { $('#node-input-device').val(node.device); $('#node-input-device').trigger('change'); } }); } $('#node-input-account').change(function() { if( $('#node-input-account').val() !== '' ) { if( $('#node-input-account').val() === '_ADD_' ) { $('#node-input-current').val('_ADD_'); $('#node-input-device option').remove(); $('<option value="none">Select Device</option>').appendTo('#node-input-device'); }else{ if($('#node-input-account').val() !== $('#node-input-current').val()) { $('#node-input-current').val($('#node-input-account').val()); updateDevices(); } } } }); $('#node-input-refresh').on('click', function() { updateDevices(); }); updateDevices(); } }); </script> <script type="text/x-red" data-template-name="etekcity"> <div class="form-row"> <label for="node-input-name"><i class="icon-tag"></i> Name</label> <input type="text" id="node-input-name"> </div> <div class="form-row"> <label for="node-input-account"><i class="fa fa-user"></i> Account</label> <input type="text" id="node-input-account"> <input type="hidden" id="node-input-current"> </div> <div class="form-row"> <label for="node-input-device"><i class="fa fa-plug"></i> Devices</label> <select id="node-input-device"></select> <input type="button" id="node-input-refresh" value="Refresh" style="width: 75px; height: 25px;"> </div> </script> <script type="text/x-red" data-help-name="etekcity"> <p>Turns an Etekcity Smart Plug On or Off</p> <h3>Inputs</h3> <dl class="message-properties"> <dt>payload <span class="property-type">string</span> </dt> <dd>the action to send to the smart plug</dd> </dl> <h3>Outputs</h3> <dl class="message-properties"> <dt>payload - on success <span class="property-type">string</span> </dt> <dd>the text <code>on</code> or <code>off</code> is returned</dd> <dt>payload - on failure <span class="property-type">string</span> </dt> <dd>the specific error message is returned</dd> </dl> <h3>Details</h3> <dl class="message-properties"> <dt>setup</dt> <dd>before using the node, you must add your Vesync Account in the settings, which consists of the username and password created with the Vesync iOS/Android app</dd> <dt>payload <span class="property-type">string</span> </dt> <dd><code>msg.payload</code> must be <code>on</code> or <code>off</code></dd> <dt>on/off status</dt> <dd>keep in mind that the vesync system does not allow for constant connection to their server, therefore, the status message under the node (<code>on</code> or <code>off</code>) may be inaccurate if you turn the device on/off outside of node-red (e.g. Alexa, Google Home, etc), as it will still display the status as last changed in node-red.</dd> </dl> <h3>Credits</h3> <dl class="message-properties"> <dd>Thanks to <a href="https://www.npmjs.com/~dirwin517">@dirwin517</a> for creating the <a href="https://www.npmjs.com/package/etekcity-smartplug">etekcity-smartplug</a> npm package that this node-red node is a wrapper for</dd> </dl> </script>