Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Garage door opener support MSG100 #4

Merged
merged 4 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ Meross Config is a config node to set the token, message id and timestamp for be
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 MSS110(EU)
- Meross Smart Plug MSS210(EU)
- Meross Garage Door MSG100

# 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.
You might also feel free to directly contribute in this project.
Binary file added meross/icons/smartgarage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions meross/smartgarage-control.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<script type="text/javascript">
RED.nodes.registerType('smartgarage-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: 'smartgarage.png', // saved in icons/myicon.png
color: '#005AFF',
label: function() {
return this.name || 'Smart Garage';
},
paletteLabel: 'Smart Garage',
});
</script>

<!-- Setting design and inputs for node -->
<script type="text/x-red" data-template-name="smartgarage-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 Garage 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 Garage">
</div>
</script>

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

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

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

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

this.on('input', function (msg) {
request.post({
url: 'http://' + Platform.ip + '/config',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
'header': {
'messageId': Platform.config.messageid,
'method': (typeof msg.payload === 'boolean') ?
'SET' :
'GET',
'from': 'http://' + Platform.ip + '/config',
'sign': Platform.config.token,
'namespace': (typeof msg.payload === 'boolean') ?
'Appliance.GarageDoor.State' :
'Appliance.System.All',
'timestamp': parseInt(Platform.config.timestamp),
'payloadVersion': 1
},
'payload': (typeof msg.payload === 'boolean') ?
{
'state': {
'open': msg.payload ? 1 : 0,
'channel': 0,
'uuid': makeUUID(16)
}
} :
{}
})
}, 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.garageDoor[0].open === 1 ? true : false;
}
catch (e) {
var r = 'Received unexpected data!';
}
Platform.send({ payload : r });
}
});
});
}

function makeUUID(size) {
let uuid = '';
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
while (uuid.length < size) {
uuid += chars.charAt(Math.floor(Math.random() * chars.length));
}
return uuid;
}

RED.nodes.registerType('smartgarage-control', SmartGarageNode);
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"node-red": {
"nodes": {
"meross-config": "meross/meross-config.js",
"smartplug-control": "meross/smartplug-control.js"
"smartplug-control": "meross/smartplug-control.js",
"smartgarage-control": "meross/smartgarage-control.js"
}
},
"repository": {
Expand Down