node-red-contrib-node-tradfri/dist/node-tradfri.html

184 lines
9.2 KiB
HTML
Executable File

<!-- ======= CONNECTION ========= -->
<script type="text/javascript">
RED.nodes.registerType('tradfri-connection',{
category: 'config',
defaults: {
name: { value:"" },
address: { value:"", required:true },
securityCode: { value:"" },
identity: { value:"" },
psk: { value:"" },
},
label: function() {
return this.name || "tradfri@" + this.address;
}
});
</script>
<script type="text/x-red" data-template-name="tradfri-connection">
<div class="form-row">
<label for="node-config-input-name"><i class="icon-bookmark"></i> Name</label>
<input type="text" id="node-config-input-name">
</div>
<div class="form-row">
<label for="node-config-input-address"><i class="icon-bookmark"></i> Address</label>
<input type="text" id="node-config-input-address">
</div>
<div class="form-row">
<label for="node-config-input-securityCode"><i class="icon-bookmark"></i> Security Code</label>
<input type="text" id="node-config-input-securityCode">
</div>
<div class="form-row">
<label for="node-config-input-identity"><i class="icon-bookmark"></i> Identity</label>
<input type="text" id="node-config-input-identity">
</div>
<div class="form-row">
<label for="node-config-input-psk"><i class="icon-bookmark"></i> Pre-shared key</label>
<input type="text" id="node-config-input-psk">
</div>
</script>
<!-- ======= THREADFREE ========= -->
<script type="text/javascript">
var updateDevices = (currentDeviceId) => {
let configNodeId = $('#node-input-connection').find(":selected").val();
if (configNodeId == null || configNodeId === '_ADD_') { return; }
$.get('tradfri/lights', {nodeId: configNodeId}, function(resp){
let lights = JSON.parse(resp);
if (!Array.isArray(lights) || lights.length <= 0) { return; }
$('#node-input-deviceId').find('option').not(':first').remove();
$.each(lights, function(i, light) {
let opt = {};
opt.value = light.id;
opt.text = light.name;
if (light.id === currentDeviceId) {
opt.selected = "selected";
}
$('#node-input-deviceId').append($('<option>', opt));
});
});
};
RED.nodes.registerType('tradfri',{
category: 'function',
color: '#84E87A',
defaults: {
name: {value:""},
deviceId: {value: "", required:true, validate:RED.validators.number()},
deviceName: {value: ""},
connection: {value:"", type:"tradfri-connection"},
observe: { value:true, required: true },
},
inputs:1,
outputs:1,
icon: "light.png",
label: function() {
return this.deviceName || "tradfri";
},
oneditprepare: function() {
var node = this;
$('#node-input-connection').change(function(){
updateDevices(node.deviceId);
});
$('#tradfri-deviceId-refresh').click(function(){
updateDevices(node.deviceId);
});
$(document).ready(function() {
$('#node-input-msgPassthrough').prop('checked', node.observe);
});
},
oneditsave: function() {
this.deviceName = $('#node-input-deviceId').find(":selected").text();
}
});
</script>
<script type="text/x-red" data-template-name="tradfri">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-connection"><i class="fa fa-bookmark"></i> Connection</label>
<input type="text" id="node-input-connection" placeholder="Connection">
</div>
<div class="form-row">
<label for="node-input-deviceId"><i class="fa fa-lightbulb-o"></i> Device</label>
<div style="display: inline-block; position: relative; width: 70%; height: 20px;">
<div style="position: absolute; left: 0px; right: 40px;">
<select id="node-input-deviceId" style="width: 100%">
<option value="-1" selected="selected">None</option>
</select>
</div>
<a id="node-input-lookup-connection" class="editor-button" style="position: absolute; right: 0px; top: 0px;"><i id="tradfri-deviceId-refresh-spinner" class="fa fa-refresh"></i></a>
</div>
</div>
<div class="form-row">
<label>&nbsp;</label>
<input type="checkbox" id="node-input-observe" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-observe" style="width: 70%;" >Observe device?</label>
</div>
</script>
<script type="text/x-red" data-help-name="tradfri">
<p>Interface for IKEA Tradfri devices</p>
<h3>Inputs</h3>
<dl class="message-properties">
<dt> payload <span class="property-type"> string </span> </dt>
<dd> A single command can be sent as a string to the node. <dd>
<dt> payload <span class="property-type"> object </span> </dt>
<dd> An object with one or more commands targeting the light. </dd>
</dl>
<h3>Outputs</h3>
<dl class="message-properties">
<dt> payload.light <span class="property-type"> object </span></dt>
<dd> The status of the light. </dd>
</dl>
<h3>Details</h3>
The tradfri node acts as both input and output for a IKEA Tradfri lighbulb.
If the node is set to observe it will send a message with the lights current properties as payload every time the light is updated:
<ul>
<li><code>id</code><code>number</code> The id of the light </li>
<li><code>name</code><code>string</code> The given name of the light </li>
<li><code>model</code><code>string</code> The model of the light </li>
<li><code>firmware</code><code>string</code> The firmware of the light </li>
<li><code>alive</code><code>boolean</code> True if the gateway can communicate with the light, false if not </li>
<li><code>on</code><code>boolean</code> True if the light is on, false if not.</li>
<li><code>brightness</code><code>number</code><code>[0,100]</code> The brightness of the light</li>
<li><code>colorTemperature</code><code>number</code>[0,100] The color temperature of the light</li>
<li><code>color</code><code>string</code> The hex-code for the color of the light. Only fully supported by CWS bulbs.</li>
<li><code>colorX</code><code>number</code> The x component of the xy-color</li>
<li><code>colorY</code><code>number</code> The y component of the xy-color</li>
<li><code>transition</code><code>number</code> The default transition time for operations. However, since the default value of 0.5 makes it impossible to send temperature and brightness updates in the same command, this is overridden and set to 0 by default.</li>
<li><code>created</code><code>number</code> Probably when the light was paired with the gateway for the first time, measured in epoch time.</li>
<li><code>seen</code><code>number</code> When the light was last interacted with by the gateway (or similar), measured in epoch time.</li>
<li><code>type</code><code>number</code> The type of device where 2 is light</li>
<li><code>power</code><code>number</code> The type of power source powering the light. Will most likely always be 1.</li>
</ul>
<h2>Controlling the node</h2>
The can be programmatically controlled by sending a message with <code>msg.payload</code> set to one of the following:
<ul>
<li><code>status</code> The node will output the current status of its target light.
</ul>
<h2>Controlling the lights</h2>
Lights can be controlled by sending an objet with one or more of the following properties as <code>msg.payload</code> to the node.
<ul>
<!-- <li><code>id</code><code>number</code> The id of the light <li>
<li><code>name</code><code>string</code> The given name of the light <li> -->
<li><code>on</code><code>boolean</code><li> Turn the light on or off.</li>
<li><code>brightness</code><code>number</code> The brightness of the light [0,100]</li>
<li><code>colorTemperature</code><code>number</code> The color temperature of the light [0,100]</li>
<li><code>color</code><code>string</code> Sets the color of the light. For WS-bulbs, <code>F5FAF6</code>, <code>F1E0B5</code> and <code>EFD275</code> will set the light to the default cold, normal and warm temperatures respectively.</li>
<li><code>transition</code><code>number</code> The default transition time for operations. Will only work for single operation commands and not for on/off. Defaults to 0. </li>
<li><code>hue</code><code>number</code> Sets the hue of the light. Only for CWS. [0,365] (UNTESTED)</li>
<li><code>saturation</code><code>number</code> Sets the saturation of the light. Only for CWS. [0,100] (UNTESTED)</li>
</ul>
</script>