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

Update sample Config.json #3

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
nbproject*
### Node ###
# Logs
Expand Down Expand Up @@ -49,4 +50,4 @@ jspm_packages
.yarn-integrity


# End of https://www.gitignore.io/api/node
# End of https://www.gitignore.io/api/node
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Evan (EvMac) McClintock
Copyright (c) 2017 Jackie (Junrui) Yang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
21 changes: 21 additions & 0 deletions LICENSE.original
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Evan (EvMac) McClintock

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
#homebridge-switchmateA [Homebridge](https://github.com/nfarina/homebridge) platform plugin for [Switchmate](http://www.myswitchmate.com). Switchmate is a Bluetooth LE lightswitch cover which allows for the automation of lightswitches without needing to rewire your home.This plugin was developed using the "Rocker" models of the Switchmate (RSM0001 & RSM0002), though the Toggle models (TSM0001 & TSM0002) will ***hopefully*** work too. This is still somewhat "experimental" and definitely will need further refinement.##Prerequisites & InstallationBe sure to install the following pre-requisites before installing homebridge-switchmate. The prerequisites and their detailed installation instructions are provided on their GitHub pages and websites:* **[Node.js](https://nodejs.org)*** **[Noble](https://github.com/sandeepmistry/noble#prerequisites)** ```npm install -g noble```* **[Noble-Device](https://github.com/sandeepmistry/noble-device#prerequisites)*** **[Node-Switchmate](https://github.com/emmcc/node-switchmate#readme)** ```npm install -g node-switchmate```###Note for Raspberry Pi 3 Users:If you are using a Raspberry Pi 3, you may wish to use a third-party USB Bluetooth adapter. There have been issues with the Pi disconnecting, especially if its internal Wi-Fi is in use. The [IOGEAR GBU521](https://www.amazon.com/dp/B007GFX0PY/) is a decent and compact Bluetooth 4.0 adapter which works really well with the Pi 3.###Installing homebridge-switchmate1. After installing the pre-requisites, install homebridge-switchmate with the Node Package Manager: ```npm install -g homebridge-switchmate```##Adding Switchmate to Homebridge:1. Follow the Switchmate pairing instructions at the [node-switchmate](https://github.com/emmcc/node-switchmate#readme) project page to receive and test your auth code.##Sample Configuration file: ``` "platforms": [ { "platform": "Switchmate", "switchmates": [ { "displayName": "Porch Light", "id": "fe5c32ba4c95", "authCode": "VCcHQA==", "model": "RSM001W" } ] } ]
```
# A Homebridge plugin for Switchmate3 #

Notice: I haven't used this plugin for a long time. I now use Samsung Smartthings hub + Ecolink ZWAVE switch.
Similar to Swtichmate, it allows conventional light switches to be remotely controlled, but it's much more stable.
One tip: Ecolink ZWAVE switch can't operate with NiMH rechargeable battery due to their low operating voltage.
I recommend rechargeable lithium AA batteries, which can maintain a stable 5V supply.

##Important Considerations:###Reversed Light Switches:If your light switches are reversed, you can open the Switchmate App on your smartphone and set it to 'reversed mode'. There is nothing you need to do with this API, as the orientation will be correct in this API after the setting is applied in your Switchmate app.###Avoiding an accidental Switchmate Reset:If you provide the **wrong** authCode in your config.json, there is a good chance your Switchmate will reset itself. This means you will need to relink it to your Smartphone and re-create any timers or schedules you have setup within the Switchmate app.It is imperative to run the toggle command using your authCode before adding a Switchmate to your config.json file.
Switchmate is a BLE controlled light switch add-on that provide smart home capability to conventional light switches.

This plugin is developed for a specific model of Switchmate switch TSM003W. This is the newer toggle style Switchmate
which have a smaller form factor for fitting on a multi-gang switch.

This plugin is a fork of [homebridge-switchmate](https://github.com/emmcc/homebridge-switchmate) a Homebridge Plugin
for the original Switchmate (RSM0001 & RSM0002). As the communication protocol of these two product is quite different.
I have to use [node-switchmate3](https://github.com/valkjsaaa/node-switchmate3) as the communication library. Any
attempt to merge them would be welcome :)

This plugin is still very experimental. Please create an issue or a pull request for any problem you encountered.
155 changes: 155 additions & 0 deletions Switchmate3Manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
var Switchmate3Device = require('node-switchmate3').Switchmate3Device;
var util = require('util');
var EventEmitter = require('events').EventEmitter;

var Switchmate3Manager = function ()
{
var manager = this;
manager.initialized = false;
manager.SmIdList = [];
manager.event = new EventEmitter();
manager.Switchmate3s = [];
if (!(this instanceof Switchmate3Manager))
return new Switchmate3Manager();


manager.FindAllSwitchmate3s = function ()
{
Switchmate3Device.SCAN_DUPLICATES = true;
Switchmate3Device.discoverAll(onFound);
};

manager.StopFind = function ()
{
Switchmate3Device.stopDiscoverAll(onFound);
};

manager.ResetSwitchmate3Scan = function()
{
manager.StopFind();
manager.FindAllSwitchmate3s();
};

function onFound(foundSm) {
var smid = foundSm.id;

if (smid in manager.SmIdList) //if Switchmate3 is in the list of configured Switchmate3 ids.
{
if (!manager.SmIdList[smid] === true) //if Switchmate3 hasn't been found until now...
{
var foundSmToggleMode = foundSm.ToggleMode();
foundSm.on('unreachable', function (smid) {
manager.event.emit('smUnreachable', smid);
});
foundSm.on('reachable', function (smid) {
manager.event.emit('smReachable', smid);
});
foundSmToggleMode.event.on('toggleDone',manager.ResetSwitchmate3Scan);
foundSm.foundMe();
manager.Switchmate3s[smid] = foundSm;
manager.SmIdList[smid] = true;
manager.event.emit('smSetup', smid);
} else
{
if (manager.Switchmate3s[smid].ToggleState !== foundSm.ToggleState && foundSm.ToggleState !== null)
{
manager.Switchmate3s[smid].ToggleState = foundSm.ToggleState;
manager.event.emit('smToggleStateChange', smid, foundSm.ToggleState);
manager.event.emit('smBatteryLevelChange', smid, foundSm.BatteryLevel);
}
manager.Switchmate3s[smid].foundMe();
}
}
}
};

Switchmate3Manager.prototype.Initialize = function (sm_config)
{
var manager = this;
if (!manager.initialized)
{
manager.SmRaw = sm_config;
for (var i = 0, len = manager.SmRaw.length; i < len; i++) {
sminfo = manager.SmRaw[i];
manager.SmIdList[sminfo.id] = false;
}
manager.FindAllSwitchmate3s();
manager.initialized = true;
}
};

Switchmate3Manager.prototype.GetSwitchmate3BatteryLevel = function (smid)
{
manager = this;
if (typeof manager.Switchmate3s[smid] !== 'undefined')
{
return manager.Switchmate3s[smid].BatteryLevel || 100; //if Switchmate3 exists, return its last known Battery Level.
} else
{
return 100; //otherwise, just assume it is 100%.
}
};

Switchmate3Manager.prototype.GetSwitchmate3State = function (smid)
{
manager = this;
if (typeof manager.Switchmate3s[smid] !== 'undefined')
{
return manager.Switchmate3s[smid].ToggleState; //if Switchmate3 exists, return its last known Toggle State.
} else
{
return false; //otherwise, just assume it is turned off.
}
};

Switchmate3Manager.prototype.GetReachableState = function (smid)
{
if (this.SmIdList[smid] === false || typeof this.SmIdList[smid] === 'undefined')
{
return false;
} else
{
return this.Switchmate3s[smid].Reachable;
}
};

Switchmate3Manager.prototype.On = function (smid)
{
var manager = this;
if (manager.SmIdList[smid] === true &&
(manager.Switchmate3s[smid].ToggleState === false || manager.Switchmate3s[smid].ToggleState === null))
{
var ToggleMode = manager.Switchmate3s[smid].ToggleMode();
ToggleMode.event.once('toggleDone', function() {
manager.event.emit('smBatteryLevelChange', smid, manager.Switchmate3s[smid].BatteryLevel);
});
ToggleMode.TurnOn();
}
};

Switchmate3Manager.prototype.Off = function (smid)
{
var manager = this;
if (manager.SmIdList[smid] === true && (
manager.Switchmate3s[smid].ToggleState === true || manager.Switchmate3s[smid].ToggleState === null))
{
var ToggleMode = manager.Switchmate3s[smid].ToggleMode();
ToggleMode.event.once('toggleDone', function() {
manager.event.emit('smBatteryLevelChange', smid, manager.Switchmate3s[smid].BatteryLevel);
});
ToggleMode.TurnOff();
}
};

Switchmate3Manager.prototype.Identify = function (smid)
{
var manager = this;
if (manager.SmIdList[smid] === true)
{
var ToggleMode = manager.Switchmate3s[smid].ToggleMode();
ToggleMode.IdentifySwitchmate3();
}
};

util.inherits(Switchmate3Manager, EventEmitter);
module.exports = Switchmate3Manager;
141 changes: 0 additions & 141 deletions SwitchmateManager.js

This file was deleted.

4 changes: 2 additions & 2 deletions config-sample-linux.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
{
"displayName": "Porch Light",
"id": "fe5c32ba4c95",
"authCode": "VCcHQA==",
"model": "RSM001W"
"model": "TSM003W",
"lowBatteryPercent": 25
}
]
}
Expand Down
6 changes: 3 additions & 3 deletions config-sample-macos.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
{
"displayName": "Porch Light",
"id": "754ffdf6021c4285b7240c0a778ebd96",
"authCode": "VCcHQA==",
"model": "RSM001W"
"model": "TSM003W",
"lowBatteryPercent": 25
}
]
}
]
}
}
Loading