A control server for G-Homa wifi plugs written in node.
This library enables the use of the wifi plugs without the need to allow them to call home.
This library is intended to be used as part of a home automatisation solution. For example, it can be used together with a framework like express.js to switch the plugs on or off by simple http calls.
Installation
$ npm install ghoma
Usage examples
This example shows the callback methods provided.
var ghoma = require('./ghoma.js');
ghoma.onNew = function(plug) {
console.log('Registerd ' + plug.remoteAddress+" "+plug.id);
plug.on();
}
ghoma.onStatusChange = function(plug) {
console.log('New state of ' + plug.remoteAddress+' is '+plug.state+' triggered '+plug.triggered);
}
ghoma.onClose = function(plug) {
console.log('Closed ' + plug.remoteAddress);
}
ghoma.onHeartbeat = function(plug) {
console.log('Heartbeat ' + plug.remoteAddress);
}
ghoma.startServer(4196);
A more comprehensive example shows the node-ghoma library in combination with the express framework. See express_example.js in the git repository.
API description
Notifications
These notifications are triggered. See also example above.
onNew(plug)
Called when a new plug is registered with the control server.
onStatusChange(plug)
Called if the plug was switched on or off.
onClose(plug)
Called if the connection to the plug was lost.
onHeartbeat(plug)
Called when a heartbeat event from the plug occurred.
Methods
Methods provided by the module.
forEach(callback)
Iterate through each registered plug object. The callback will receive the plug object.
Example:
ghoma.forEach(function(plug) {
console.log('Plug with id '+plug.id+' at '+plug.remoteAddress+' has state '+plug.state);
});
get(id)
Helper method to get a plug by id. The id is the hex representation of the short mac of the plug. It can be used to unique identify the plug.
The ghoma plug object
The plug object is used as callback argument for each notification and as a result of method calls.
{
"id": "53ae11",
"state": "on",
"statechanged": "2017-01-22T21:00:19.733Z",
"tiggered": "local",
"prevstate": "off",
"initalized": "2017-01-22T20:59:23.565Z",
"remoteAddress": "::ffff:192.168.1.136",
"remotePort": 14283,
"heartbeat": "2017-01-22T21:00:20.893Z"
}
G-Homa installation
With firmware version <=1.0.06 you can use the embedded web server to adjust the control server address. See the fhem wiki page for instructions.
With newer firmware version, this easy way to configure the plug is disabled. The only known way to run your own control server is to setup your own DNS and DHCP service. Then the DNS entry for 'plug.g-homa.com' must point to your own server and you are forced to use '4196' as listening port.
Further information
The network protocol was deciphered by others - full credits go to them.
See the FHEM Wiki Page (german)
and
Full disclosure for gHoma on seclists (german).
The hardware producer site can be found
here (also in german).