UNPKG

node-red-contrib-mobius-flow-dali

Version:

Node-RED nodes to work with MOBiUSFlow and DALI devices

293 lines (280 loc) 12.1 kB
<!-- Copyright (C) 2020, IAConnects Technology Limited All Rights Reserved ALL INFORMATION CONTAINED HEREIN IS, AND REMAINS THE PROPERTY OF IACONNECTS TECHNOLOGY LIMITED AND ITS SUPPLIERS, IF ANY. THE INTELLECTUAL AND TECHNICAL CONCEPTS CONTAINED HEREIN ARE PROPRIETARY TO IACONNECTS TECHNOLOGY LIMITED AND ITS SUPPLIERS AND ARE PROTECTED BY TRADE SECRET OR COPYRIGHT LAW. DISSEMINATION OF THIS INFORMATION OR REPRODUCTION OF THIS MATERIAL IS STRICTLY FORBIDDEN UNLESS PRIOR WRITTEN PERMISSION IS OBTAINED FROM IACONNECTS TECHNOLOGY LIMITED. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --> <script type="text/html" data-template-name="dali control command generator"> <div class="form-row"> <label for="node-input-daliConnection" style="width: 160px;"><i class="fa fa-globe"></i> DALI Connection</label> <select type="text" id="node-input-daliConnection" style="display: inline-block; width: 300px; vertical-align: middle;"></select> </div> <div id="nocons-message-row" class="form-row" style="color:#ff0000" align="center"> <p>Please use the DALI connection manager node <br/> to add a new DALI connection.</p> </div> <hr> <div class="form-row"> <label for="node-input-command" style="width: 160px;"><i class="fa fa-terminal"></i> Command Type</label> <select type="text" id="node-input-command" style="display: inline-block; width: 300px; vertical-align: middle;"> <option value='' disabled selected>Select a command...</option> <option value='0'>Off</option> <option value='3'>Step Up</option> <option value='4'>Step Down</option> <option value='5'>Recall Max Level</option> <option value='6'>Recall Min Level</option> <option value="999">Lighting Level Control</option> </select> </div> <div class="form-row"> <label for="node-input-addressingMode" style="width: 160px;"><i class="fa fa-address-book"></i> Addressing Mode</label> <select type="text" id="node-input-addressingMode" style="display: inline-block; width: 300px; vertical-align: middle;"> <option value='short'>Short</option> <option value='group'>Group</option> <option value='broadcast'>Broadcast</option> </select> </div> <div id="shortAddressingMethod"> <div class="form-row"> <label for="node-input-selectionMethod" style="width: 160px;"><i class="fa fa-hand-pointer-o"></i> Selection Method</label> <select type="text" id="node-input-selectionMethod" style="display: inline-block; width: 300px; vertical-align: middle;"> <option value='ins'>By Object Instance</option> <option value='addr'>By DALI Address</option> </select> </div> </div> <div id="addressing"> <div class="form-row"> <label id ="insLabel" for="node-input-address" style="width: 160px;"><i class="fa fa-list-ol"></i> Object Instance</label> <label id = "daliLabel" for="node-input-address" style="width: 160px;"><i class="fa fa-sitemap"></i> DALI Address</label> <input type="text" id="node-input-address" style="width: 300px;"> </div> </div> <div id="power-level"> <div class="form-row"> <label for="node-input-level" style="width: 160px;"><i class="fa fa-lightbulb-o"></i> Lighting Level</label> <input type="text" id="node-input-level" style="width: 300px;"> </div> </div> <hr> <div class="form-row"> <label for="node-input-name" style="width: 160px;"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name" style="width: 300px;"> </div> </script> <script type="text/javascript"> function getLabel(conNode) { return RED.nodes.node(conNode).name } RED.nodes.registerType('dali control command generator', { category: 'dali', color: '#ffd11a', defaults: { name: {value: ''}, daliConnection: {value: '', required: true}, command: {required:true, value: '', validate:RED.validators.regex(/^([0-9]{3}|[0-9]{2}|[0-9]{1})$/)}, addressingMode: {required:true, value: 'broadcast'}, address: {required:true, value: '0001', validate: (v) => { let re; if (v === undefined || v === null) { return false; } else { if ($("#node-input-addressingMode").val() === undefined) { return true; } else if ($("#node-input-addressingMode").val() === 'short') { if ($("#node-input-selectionMethod").val() === 'ins') { re = /^([0][0]([0]([0-9]|[A-F])|[1-3]([0-9]|[A-F])))$/g; } else { re = /^([0-9]|([1-5][0-9]|[6][0-3]))$/g; } return re.test(v); } else if ($("#node-input-addressingMode").val() === 'group') { re = /^([0-9]|([1][0-5]))$/g; return re.test(v); } else { return true; } } }}, level: {required:true, value: '0', validate: (v) => { let val = parseInt(v); if (val === undefined || val === null) { return false; } else { return (val <= 100 && val >= 0); } }}, selectionMethod: {value: 'ins', required: true} }, inputs: 1, outputs: 0, icon: 'dali-icon.png', align: 'left', paletteLabel: 'dali send lighting command', label: function() { const commandLookup = { 0: 'Off', 3: 'Step Up', 4: 'Step Down', 5: 'Recall Max Level', 6: 'Recall Min Level', 999: 'Lighting Level Control' } let connectionLabel; if (this.daliConnection !== '') { connectionLabel = getLabel(this.daliConnection); } if (commandLookup[parseInt(this.command)] !== undefined) { if (connectionLabel !== undefined) { return this.name||`${commandLookup[parseInt(this.command)]} - ${connectionLabel}`; } else { return this.name||`${commandLookup[parseInt(this.command)]}`; } } else { return this.name||`DALI Send Lighting Command`; } }, labelStyle: function() { return this.name ? 'node_label_italic':''; }, oneditprepare: function () { let node = this; RED.nodes.eachConfig((n) => { if (n.type === 'dali-connection') { $("#node-input-daliConnection").append($("<option></option>").val(n.id).text(n.name)); $("#nocons-message-row").hide(); } }); $("#node-input-daliConnection").val(node.daliConnection); function displayLayout() { if($("#node-input-addressingMode").val() === 'broadcast') { $("#addressing").hide(); } else { $("#addressing").show(); } if($("#node-input-addressingMode").val() === 'group') { $("#insLabel").hide(); $("#daliLabel").show(); } if($("#node-input-addressingMode").val() === 'short') { $("#shortAddressingMethod").show(); updateSelectionLabel() } else { $("#shortAddressingMethod").hide(); } if($("#node-input-command").val() === '999') { $("#power-level").show(); } else { $("#power-level").hide(); } } displayLayout(); $("#node-input-addressingMode").change(function() { displayLayout(); }); $("#node-input-command").change(function() { displayLayout(); }); function updateSelectionLabel() { if($("#node-input-selectionMethod").val() === 'ins') { $("#insLabel").show(); $("#daliLabel").hide(); } else { $("#insLabel").hide(); $("#daliLabel").show(); } } updateSelectionLabel() $("#node-input-selectionMethod").change(function() { updateSelectionLabel(); }); $("#circuit-busy-message-row").hide(); $("#circuit-failed-message-row").hide(); function doesMobiusServiceExist () { let srvc = $("#node-input-mobius").val(); if (srvc === '_ADD_') { $("#node-lookup-circuit").hide(); $("#circuit-message-row").show(); } else { $("#circuit-message-row").hide(); $("#node-lookup-circuit").show(); } } doesMobiusServiceExist(); $("#node-lookup-circuit").click(function() { $("#node-lookup-circuit").addClass('disabled'); $("#circuit-row").hide(); $("#circuit-busy-message-row").show(); $("#circuit-failed-message-row").hide(); let mobiusSrvc = $("#node-input-mobius").val(); let mobiusHID = $("#node-input-hid").val(); let mobiusSPID = "0032"; $.getJSON(`mservicediscover?mobius=${mobiusSrvc}&hid=${mobiusHID}&spid=${mobiusSPID}`,function(services) { $("#node-lookup-circuit").removeClass('disabled'); $("#circuit-busy-message-row").hide(); $("#circuit-row").show(); $("#node-input-circuit").autocomplete({ source: services, minLength: 0, close: function( event, ui ) { $("#node-input-circuit").autocomplete('destroy'); } }).autocomplete('search',''); }) .fail((err) => { $("#node-lookup-circuit").removeClass('disabled'); $("#circuit-busy-message-row").hide(); $("#circuit-row").show(); $("#circuit-failed-message-row").show(); }); }); } }); </script> <script type="text/html" data-help-name="dali control command generator"> <p>MOBiUS DALI Lighting Control Command Generator.</p> <h3>Configuration Page</h3> <dl class="message-properties"> <dt>DALI Connection <span class="property-type">connection</span></dt> <dd>The connection to an instance of the DALI circuit service representing the working DALI circuit.</dd> <dt>Command Type <span class="property-type">choice</span></dt> <dd>The DALI command to be generated.</dd> <dt>Addressing Mode <span class="property-type">choice</span></dt> <dd>The DALI addressing mode, short / group / broadcast.</dd> <dt>Selection Method <span class="property-type">choice</span></dt> <dd>The method to select DALI fittings.</dd> <dt>DALI Address / Instance <span class="property-type">number</span></dt> <dd>If DALI Address selection is used: Short addressing (0-63), Group addressing (0-15).</dd> <dd>If object instances selection is used: The Mobius object instance number (0001-003F).</dd> <dt>Lighting Level<span class="property-type">number</span></dt> <dd>The desired lighting level (0-100%). Note: Only active when 'Lighting Level Control' command is used.</dd> </dl> <h3>Input: </h3> <dl class="message-properties"> <dd>Any input message will trigger the node to generate the set command.</dd> <dt>payload.level <span class="property-type">number</span></dt> <dd>An optional property used if the 'Lighting Level Control' command is being used. If set, this input property will overide the lighting level set within the node. (0-100%)</dd> </dl> <h3>Details</h3> <p>Generates DALI commands relating to lighting control. Does not include DALI device configuration or DALI device querying commands.</p> <p align="center" style="color:#000080">iaconnects © 2020</p> <br> <p align="center" style="color:#000080">ER 2020</p> </script>