UNPKG

node-red-contrib-openhab

Version:

Openhab connectivity nodes for node-red

273 lines (247 loc) 10.4 kB
<!-- // // Copyright (C) 2017 Michael Kolb // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. --> <!-- *************** Input Node *************** --> <script type="text/javascript"> $.getScript('openhab/bootstrap-multiselect/bootstrap-multiselect.js'); RED.nodes.registerType('openhab-input', { category: 'openhab', color: '#F3B567', defaults: { name: { value: "" }, simpleitem: { value: false }, server: { type: "openhab-server", required: true }, filter: { value: null } }, inputs: 0, outputs: 1, outputLabels: ["event"], icon: "light.png", label: function() { return this.name || "openhab-input"; }, oneditprepare: function() { var filter=this.filter; $.getJSON("openhab-input/itemlist", function(data) { var htmlelement = $('#node-input-filter'); htmlelement.html(''); $.each(data, function(index, value) { var selected=$.inArray(value.name,filter) !== -1; htmlelement.append('<option value="' + value.name + '"'+(selected ? 'selected' : '')+'>' + value.name + '</option>'); }); htmlelement.multiselect({ enableFiltering: true, enableCaseInsensitiveFiltering: true, nonSelectedText: "Disable item filtering" }); }); }, oneditsave: function() { var selectedOptions = $('#node-input-filter option:selected'); if (selectedOptions) { this.filter = selectedOptions.map(function() { return $(this).val(); }); } else { this.filter=null; } } }); </script> <script type="text/x-red" data-template-name="openhab-input"> <style type="text/css"> .multiselect-clear-filter { display: none; } .multiselect-container input[type="checkbox"] { display: none } </style> <link rel="stylesheet" href="openhab/bootstrap-multiselect/bootstrap-multiselect.css" type="text/css" /> <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-server"><i class="icon-tag"></i> Server</label> <input type="text" id="node-input-server"> </div> <div class="form-row"> <label for="node-input-simpleitem"><i class="icon-tag"></i> Simple Item</label> <input type="checkbox" id="node-input-simpleitem" style="display: inline-block; width: auto; vertical-align: top;"> Use simple item name instead of full path</input> </div> <div class="form-row"> <label for="node-input-filter"><i class="icon-tag"></i> Items</label> <select id="node-input-filter" multiple> </select> </div> </script> <script type="text/x-red" data-help-name="openhab-input"> <p>This node listens for events (state changes / commands) sent to your openhab items.</p> <b>Configuration</b><br> <ul> <li><b>Name:</b> Choose any name to identify your node.</li> <li><b>Server:</b> Choose the openhab server instance to use.</li> <li><b>Simple Item:</b> If checked, the topic contains the simple item name <code>Daylight</code> instead of the fully item path <code>smarthome/items/Daylight/state</code>.</li> <li><b>Items:</b> Select the items to listen to. If none is selected, the node will listen to all items.</li> </ul> <b>Output</b><br> <ul> <li>The <code>msg.payload</code> of your message contains information about the change. e.g. <code>{"type":"OnOffType","value":"ON"}</code></li> <li>The <code>msg.topic</code> contains the item name. See config parameter <i>Simple Item</i> for a description of the format.</li> </ul> <b>Status</b><br> <ul> <li>The node indicates the connection status to openhab via a status indicator.</li> </ul> </script> <!-- *************** Output Node *************** --> <script type="text/javascript"> RED.nodes.registerType('openhab-output', { category: 'openhab', color: '#F3B567', align: 'right', defaults: { name: { value: "" }, server: { type: "openhab-server", required: true }, typ: { value: "", required: true }, itemname: { value: "", required: true } }, inputLabels: "event", inputs: 1, outputs: 0, icon: "light.png", label: function() { return this.name || "openhab-output"; }, oneditprepare: function() { $.getJSON("openhab-output/itemlist", function(data) { var htmlelement = $('#node-input-itemname'); htmlelement.html(''); htmlelement.append("<optgroup label=\"Nodered\"><option value=\"msg.topic\">Use msg.topic</option></optgroup>"); htmlelement.append("<optgroup label=\"Openhab Items\" id=\"node-input-itemname-optgroup\"></optgroup>"); $.each(data, function(index, value) { $('#node-input-itemname-optgroup').append("<option value=\"" + value.name + "\">" + value.name + ":" + value.type + " (" + value.label + ")</option>"); }); }); } }); </script> <script type="text/x-red" data-template-name="openhab-output"> <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-server"><i class="icon-tag"></i> Server</label> <input type="text" id="node-input-server"> </div> <div class="form-row"> <label for="node-input-typ"><i class="icon-tag"></i> Type</label> <select id="node-input-typ"> <option value="state" selected>State</option> <option value="command">Command</option> </select> </div> <div class="form-row"> <label for="node-input-itemname"><i class="icon-tag"></i> Item Name</label> <select id="node-input-itemname"> </select> </div> </script> <script type="text/x-red" data-help-name="openhab-output"> <p>This node updates a state or sends a command to an item. The node uses the openhab REST-API to accomplish this.</p> <b>Configuration</b><br> <ul> <li><b>Name:</b> Choose any name to identify your node.</li> <li><b>Server:</b> Choose the openhab server instance to use.</li> <li><b>Type:</b> Choose whether the node should set the <code>state</code> of the choosen item, or send a <code>command</code> to it.</li> <li><b>Item:</b> Select the name of the item to send your command / state to. If you choose <code>Use msg.topic</code> the topic of the input message will be used as item name. The list of openhab items is retrieved via a rest call. It refreshes every time you open up the configuration menu.</li> </ul> <b>Input</b><br> <ul> <li>The <code>msg.payload</code> of your message is used as command / state.</li> <li>The <code>msg.topic</code> is used as item name (if you selected the appropiate option in the item dropdown).</li> </ul> </script> <!-- *************** Server Node *************** --> <script type="text/javascript"> RED.nodes.registerType('openhab-server', { category: 'config', defaults: { name: { value: null, required: false }, url: { value: null, required: true, validate: RED.validators.regex(/https?:\/\/.+\/rest\//) }, allowuntrusted: { value: false, required: true } }, label: function() { return this.name ||  this.url; } }); </script> <script type="text/x-red" data-template-name="openhab-server"> <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-url"><i class="icon-bookmark"></i> URL</label> <input type="text" id="node-config-input-url"> </div> <div class="form-row"> <label for="node-config-input-allowuntrusted"><i class="icon-tag"></i> SSL</label> <input type="checkbox" id="node-config-input-allowuntrusted" style="display: inline-block; width: auto; vertical-align: top;"> Do not validate SSL Server Certificate</input> </div> </script> <script type="text/x-red" data-help-name="openhab-server"> <b>Configuration</b><br> <ul> <li><b>Name:</b> Choose any name to identify your server.</li> <li><b>URL:</b> The URL to the REST-API of your openhab instance. Make sure to include the trailing slash in your URL. Example: <code>http://localhost:8080/rest/</code></li> <li><b>SSL:</b> Activate to disable SSL Certificate validation. e.g. for using a self signed certificate</li> </ul> </script>