forked from nidayand/node-red-contrib-norelite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnrl-tellstick.html
112 lines (105 loc) · 4.84 KB
/
nrl-tellstick.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!-- HTML -->
<script type="text/x-red" data-template-name="nrl-tellstick-out">
<div class="form-row">
<label for="node-input-code"><i class="fa fa-lightbulb-o"></i> Device</label>
<select id="node-input-code"/>
</div>
<div class="form-row">
<label> </label>
<input type="checkbox" id="node-input-dimmable" placeholder="Only" style="display: inline-block; width: auto; vertical-align: top;" disabled>
<label for="node-input-dimmable" style="width: 70%;">Dimmable</label>
</div>
<div class="form-row">
<label for="node-input-code"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name">
</div>
</script>
<script type="text/x-red" data-help-name="nrl-tellstick-out">
<p>Convert the Norelite payload into a format that is applicable for the <a href="https://github.com/emiloberg/node-red-contrib-tellstick">node-red-contrib-tellstick</a> input format</p>
<h3>Input</h3>
<dl class="message-properties">
<dt>payload <span class="property-type">object</span></dt>
<dd>Norelite message format. See References</dd>
</dl>
<h3>Output</h3>
<dl class="message-properties">
<dt>device specific instructions</dt>
<dd>Message content specific for the receiving hardware node</dd>
<dt>instruction <span class="property-type">object</span></dt>
<dd>Msg with Norelite message format in <code>msg.payload</code> from incoming payload. See References</dd>
</dl>
<h3>Settings</h3>
<dl class="message-properties">
<dt>Device</dt>
<dd>Select device or group to be controlled</dd>
<dt>Dimmable</dt>
<dd>Mark if the hardware device is dimmable</dd>
</dl>
<h3>Details</h3>
<p>Use the node just before the output node from <a href="https://github.com/emiloberg/node-red-contrib-tellstick">node-red-contrib-tellstick</a>.</p>
<p><a href="https://github.com/emiloberg/node-red-contrib-tellstick">node-red-contrib-tellstick</a> must have been deployed as a node prior to configuration so that one can get the devices to control in the configuration in this node.</p>
<p>When selecting a device the name is changed to the name of the device but can be modified.</p>
<p>All device information is to be configured in <a href="https://github.com/emiloberg/node-red-contrib-tellstick">node-red-contrib-tellstick</a> (e.g. if it is dimmable or not).</p>
<div></div>
<h3>References</h3>
<ul>
<li><a href="https://www.npmjs.com/package/node-red-contrib-norelite">Norelite</a></li>
</ul>
</script>
<script type="text/javascript">
var devices = null;
RED.nodes.registerType('nrl-tellstick-out', {
category: 'norelite_device-output',
color: "#A6BBCF",
defaults: {
name: {value: "", required: false},
code: {value: 1, required: true},
dimmable: {value: false, required: true},
devicename: {value: ""}
},
inputs: 1,
outputs: 1,
icon: "nrltellstick.png",
align: "right",
label: function() {
return (this.name || (this.devicename !== '' ? this.devicename : "undefined"));
},
oneditprepare: function(){
var self = this;
//Get the tellstick devices
var jqXHR = $.getJSON('tellstick/device');
jqXHR.fail(function(data) {
RED.notify('<strong>Tellstick error (err: 13)</strong>: ' + JSON.stringify(data.responseText), 'error');
});
jqXHR.done(function(data) {
if(data.length>0){
//Store devices for event management
devices = data;
//Add all options
data.forEach(function(device){
$('#node-input-code').append($('<option>', { value: device.id }).text(device.name));
});
$('#node-input-code').find('option[value="' + self.code + '"]').prop('selected', true);
//Add events on select change
$('#node-input-code').change(function(){
var val = $('#node-input-code').val();
//Find in device list
for (var i=0; i<devices.length; i++){
if (devices[i].id == val){
if (devices[i].methods.dim){
self.dimmable=true;
$('#node-input-dimmable').prop('checked', true);
} else {
self.dimmable=false;
$('#node-input-dimmable').prop('checked', false);
}
//Copy the name
self.devicename = devices[i].name;
}
}
});
}
});
}
});
</script>