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

195 lines
10 KiB
HTML
Raw Normal View History

2018-01-07 22:21:26 +00:00
<!-- Config Node -->
2018-01-06 14:11:37 +00:00
<script type="text/javascript">
RED.nodes.registerType('tradfri-connection',{
category: 'config',
defaults: {
address: { value:"", required:true },
2018-01-07 22:21:26 +00:00
name: { value:"" }
},
credentials: {
securityCode: { type:"text" },
identity: { type:"text" },
psk: { type:"text" }
2018-01-06 14:11:37 +00:00
},
label: function() {
return this.name || "tradfri@" + this.address;
}
});
</script>
<script type="text/x-red" data-template-name="tradfri-connection">
<div class="form-row">
2018-01-07 22:21:26 +00:00
<label for="node-config-input-address"><i class="fa fa-globe"></i> Address</label>
2018-01-06 14:11:37 +00:00
<input type="text" id="node-config-input-address">
</div>
<div class="form-row">
2018-01-07 22:21:26 +00:00
<label for="node-config-input-securityCode"><i class="fa fa-gears"></i> Security Code</label>
2018-01-06 14:11:37 +00:00
<input type="text" id="node-config-input-securityCode">
</div>
<div class="form-row">
2018-01-07 22:21:26 +00:00
<label for="node-config-input-identity"><i class="fa fa-address-card-o"></i> Identity</label>
2018-01-06 14:11:37 +00:00
<input type="text" id="node-config-input-identity">
</div>
<div class="form-row">
2018-01-07 22:21:26 +00:00
<label for="node-config-input-psk"><i class="fa fa-lock"></i> Pre-shared key</label>
2018-01-06 14:11:37 +00:00
<input type="text" id="node-config-input-psk">
</div>
2018-01-07 22:21:26 +00:00
<div class="form-row">
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-config-input-name">
</div>
2018-01-06 14:11:37 +00:00
</script>
2018-01-07 22:21:26 +00:00
<script type="text/x-red" data-help-name="tradfri-connection">
<ul>
<li><i class="fa fa-globe"></i> <b>Address:</b> The address to your gateway.</li>
<li><i class="fa fa-gears"></i> <b>Security code:</b> The security code on the backside of your gateway. You only need to enter this if you <em>don't</em> have an identiy and PSK. In that case identity and PSK will be generated for you using the security key.</li>
<li><i class="fa fa-address-card-o"></i> <b>Address:</b> The identiy used to access the gateway. Used together with a PSK.</li>
<li><i class="fa fa-lock"></i> <b>Pre-shared key:</b> The passkey used to access the gateway. Used together with an identity.</li>
</ul>
</script>
<!--- I/O Node -->
2018-01-06 14:11:37 +00:00
<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',
2018-01-07 22:21:26 +00:00
color: '#9FE597',
2018-01-06 14:11:37 +00:00
defaults: {
name: {value:""},
deviceId: {value: "", required:true, validate:RED.validators.number()},
deviceName: {value: ""},
connection: {value:"", type:"tradfri-connection"},
observe: { value:true, required: true },
},
2018-01-07 22:21:26 +00:00
align: 'right',
2018-01-06 14:11:37 +00:00
inputs:1,
outputs:1,
2018-01-07 22:21:26 +00:00
icon: 'light.png',
2018-01-06 14:11:37 +00:00
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">
2018-01-07 22:21:26 +00:00
<label for="node-input-connection"><i class="fa fa-cog"></i> Connection</label>
2018-01-06 14:11:37 +00:00
<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>
2018-01-07 22:21:26 +00:00
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
2018-01-06 14:11:37 +00:00
</script>
<script type="text/x-red" data-help-name="tradfri">
<p>Interface for IKEA Tradfri devices</p>
<h3>Inputs</h3>
<dl class="message-properties">
2018-01-07 22:21:26 +00:00
<dt> payload <span class="property-type"> string | object</span> </dt>
<dd> The payload can either be a single command to the node (such as a status update request) sent as a string or an object with one or more commands targeting the light.</dd>
2018-01-06 14:11:37 +00:00
</dl>
<h3>Outputs</h3>
<dl class="message-properties">
2018-01-07 22:21:26 +00:00
<dt> payload <span class="property-type"> object </span></dt>
2018-01-06 14:11:37 +00:00
<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.
2018-01-07 22:21:26 +00:00
<h2>Controlling the node</h2>
Nodes can be programmatically controlled by sending a message with <code>msg.payload</code> set to one of the following strings:
<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>
<h2>Observing</h2>
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:
2018-01-06 14:11:37 +00:00
<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>
</script>