Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
dehsgr committed Nov 22, 2020
0 parents commit 7802ab0
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 0 deletions.
12 changes: 12 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Copyright 2019 d3h56r

Permission to use, copy, modify, and/or distribute this software for any purpose with
or without fee is hereby granted, provided that the above copyright notice and this
permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# node-red-contrib-meross

This provides nodes for locally controlling e.g. Meross Smart Plug (without cloud!). It's requiring a Merross token and a corresponding timestamp to be provided by you. You should get this data via network sniffer or traffic interception between your Meross app and your Smart Plug. node-red-contrib-meross delivers 2 nodes:

## Meross Config
Meross Config is a config node to set the token and timestamp for being able to locally communicate with your devices.

## Meross Smart Plug
Meross Smart Plug can be used to set smart plugs state and/or poll its current state. For setting smart plugs state to on|off you simply provide a boolean value (true|false). To request its current state you send any non-boolean payload.

# Currently supported devices
- Meross Smart Plug MSS210(EU)

# Requesting additional devices
To be able to implement additional devices feel free to provide sniffed communication between your app and devices.
You might also feel free to directly contribute in this project.
Binary file added meross/icons/smartplug.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions meross/meross-config.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script type="text/javascript">
RED.nodes.registerType('meross-config', {
category: 'config',
defaults: {
name: { value: '' },
timestamp: { value: '', required: true, validate: RED.validators.number() },
token: { value: '', required: true }
},
label: function() {
return this.name || 'Meross';
}
});
</script>

<script type="text/x-red" data-template-name="meross-config">
<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" placeholder="Name">
</div>
<div class="form-row">
<label for="node-config-input-timestamp"><i class="fa fa-tag"></i> Timestamp</label>
<input type="text" id="node-config-input-timestamp">
</div>
<div class="form-row">
<label for="node-config-input-userid"><i class="fa fa-tag"></i> Token</label>
<input type="text" id="node-config-input-token">
</div>
</script>
12 changes: 12 additions & 0 deletions meross/meross-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = function(RED) {
function MerossNode(MyNode) {
RED.nodes.createNode(this, MyNode);
this.token = MyNode.token;
this.timestamp = MyNode.timestamp;
}

RED.nodes.registerType("meross-config", MerossNode, {
token: { type: "text" },
timestamp: { type: "text" }
});
};
40 changes: 40 additions & 0 deletions meross/smartplug-control.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<script type="text/javascript">
RED.nodes.registerType('smartplug-control',{
category: 'Meross',
defaults: {
confignode: { value: '', type: 'meross-config' },
name: { value: '' },
ip: { value: '', type: 'text', required: true }
},
inputs: 1, // set the number of inputs - only 0 or 1
outputs: 1, // set the number of outputs - 0 to n
icon: 'smartplug.png', // saved in icons/myicon.png
color: '#005AFF',
label: function() {
return this.name || 'Smart Plug';
},
paletteLabel: 'Smart Plug',
});
</script>

<!-- Setting design and inputs for node -->
<script type="text/x-red" data-template-name="smartplug-control">
<div class="form-row">
<label for="node-input-confignode"> Meross</label>
<input type="text" id="node-input-confignode">
</div>
<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="Meross Smart Plug Node Name">
</div>
<div class="form-row">
<label for="node-input-ip"><i class="fa fa-tag"></i> IP</label>
<input type="text" id="node-input-ip" placeholder="IP address of your Smart Plug">
</div>
</script>


<!-- Simple Help Text -->
<script type="text/x-red" data-help-name="evohome-control">
<p>A node to control Meross Smart Plug.</p>
</script>
62 changes: 62 additions & 0 deletions meross/smartplug-control.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const request = require('request');

module.exports = function(RED) {
'use strict';

function SmartPlugNode(myNode) {
RED.nodes.createNode(this, myNode);
var Platform = this;

this.config = RED.nodes.getNode(myNode.confignode);
this.ip = myNode.ip;

this.on('input', function (msg) {
request.post({
url: 'http://' + Platform.ip + '/config',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
'header': {
'messageId': 'd31722ef727e2314ad0736cb99beb11f',
'method': (typeof msg.payload === 'boolean') ?
'SET' :
'GET',
'from': 'http://' + Platform.ip + '/config',
'sign': Platform.config.token,
'namespace': (typeof msg.payload === 'boolean') ?
'Appliance.Control.ToggleX' :
'Appliance.System.All',
'timestamp': parseInt(Platform.config.timestamp),
'payloadVersion': 1
},
'payload': (typeof msg.payload === 'boolean') ?
{
'togglex': {
'onoff': msg.payload ? 1 : 0,
'channel': 0
}
} :
{}
})
}, function(myError, myResponse, myBody) {
if(myError) {
Platform.warn('There was an Error: ' + myError);
} else {
var j = JSON.parse(myResponse.body);
try {
var r = (j.header.method !== undefined && j.header.method === 'SETACK') ?
msg.payload :
j.payload.all.digest.togglex[0].onoff === 1 ? true : false;
}
catch (e) {
var r = 'Received unexpected data!';
}
Platform.send({ payload : r });
}
});
});
}

RED.nodes.registerType('smartplug-control', SmartPlugNode);
};
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "node-red-contrib-meross",
"version": "1.0.0",
"description": "This provides nodes for controlling Meross devices.",
"author": "d3h56r",
"license": "ISC",
"keywords": [
"node-red",
"meross"
],
"node-red": {
"nodes": {
"meross-config": "meross/meross-config.js",
"smartplug-control": "meross/smartplug-control.js"
}
},
"repository": {
"type": "git",
"url": "https://github.com/dehsgr/node-red-contrib-meross.git"
},
"dependencies": {
"request": "^2.75.0"
}
}

0 comments on commit 7802ab0

Please sign in to comment.