Added info notes

This commit is contained in:
Harald Rietman
2017-07-03 22:41:43 +02:00
parent fc5270ad87
commit 7d7eaaa820
9 changed files with 243 additions and 81 deletions

29
README.md Normal file
View File

@@ -0,0 +1,29 @@
# node-red-contrib-xiaomi-devices
This module contains the following nodes to provide easy integration of the Xiaomi devices into node-red.
The following devices are currently supported:
* Temperature/humidity sensor
* Magnet switch
* Button switch
* Motion sensor
* Power plug (zigbee)
## Preperation
To receive the gateway json messages on your network you need to enable the developer mode, aka LAN mode in the gateway.
A UDP input node is needed to receive the json messages. An UDP output node to send command's to the gateway.
## Install
```
cd ~\.node-red
npm install node-red-contrib-xiaomi-devices
```
## Usage
Below a screenshot of an example use of all nodes.

View File

@@ -94,28 +94,49 @@
<script type="text/x-red" data-help-name="xiaomi-ht"> <script type="text/x-red" data-help-name="xiaomi-ht">
<p>The Xiaomi Humidity & Temperature sensor node</p> <p>The Xiaomi Humidity & Temperature sensor node</p>
<h3>Inputs</h3>
<dl class="message-properties"> <dl class="message-properties">
<dt class="mandatory">Gateway</dt> <dt>payload
<dd>The Gateway configuration node this sensor is attached.</dd> <span class="property-type">json</span>
<dt class="optional">Name</dt> </dt>
<dd>A descriptive name for this sensor.</dd> <dd>Gateway <code>sensor_ht</code> message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code></dd>
<dt class="mandatory">Device</dt> </dl>
<dd>The device to associate this node with. This device is configured in the Gateway configuration.</dd>
<dt class="mandatory">Output</dt> <h3>Outputs</h3>
<dd>Three output types are supported:</dd> <ol class="node-ports">
<li>Temperature output
<dl class="message-properties">
<dt>payload <span class="property-type">string | json</span></dt>
<dd>raw data, value or template.</dd>
</dl>
</li>
<li>Humidity output
<dl class="message-properties">
<dt>payload <span class="property-type">string | json</span></dt>
<dd>raw data, value or template.</dd>
</dl>
</li>
</ol>
<h3>Details</h3>
<p>The incoming json message is parsed if the type model is <code>sensor_ht</code> and
the <code>sid</code> matches the configured value for this device.</p>
<p>Three output types are supported:
<ul> <ul>
<li>Full data</li> <li>Full data</li>
<li>Just values</li> <li>Just values</li>
<li>Template</li> <li>Template</li>
</ul> </ul>
<dt class="mandatory">Full data</dt> </p>
<dd>Passes the complete object received from the gateway. Use this if you need the raw data.</dd>
<dt class="mandatory">Just values</dt> <h4>Full data</h4>
<dd>Only passes the values for humidity and temperature.</dd> <p>Passes the complete json object received from the gateway on output 1. Use this if you need the raw data.</p>
<dt class="mandatory">Template</dt> <h4>Just values</h4>
<dd>Use your own template to pass the values on. The template can contain <a href="http://mustache.github.io/mustache.5.html">mustache-style</a> tags. <p>Only passes the string values for temperature on output 1 and humidity on output 2.</p>
Any property from the data section of the full object can be used.</dd> <h4>Template</h4>
</dl> <p>Use your own template to pass the values on. The template can contain <a href="http://mustache.github.io/mustache.5.html">mustache-style</a> tags.
Any property from the data section of the full object can be used.</p>
<p>Sample message:</p> <p>Sample message:</p>
<p><pre> <p><pre>
{ {

View File

@@ -87,28 +87,43 @@
<script type="text/x-red" data-help-name="xiaomi-magnet"> <script type="text/x-red" data-help-name="xiaomi-magnet">
<p>The Xiaomi contact sensor node</p> <p>The Xiaomi contact sensor node</p>
<h3>Inputs</h3>
<dl class="message-properties"> <dl class="message-properties">
<dt class="mandatory">Gateway</dt> <dt>payload
<dd>The Gateway configuration node this sensor is attached.</dd> <span class="property-type">json</span>
<dt class="optional">Name</dt> </dt>
<dd>A descriptive name for this sensor.</dd> <dd>Gateway <code>magnet</code> message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code></dd>
<dt class="mandatory">Device</dt> </dl>
<dd>The device to associate this node with. This device is configured in the Gateway configuration.</dd>
<dt class="mandatory">Output</dt> <h3>Outputs</h3>
<dd>Three output types are supported:</dd> <ol class="node-ports">
<li>State output
<dl class="message-properties">
<dt>payload <span class="property-type">string | json</span></dt>
<dd>raw data, value or template.</dd>
</dl>
</li>
</ol>
<h3>Details</h3>
<p>The incoming json message is parsed if the type model is <code>magnet</code> and
the <code>sid</code> matches the configured value for this device.</p>
<p>Three output types are supported:
<ul> <ul>
<li>Full data</li> <li>Full data</li>
<li>Just values</li> <li>Just values</li>
<li>Template</li> <li>Template</li>
</ul> </ul>
<dt class="mandatory">Full data</dt> </p>
<dd>Passes the complete object received from the gateway. Use this if you need the raw data.</dd>
<dt class="mandatory">Just values</dt> <h4>Full data</h4>
<dd>Only passes the values <code>open</code> or <code>close</code></dd> <p>Passes the complete json object received from the gateway. Use this if you need the raw data.</p>
<dt class="mandatory">Template</dt> <h4>Just values</h4>
<dd>Use your own template to pass the values on. The template can contain <a href="http://mustache.github.io/mustache.5.html">mustache-style</a> tags. <p>Only passes the sting values <code>open</code> or <code>close</code>.</p>
Any property from the data section of the full object can be used.</dd> <h4>Template</h4>
</dl> <p>Use your own template to pass the values on. The template can contain <a href="http://mustache.github.io/mustache.5.html">mustache-style</a> tags.
Any property from the data section of the full object can be used.</p>
<p>Sample message:</p> <p>Sample message:</p>
<p><pre> <p><pre>
{ {

View File

@@ -87,28 +87,49 @@
<script type="text/x-red" data-help-name="xiaomi-motion"> <script type="text/x-red" data-help-name="xiaomi-motion">
<p>The Xiaomi body motion sensor node</p> <p>The Xiaomi body motion sensor node</p>
<h3>Inputs</h3>
<dl class="message-properties"> <dl class="message-properties">
<dt class="mandatory">Gateway</dt> <dt>payload
<dd>The Gateway configuration node this sensor is attached.</dd> <span class="property-type">json</span>
<dt class="optional">Name</dt> </dt>
<dd>A descriptive name for this sensor.</dd> <dd>Gateway <code>motion</code> message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code></dd>
<dt class="mandatory">Device</dt> </dl>
<dd>The device to associate this node with. This device is configured in the Gateway configuration.</dd>
<dt class="mandatory">Output</dt> <h3>Outputs</h3>
<dd>Three output types are supported:</dd> <ol class="node-ports">
<li>Motion output
<dl class="message-properties">
<dt>payload <span class="property-type">string | json</span></dt>
<dd>raw data, value or template.</dd>
</dl>
</li>
<li>Duration output
<dl class="message-properties">
<dt>payload <span class="property-type">json</span></dt>
<dd>raw data</dd>
</dl>
</li>
</ol>
<h3>Details</h3>
<p>The incoming json message is parsed if the type model is <code>motion</code> and
the <code>sid</code> matches the configured value for this device.</p>
<p>Three output types are supported for output 1:
<ul> <ul>
<li>Full data</li> <li>Full data</li>
<li>Just values</li> <li>Just values</li>
<li>Template</li> <li>Template</li>
</ul> </ul>
<dt class="mandatory">Full data</dt> </p>
<dd>Passes the complete object received from the gateway. Use this if you need the raw data.</dd>
<dt class="mandatory">Just values</dt> <h4>Full data</h4>
<dd>Only passes the values <code>motion</code> or <code>no_motion</code>. In case of <code>no_motion</code> also the duration is passed on the second output.</dd> <p>Passes the complete json object received from the gateway. Use this if you need the raw data.</p>
<dt class="mandatory">Template</dt> <h4>Just values</h4>
<dd>Use your own template to pass the values on. The template can contain <a href="http://mustache.github.io/mustache.5.html">mustache-style</a> tags. <p>Only passes the values <code>motion</code> or <code>no_motion</code>. In case of <code>no_motion</code> also the duration object is passed on output 2.</p>
Any property from the data section of the full object can be used.</dd> <h4>Template</h4>
</dl> <p>Use your own template to pass the values on. The template can contain <a href="http://mustache.github.io/mustache.5.html">mustache-style</a> tags.
Any property from the data section of the full object can be used.</p>
<p>Sample message:</p> <p>Sample message:</p>
<p><pre> <p><pre>
{ {

View File

@@ -85,34 +85,58 @@
</script> </script>
<script type="text/x-red" data-help-name="xiaomi-plug"> <script type="text/x-red" data-help-name="xiaomi-plug">
<p>The Xiaomi plug (zigbee) sensor node</p> <p>The Xiaomi plug (zigbee) node</p>
<p>This is the plug (socket) version which is attached to a Xiaomi gateway. The Wifi version is not yet supported.</p> <p>This is the plug (socket) version which is attached to a Xiaomi gateway. The Wifi version is not yet supported.</p>
<p>To switch an output you need to specify the key of the gateway in the gateway configuration; without the key <p>To switch an output you need to specify the key of the gateway in the gateway configuration; without the key
no output can be switched. To retrieve the gateway key consult the Xiaomi Mi Home App.</p> no output can be switched. To retrieve the gateway key consult the Xiaomi Mi Home App.</p>
<p>On the input you can send <code>on</code> to switch the plug on. To turn it off just send <code>off</code></p>
<p>Output 1 reports the status, output 2 is the write command for the plug.</p> <h3>Inputs</h3>
<dl class="message-properties"> <dl class="message-properties">
<dt class="mandatory">Gateway</dt> <dt>payload
<dd>The Gateway configuration node this sensor is attached.</dd> <span class="property-type">string | json</span>
<dt class="optional">Name</dt> </dt>
<dd>A descriptive name for this sensor.</dd> <dd>Gateway <code>plug</code> message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code>. Or <code>on</code> or <code>off</code>.</dd>
<dt class="mandatory">Device</dt> </dl>
<dd>The device to associate this node with. This device is configured in the Gateway configuration.</dd>
<dt class="mandatory">Output</dt> <h3>Outputs</h3>
<dd>Three output types are supported:</dd> <ol class="node-ports">
<li>Status output
<dl class="message-properties">
<dt>payload <span class="property-type">string | json</span></dt>
<dd>raw data, value or template.</dd>
</dl>
</li>
<li>Control output
<dl class="message-properties">
<dt>payload <span class="property-type">json</span></dt>
<dd>Gateway <code>write_cmd</code> to switch the output on or off.</dd>
</dl>
</li>
</ol>
<h3>Details</h3>
<p>The incoming json message is parsed if the type model is <code>plug</code> and
the <code>sid</code> matches the configured value for this device.</p>
<p>On the input you can send the string <code>on</code> to switch the plug on. To turn it off just send the string <code>off</code></p>
<p>Output 1 reports the status, output 2 is the write command for the plug.</p>
<p>Three output types are supported:
<ul> <ul>
<li>Full data</li> <li>Full data</li>
<li>Just values</li> <li>Just values</li>
<li>Template</li> <li>Template</li>
</ul> </ul>
<dt class="mandatory">Full data</dt> </p>
<dd>Passes the complete object received from the gateway. Use this if you need the raw data.</dd>
<dt class="mandatory">Just values</dt> <h4>Full data</h4>
<dd>Only passes the values <code>on</code> or <code>off</code>.</dd> <p>Passes the complete json object received from the gateway on output 1. Use this if you need the raw data.</p>
<dt class="mandatory">Template</dt> <h4>Just values</h4>
<dd>Use your own template to pass the values on. The template can contain <a href="http://mustache.github.io/mustache.5.html">mustache-style</a> tags. <p>Only passes the values <code>on</code> or <code>off</code> on output 1.</p>
Any property from the data section of the full object can be used.</dd> <h4>Template</h4>
</dl> <p>Use your own template to pass the values on. The template can contain <a href="http://mustache.github.io/mustache.5.html">mustache-style</a> tags.
Any property from the data section of the full object can be used.</p>
<p>Sample message:</p> <p>Sample message:</p>
<p><pre> <p><pre>
{ {

View File

@@ -18,7 +18,7 @@ module.exports = function(RED) {
node.status({fill:"yellow", shape:"ring", text:"waiting for key"}); node.status({fill:"yellow", shape:"ring", text:"waiting for key"});
if (this.gateway) { if (this.gateway && this.key != "") {
node.on('input', function(msg) { node.on('input', function(msg) {
// var payload = JSON.parse(msg); // var payload = JSON.parse(msg);
var payload = msg.payload; var payload = msg.payload;
@@ -98,6 +98,9 @@ module.exports = function(RED) {
} else { } else {
// no gateway configured // no gateway configured
if (this.key == "") {
node.status({fill:"red", shape:"dot", text:"no key configured"});
}
} }
} }

View File

@@ -87,7 +87,62 @@
</div> </div>
</script> </script>
<script type="text/x-red" data-help-name="xiaomi-ht"> <script type="text/x-red" data-help-name="xiaomi-switch">
<p>A simple node that converts the message payloads from a switch into an output message</p> <p>The Xiaomi Switch node</p>
<h3>Inputs</h3>
<dl class="message-properties">
<dt>payload
<span class="property-type">json</span>
</dt>
<dd>Gateway <code>switch</code> message of type <code>read_ack</code>, <code>heartbeat</code> or <code>report</code></dd>
</dl>
<h3>Outputs</h3>
<ol class="node-ports">
<li>Single click output
<dl class="message-properties">
<dt>payload <span class="property-type">string | json</span></dt>
<dd>raw data, value or template.</dd>
</dl>
</li>
<li>Double click output
<dl class="message-properties">
<dt>payload <span class="property-type">string | json</span></dt>
<dd>raw data, value or template.</dd>
</dl>
</li>
</ol>
<h3>Details</h3>
<p>The incoming json message is parsed if the type model is <code>switch</code> and
the <code>sid</code> matches the configured value for this device.</p>
<p>Three output types are supported:
<ul>
<li>Full data</li>
<li>Just values</li>
<li>Template</li>
</ul>
</p>
<h4>Full data</h4>
<p>Passes the complete json object received from the gateway on output 1. Use this if you need the raw data.</p>
<h4>Just values</h4>
<p>Only passes the string values <code>single_click</code> on output 1 and <code>double_click</code> on output 2.</p>
<h4>Template</h4>
<p>Use your own template to pass the values on. The template can contain <a href="http://mustache.github.io/mustache.5.html">mustache-style</a> tags.
Any property from the data section of the full object can be used.</p>
<p>Sample message:</p>
<p><pre>
{
cmd: "report"
model: "switch"
sid: "158d000128b124"
short_id: 56773
data: "{
"status":"click"
}"
}</pre></p>
</script> </script>

View File

@@ -1,22 +1,16 @@
{ {
"name": "node-red", "name": "node-red-contrib-xiaomi-devices",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "A set of nodes to control some of the popular Xiaomi sensors which are connected to the Xiaomi Gateway.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+ssh://git@gitlab.com/h-rietman/xiaomi-devices-node-red.git" "url": "git+ssh://git@gitlab.com/h-rietman/xiaomi-devices-node-red.git"
}, },
"keywords": [], "keywords": [Xiaomi],
"author": "Harald Rietman <harald.rietman@portofrotterdam.com> (http://blog.example.com)", "author": "Harald Rietman <h.rietman@gmail.com>",
"license": "ISC",
"bugs": { "bugs": {
"url": "https://gitlab.com/h-rietman/xiaomi-devices-node-red/issues" "url": "https://gitlab.com/h-rietman/xiaomi-devices-node-red/issues"
}, },
"homepage": "https://gitlab.com/h-rietman/xiaomi-devices-node-red#README",
"dependencies": { "dependencies": {
"cryptojs": "^2.5.3", "cryptojs": "^2.5.3",
"mustache": "^2.3.0" "mustache": "^2.3.0"

BIN
xiaomi-devices-overview.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 KiB