node-red-contrib-mobius-flow-dali
Version:
Node-RED nodes to work with MOBiUSFlow and DALI devices
302 lines (289 loc) • 12.6 kB
HTML
<!--
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 config 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='32'>Reset</option>
<option value='33'>Store Actual Level in DTR</option>
<option value='42'>Store DTR as Max Level</option>
<option value='43'>Store DTR as Min Level</option>
<option value='44'>Store DTR as System Failure Level</option>
<option value='45'>Store DTR as Power On Level</option>
<option value='46'>Store DTR as Fade Time</option>
<option value='47'>Store DTR as Fade Rate</option>
<option value='96'>Add to Group(s)</option>
<option value='112'>Remove from Group(s)</option>
<option value='128'>Store DTR as Short Address</option>
<option value='129'>Enable Write Memory</option>
</select>
</div>
<div id="group-num">
<div class="form-row">
<label for="node-input-groupNo" style="width: 160px;"><i class="fa fa-users"></i> Group Number(s)</label>
<input type="text" id="node-input-groupNo" style="width: 300px;">
</div>
</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>
<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 addressValidator (v) {
console.log('Address validator running');
return false;
}
function getLabel(conNode) {
return RED.nodes.node(conNode).name
}
RED.nodes.registerType('dali config 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})$/)},
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;
}
}
}},
groupNo: {required:true, value: '0', validate: (v) => {
var re = /^(([0-9]|[1][0-5])([-]([0-9]|[1][0-5])|))((|[,](|[ ])((([0-9]|[1][0-5])([-]([0-9]|[1][0-5])|))))+)$/g;
return re.test(v);
}},
selectionMethod: {value: 'ins', required: true}
},
inputs: 1,
outputs: 0,
icon: 'dali-icon.png',
align: 'left',
paletteLabel: 'dali send configuration command',
label: function() {
const commandLookup = {
33: 'Store Actaul Level in the DTR',
42: 'Store the DTR as Max Level',
43: 'Store the DTR as Min Level',
44: 'Store the DTR as System Failure Level',
45: 'Store the DTR as Power on Level',
46: 'Store the DTR as Fade Time',
47: 'Store the DTR as Fade Rate',
96: 'Add to Group(s)',
112: 'Remove from Group(s)',
128: 'Store DTR As Short Address',
129: 'Enable Write Memory',
}
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 Configuration 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() === '96' || $("#node-input-command").val() === '112') {
$("#group-num").show();
} else {
$("#group-num").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 config command generator">
<p>MOBiUS DALI Configuration 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 the DALI Circuit.</dd>
<dt>Command Type <span class="property-type">choice</span></dt>
<dd>The DALI command to be generated.</dd>
<dt>Group Number<span class="property-type">number</span></dt>
<dd>The DALI group number to add object to or remove object from (0-15). Note: Only active when either the 'Add to Group' or the 'Remove from Group' command is used.</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>
</dl>
<h3>Input: </h3>
<dl class="message-properties">
<dd>Any input message will trigger the node to generate the set command.</dd>
</dl>
<h3>Details</h3>
<p>Generates DALI commands relating to DALI object configuration. Does not include DALI lighting 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>