node-red-contrib-nuki
Version:
Interact with your nuki bridge locally
297 lines (273 loc) • 8.23 kB
HTML
<script type="text/javascript">
function disableChangeEvents() {
$('#node-input-bridge, #node-input-nuki').off('change');
}
function getNukiList(callback) {
var configNodeId = $('#node-input-bridge').val();
var node = RED.nodes.node(configNodeId);
var path = RED.settings.httpNodeRoot;
$('#return-msg').html('').css({});
var userMsg = 'No bridge selected or connected!';
var userMsgCss = {
'color': '#ad1625',
'font-weight': 'bold'
};
var $nukiSelect = $('#node-input-nuki');
$nukiSelect.empty();
$nukiSelect.append('<option value=""></option>');
if (node) {
var url = path + 'nuki-bridge/list?id=' + node.id;
$.getJSON(url)
.done(function (data) {
var userMsgCss = {
'color': '#49db3c'
};
for (var i = 0; i < data.items.length; ++i) {
var n = data.items[i];
$nukiSelect.append('<option value="' + n.id + '">' + n.name + '</option>');
}
$('#return-msg').html(data.msg).css(userMsgCss);
callback(data);
});
} else {
$('#return-msg').html(userMsg).css(userMsgCss);
}
}
</script>
<script type="text/markdown" data-help-name="nuki-lock-control">
This node enables communication to a Nuki Smart Lock. At the moments 2 topics are supported:
* lockStatus
* lockAction
The lockAction requires the payload to be valid range of:
* LOCK
* UNLOCK
* UNLATCH
* LOCK_N_GO
* LOCK_N_GO_WITH_UNLATCH
* webInfo
Here's an example of the lockStatus **msg** input:
```
{
payload: "",
topic: "lockStatus"
}
```
Here's an example of the lockAction **msg** input:
```
{
payload: "LOCK" ,
topic: "lockAction"
}
```
For more examples/values go to [documentation](https://github.com/mabunixda/node-red-contrib-nuki/")
</script>
<script type="text/x-red" data-template-name="nuki-lock-control">
<div class="form-row">
<label for="node-input-bridge">
<i class="fa fa-globe"></i>
Bridge
</label>
<input type="text" id="node-input-bridge">
</div>
<div class="form-row">
<label for="node-input-nuki fa-lock">
<i class="icon-home"></i>
Nuki
</label>
<select id="node-input-nuki">
</select>
<input type="hidden" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-config-input-clearCallbacks"><i class="fa fa-server"></i>Clear Callbacks</label>
<input type="checkbox" id="node-config-input-clearCallbacks" placeholder="true">
</div>
<div class="form-row">
<span id="return-msg"></span>
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('nuki-lock-control', {
category: 'nuki',
paletteLabel: 'nuki-lock-control',
color: '#aaaaaa',
defaults: {
name: {
value: ''
},
nuki: {
value: '',
required: true
},
clearCallbacks: {
value: true,
required: false
},
bridge: {
type: 'nuki-bridge',
required: true
}
},
inputs: 1,
outputs: 1,
icon: "nuki-smart-lock.svg",
label: function () {
return this.name || "nuki control in";
},
oneditprepare: function () {
var node = this;
prepareInput();
$('#node-input-bridge').on('change', prepareInput);
function prepareInput() {
disableChangeEvents();
getNukiList(function (data) {
var $nukiSelect = $('#node-input-nuki');
$nukiSelect.val(node.nuki);
})
selectName();
};
},
oneditsave: function () {
var val = $('#node-input-nuki option:selected').text()
$('#node-input-name').val(val);
},
oneditcancel: function () {
disableChangeEvents();
}
});
</script>
<script type="text/markdown" data-help-name="nuki-bridge-control">
This node enables communication to a Nuki Bridge. At the moments following topics are supported:
* reboot
* fwupdate
* info
* log
* clearlog
* list
For more examples/values go to [documentation](https://github.com/mabunixda/node-red-contrib-nuki/")
</script>
<script type="text/x-red" data-template-name="nuki-bridge-control">
<div class="form-row">
<label for="node-input-bridge">
<i class="fa fa-globe"></i>
Bridge
</label>
<input type="text" id="node-input-bridge">
</div>
<input type="hidden" id="node-input-name" placeholder="Name">
<div class="form-row">
<span id="return-msg"></span>
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('nuki-bridge-control', {
category: 'nuki',
paletteLabel: 'nuki bridge in',
color: '#aaaaaa',
defaults: {
name: {
value: ''
},
bridge: {
type: 'nuki-bridge',
required: true
}
},
inputs: 1,
outputs: 1,
icon: "nuki-bridge.svg",
label: function () {
return this.name || 'bridge control';
},
oneditprepare: function () {
var node = this;
$('#node-input-bridge').on('change', selectName);
function selectName() {
var val = $('#node-input-bridge option:selected').text()
$('#node-input-name').val(val);
}
}
});
</script>
<script type="text/markdown" data-help-name="nuki-bridge">
This configuration node enables communication with a Nuki Bridge.
## Bridge API
Documentation about enabling the HTTP API on a Nuki Bridge can by found [online](https://github.com/mabunixda/node-red-contrib-nuki/tree/main#nuki-bridge-api).
## Web API Configuration
And also how to setup the Nuki Web API can be found [here](https://github.com/mabunixda/node-red-contrib-nuki/tree/main#nuki-web-api)
</script>
<script type="text/x-red" data-template-name="nuki-bridge">
<div class="form-row node-input-bridge">
<label for="node-config-input-host">
<i class="fa fa-globe"></i> Bridge
</label>
<input class="input-append-left" type="text" id="node-config-input-host" placeholder="hostname/ip" style="width: 40%;" >
<label for="node-config-input-port" style="margin-left: 10px; width: 35px;">
Port
</label>
<input type="text" id="node-config-input-port" style="width:45px" placeholder="8080">
</div>
<div class="form-row">
<label for="node-config-input-token"><i class="fa fa-user"></i> Token</label>
<input type="password" id="node-config-input-token">
</div>
<div class="form-row">
<label for="node-config-input-token"><i class="fa fa-server"></i> Bridge Callback Host</label>
<input type="text" id="node-config-input-callbackHost" placeholder="http://node-red/">
</div>
<div class="form-row">
<label for="node-config-input-clearCallbacks"><i class="fa fa-server"></i>Clear Callbacks</label>
<input type="checkbox" id="node-config-input-clearCallbacks" placeholder="true">
</div>
<div class="form-row">
<label for="node-config-input-webToken"><i class="fa fa-user"></i> WEB API Token</label>
<input type="password" id="node-config-input-webToken">
</div>
<div class="form-row">
<label for="node-config-input-webToken"><i class="fa fa-clock-o"></i> WEB API Fetch Interval</label>
<input type="text" id="node-config-input-webUpdateTimeout">
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('nuki-bridge', {
category: 'config',
defaults: {
host: {
value: "",
required: true
},
port: {
value: 8080,
required: true,
validate: RED.validators.number()
},
callbackHost: {
value: "",
required: false
},
clearCallbacks: {
value: true,
required: false
},
webUpdateTimeout: {
value: 30,
required: false,
validate: RED.validators.number()
}
},
credentials: {
token: {
type: "password",
required: true
},
webToken: {
type: "password",
required: false
}
},
icon: "nuki-bridge.svg",
label: function () {
return this.host + ':' + this.port;
}
});
</script>