Skip to content

Commit

Permalink
added online node, only controls shown regarding room/category on nod…
Browse files Browse the repository at this point in the history
…e editing

fixes #5
  • Loading branch information
codmpm committed Apr 3, 2017
1 parent c4f734a commit 1e4ea08
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 17 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### 0.2.0
* added online node
* only controls shown regarding room/category on node editing
* updated `node-lox-ws-api` to 0.2.8
* updated `ws` to 2.2.3

### 0.1.0
* breaks compatibility to 0.0.x
* updated `node-lox-ws`

### 0.0.x
* control-in
* control-out
* initial release
* testing
22 changes: 8 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ is possible. It is kept alive via `node-lox-ws-api`.
As I don't have an own Loxone installation, I can't do a "real world" test.
Gladly a friend of mine lent me his spare miniserver for initial testing.

Tested with loxone-config V8.1.11.11, node-red 0.16.2, nodeJS 6.10.0 LTS
Tested with loxone-config V8.3.3.21, node-red 0.16.2, nodeJS 6.10.1 LTS

### Working parts so far
* Configure a miniserver connection
* Miniserver: Configure a miniserver connection
* Control-In: Select a control and a state to hook an event which then gets passed to node-red on occurence.
* Control-Out: Select a control and feed it commands according to the [structure file](https://www.loxone.com/dede/wp-content/uploads/sites/2/2016/08/loxone-structure-file.pdf?x48792)
* Webservice: Send direct webservice call through the existing websocket, see the [webservice documenation](https://www.loxone.com/enen/kb/web-services/).
* Webservice: Send direct webservice calls through the existing websocket, see the [webservice documenation](https://www.loxone.com/enen/kb/web-services/).
Please use URI's in form of `jdev/sps/io/foo` (no leading `/`), simply replace `dev/` from the documentation with `jdev/`. The returned
value will be in `msg.payload`.
* Online: Emit's `true`/`false` for the state of the connection to the selected miniserver. Be careful as every failed
connection attempt sends a `false` over and over again till a connection could be established.

The structure file can be retrieved via `http://<miniserver>/data/LoxAPP3.json`.

Expand Down Expand Up @@ -88,22 +90,12 @@ an example via the webservice-node. See a short video here: https://cloud.codm.d

### Currently partially working, caveats

* ~~The "connected" info under the node in the editor is buggy atm~~
* ~~On initial configuration you have to deploy first, so that the runtime can connect to the MS, in order
to load the structure file so you can select controls~~
* Only `controls` are parsed, no `mediaServer`, `weatherServer`, etc.
Is this enough?
* ~~No `subcontrols`, yet~~
* ~~UpDownLeftRight digital/analog are not working at the moment~~ - solved with the webservice node

* Events can only be generated by control-in

### ToDo
* Convenience / Testing!
* ~~Connection handling on first configuration~~
* ~~More info in `msg`-object based on structure file~~
* ~~Configuration of the encryption method - currently only "Hash"~~
* ~~Loxone-Out~~ needs testing
* ~~SubControls~~ needs testing
* better logging, more failsaveness, more user info
* See `TODO` comments in the code
* ...
Expand Down Expand Up @@ -132,6 +124,8 @@ I'm not affiliated with [Loxone](https://www.loxone.com/) in any way.
Many thanks to [Nick O'Leary](https://github.com/knolleary), [Dave Conway-Jones](https://github.com/dceejay/)
and everyone else from the node-red Slack-Channel.

Also the people from the ever helpful [LoxForum](https://www.loxforum.com/) have to be mentioned.

### License
MIT

51 changes: 51 additions & 0 deletions loxone/loxone.html
Original file line number Diff line number Diff line change
Expand Up @@ -598,3 +598,54 @@
});
</script>



<script type="text/x-red" data-help-name="loxone-online">
<p>
This node simply outputs <code>true</code> or <code>false</code> in
<code>msg.payload</code> when the miniserver comes online or goes offline.
</p>

</script>


<script type="text/x-red" data-template-name="loxone-online">

<div class="form-row">
<label for="node-input-miniserver">
<i class="fa fa-globe"></i>
Miniserver
</label>
<input type="text" id="node-input-miniserver">
</div>

<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">
<span id="return-msg"></span>
</div>

</script>

<script type="text/javascript">
RED.nodes.registerType('loxone-online', {
category: 'loxone',
paletteLabel: 'online',
color: '#83B817',
defaults: {
name: {value: ''},
miniserver: {type: 'loxone-miniserver', required: true},
},
inputs: 0,
outputs: 1,
icon: "loxone.png",
align: "left",
label: function () {
return this.name || "online";
}
});
</script>

39 changes: 39 additions & 0 deletions loxone/loxone.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ module.exports = function (RED) {
node.connection = client;

node.setConnectionState("green", "connected", "dot");
sendOnlineMsg(true);
});

client.on('connect_failed', function () {
Expand All @@ -142,6 +143,7 @@ module.exports = function (RED) {

client.on('connection_error', function (error) {
node.error('Miniserver connection error: ' + error);
node.setConnectionState("red", "connection error", "ring");
});

client.on('close', function () {
Expand All @@ -151,6 +153,7 @@ module.exports = function (RED) {
node.connection = null;

node.setConnectionState("yellow", "connection closed", "ring");
sendOnlineMsg(false);
});

client.on('send', function (message) {
Expand Down Expand Up @@ -233,10 +236,12 @@ module.exports = function (RED) {
client.once('close', function () {
done();
});

client.abort();
} else {
done();
}
sendOnlineMsg(false);
});

}
Expand Down Expand Up @@ -388,6 +393,30 @@ module.exports = function (RED) {
return structure;
};

function sendOnlineMsg(online) {

online = online || false;

RED.nodes.eachNode(function (theNode) {

if (theNode.type == 'loxone-online') {

var node = RED.nodes.getNode(theNode.id);

node.status({
fill: (online) ? 'green' : 'yellow',
shape: 'dot',
text: (online) ? 'online' : 'offline'
});

node.send({
payload: online
});
}
});

}

function LoxoneControlInNode(config) {

RED.nodes.createNode(this, config);
Expand Down Expand Up @@ -484,4 +513,14 @@ module.exports = function (RED) {

RED.nodes.registerType('loxone-webservice', LoxoneWebServiceNode);


function LoxoneOnlineNode(config) {
RED.nodes.createNode(this, config);
var node = this;
node.miniserver = RED.nodes.getNode(config.miniserver);
}

RED.nodes.registerType('loxone-online', LoxoneOnlineNode);


};
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-loxone",
"version": "0.1.0",
"version": "0.2.0",
"description": "Connecting the Loxone Miniserver to node-red via Websocket API",
"license": "MIT",
"keywords": [
Expand All @@ -12,8 +12,8 @@
}
},
"dependencies": {
"ws": "^1.0.1",
"node-lox-ws-api": "^0.2.7"
"ws": "^2.2.3",
"node-lox-ws-api": "^0.2.8"
},
"repository": "codmpm/node-red-contrib-loxone"
}

0 comments on commit 1e4ea08

Please sign in to comment.