Skip to content

Commit

Permalink
Added lock mechanism and plain switch types
Browse files Browse the repository at this point in the history
All switches can now be stored on disk
Improved documentation
  • Loading branch information
grover committed Jan 9, 2018
1 parent ddacd3e commit 4075614
Show file tree
Hide file tree
Showing 19 changed files with 634 additions and 129 deletions.
75 changes: 22 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@

# Automation Switches Platform

A platform that provides configurable switches for automation purposes. This platform can be created to provide time delayed responses in HomeKit rules or to simulate security systems.
A platform that provides configurable switches for automation purposes. This platform can be created to provide time delayed responses in HomeKit rules or to simulate security systems.

## Why do we need this plugin?

HomeKit (as of iOS 11.1) does not provide a capability to delay the execution of rules. This platform provides switches that can be used to build a set of rules that are delayed in execution by a configurable period of time on each switch. The period as well as the repetetiveness and the response can be configured via HomeKit (while the configuration provides sane defaults) and can also be changed in response to rules.
This platform provides software based, optionally persistent, switches to create DIY HomeKit solutions.
Each switch has specific purposes that are illustrated in their respective documents linked below.

The security system switches enable an easier creation of home alarm systems using already available
accessories.
The plugin provides four different types of switches: A basic on/off switch, a lock mechanism, an automation switch with advanced properties and a security system. All of them are configured ahead
of their use through the configuration file and each one of them potentially saves their state to storage
to keep their state even across crashes, reboots and such.

## Installation instructions

Expand All @@ -18,7 +20,7 @@ After [Homebridge](https://github.com/nfarina/homebridge) has been installed:

## Example config.json:

```
```json
{
"bridge": {
...
Expand All @@ -45,61 +47,30 @@ After [Homebridge](https://github.com/nfarina/homebridge) has been installed:

The platform can provide any number of switches that have to be predefined in the homebridge config.json.

### Automation Switch Type
### Switch types

Each automation switch provides a regular switch, a motion sensor and a configuration service. Activating the switch starts a timer, which will trigger the motion sensor for 1s when the timer elapses. This can be used as a trigger for HomeKit rules.
Please see the documentation for each type of switch this plugin is able to create:

The switch support two modes: An automatic shut off mode, where the motion sensor will only be tripped once and the switch is automatically shut off. The other mode is a repeating mode, where the motion sensor will be tripped repeatedly until the switch is shut off again.
- [Automation switch](docs/AutomationSwitch.md)
- [Lock mechanism](docs/LockMechanism.md)
- [Security system](docs/SecuritySystem.md)
- [Switch](docs/Switch.md)

| Attributes | Required | Usage |
|------------|----------|-------|
| type | No | If not set, creates an "automation" switch. If specified, this must be "automation" for automation switches. |
| name | Yes | A unique name for the switch. Will be used as the accessory name. |
| period | Yes | The default delay of the switch in seconds. |
| autoOff | Yes | Determines if the switch automatically shuts off after the period has elapsed. |
An advanced configuration example containing all four switch types can be found [here](docs/Configuration.md).

### Security System Switch Type
### Storage

The security system switch type enables the creation of security systems. The switch can be armed in night, away and stay modes. Additionally there's an option to trigger an alarm using an On/Off characteristic.
Every type of switch is able to store every state change to disk. This is useful if homebridge is restarted for whatever reason: The switches created by this plugin will retain the state they had before the restart.

The value of the characteristics is persisted if homebridge is restarted.
For that the switches create individual files in the persist subfolder of your homebridge configuration folder.

| Attributes | Required | Usage |
|------------|----------|-------|
| type | Yes | Must be set to "security" for this type of switch. |
| name | Yes | A unique name for the switch. Will be used as the accessory name. |
## Developer Information

The settings of this switch are persisted to files in the homebridge configuration folder in the persist subfolder.

## Accessory Services

Each automation switch will expose four services:

* Accessory Information Service
* Switch Service
* Motion Sensor Service
* Switch Program Service

Each security switch will expose the following service:

* Accessory Information Service
* Security System Service

## Switch Program Service Characteristics

The exposed switch service supports the following characteristics:

| Characteristic | UUID | Permissions | Usage |
|---|---|---|---|
| Period | `B469181F-D796-46B4-8D99-5FBE4BA9DC9C` | READ, WRITE | The period of the switch in seconds. This value can be changed between 1s and 3600s. A change will only take effect the next time the switch is turned on. |
| AutomaticOff | `72227266-CA42-4442-AB84-0A7D55A0F08D` | READ, WRITE | Determines if the switch is shut off after the period has elapsed. If the switch is not automatically shut off, the timer will be restarted and the motion sensor will be triggered again until the switch is shut off externally. |
| Alarm | `72227266-CA42-4442-AB84-0A7D55A0F08D` | READ, WRITE, EVENTS | For security switches this characteristic enables the triggering of an alarm. Can also be used for additional rules. |

See [HomeKitTypes.js](src/HomeKitTypes.js) for details.
There's [documentation](docs/CustomCharacteristics.md) of the custom services and characteristics exposed by the switches.

## Supported clients

This platform and the delayed switches it creates have been verified to work with the following apps on iOS 11
This platform and the switches it creates have been verified to work with the following apps on iOS 11:

* Home
* Elgato Eve
Expand All @@ -112,9 +83,7 @@ This plugin was initially forked from and inspired by [homebridge-delay-switch](

If you use this and like it - please leave a note by staring this package here or on GitHub.

If you use it and have a
problem, file an issue at [GitHub](https://github.com/grover/homebridge-telegram/issues) - I'll try
to help.
If you use it and have a problem, file an issue at [GitHub](https://github.com/grover/homebridge-telegram/issues) - I'll try to help.

If you tried this, but don't like it: tell me about it in an issue too. I'll try my best
to address these in my spare time.
Expand Down Expand Up @@ -143,4 +112,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.
72 changes: 72 additions & 0 deletions docs/AutomationSwitch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Automation Switch

HomeKit (as of iOS 11.1) does not provide a capability to delay the execution of rules. This plugin provides an automation switch that can be used to build a set of rules that are delayed in execution by a configurable period of time on each switch. The period as well as the repetetiveness and the response can be configured via HomeKit (while the configuration provides sane defaults) and can also be changed in response to rules.

This switch optionally supports being saved to storage on every state change, the switch will save the settings and restore them when homebridge is restarted.

> Please note that while the plugin works with the Home app, some features, such as dynamic
> reconfiguration can only be used with other HomeKit apps, such as [Elgato Eve](https://www.elgato.com/en/eve/eve-app).
## Appearance

Each automation switch provides a regular switch, a motion sensor and a configuration service. Activating the switch starts a timer, which will trigger the motion sensor for 1s when the timer elapses. This can be used as a trigger for HomeKit rules.

The switch support two modes: An automatic shut off mode, where the motion sensor will only be tripped once and the switch is automatically shut off. The other mode is a repeating mode, where the motion sensor will be tripped repeatedly until the switch is shut off again.

![Preview](AutomationSwitch.png "Preview")

(Screenshot: Elgato Eve)

## Configuration

```json
{
"bridge": {
...
},
"platforms": [
{
"platform": "AutomationSwitches",
"switches": [
{
"type": "automation",
"name": "Automation Switch #1",
"period": 1800,
"autoOff": false
}
]
}
]
}
```

## Options

| Attributes | Required | Usage |
|------------|----------|-------|
| type | Yes | Set this to ```automation``` to make this entry an automation switch. |
| name | Yes | A unique name for the automation switch. Will be used as the accessory name. |
| period | Yes | The default time delay of the switch in seconds, before the sensor is triggered. |
| autoOff | Yes | Set this to ```true``` to automatically turn the switch off after the period has expired once, ```false``` to keep the triggering the sensor until it has expired. |
| default | No | Specifies the default state of the switch. This is used if the switch is not yet stored, not stored or the storage has become faulty. The default state is ```false``` if not specified, which means the switch is off. Setting this to ```true``` turns the switch on by default. |
| stored | No | Set this to true if you want the switch to retain its on/off state across restarts. The default setting for the ```switch``` type is ```false```. |

See [configuration](Configuration.md) for more advanced configuration examples.

## Usage

This type of switch is best used if you need to delay the execution of a scene or if you need to execute the scene multiple times until something else has happened.

I personally have used this to send me notifications until I close the bathroom window, reminding me every 10 minutes that the window is open and I might freeze to the toilet seat. For that I combine this switch type with my [homebridge-telegram](https://www.npmjs.com/packages/homebridge-telegram) plugin. (Shameless plug.)

## Notes

### Stored switch states

This switch has logic, which is tied to the state of the switch (e.g. 'On' or 'Off'.) The initial state of the switch is determined either by the "default" field in the configuration or by the value saved just before homebridge terminated the last time.

If the initial value is `true` the timer controlled by the switch will immediately start as soon as the plugin is initialized. This can also serve to delay initialization just after homebridge has been loaded.

### Editing the timeout period

If the automation switch was stored the default period from the configuration file is also not used any longer. To edit the timeout in those cases, either edit the file that belongs to the switch (located in your homebridge configuration directory under the persist folder) or delete it and then edit the default again.
Binary file added docs/AutomationSwitch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Advanced configuration

The following configuration example shows all switches in combination. The configuration was used to make the screenshots in the detailed documentation pages. The configuration shows examples of the
[automation switch](AutomationSwitch.md), the [lock mechanism](LockMechanism.md), the [security system](SecuritySystem.md) and the regular [switch](Switch.md).

## Example

```json
{
"bridge": {
...
},
"platforms": [
{
"platform": "AutomationSwitches",
"switches": [
{
"type": "automation",
"name": "WindowOpenAlert",
"period": 600,
"autoOff": false,
"stored": false
},
{
"type": "automation",
"name": "AutoOff",
"period": 900,
"autoOff": true,
"stored": false
},
{
"type": "lock",
"name": "ScreenLock",
"default": "unlocked",
"stored": true
},
{
"type": "security",
"name": "Home Mode",
"default": "armed-stay",
"stored": true
},
{
"type": "security",
"name": "My DIY security system",
"default": "unarmed",
"stored": true
}
]
}
]
}
```
60 changes: 60 additions & 0 deletions docs/CustomCharacteristics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Custom services and characteristics

Most of the switch types provided by this plugin use standard HomeKit characteristics. In some cases there was no way (or it made no sense) to bend the standard services/characteristics to enable the use cases supported by this plugin.

All custom services and characteristics used are listed below.

## Custom characteristics

All custom characteristics are defined in [HomeKitTypes.js](../src/HomeKitTypes.js).

### Custom automation switch characteristics

The automation switch provides a programming service, which allows dynamic changes to the time period between triggers and also control of the automatic shut off. These characteristics can be used in scenes to change the default behavior of the switch.

| Characteristic | UUID | Service | Permissions | Usage |
|---|---|---|---|
| Period | `B469181F-D796-46B4-8D99-5FBE4BA9DC9C` | READ, WRITE | `FD92B7CF-A343-4D7E-9467-FD251E22C374` | The period of the switch in seconds. This value can be changed between 1s and 3600s. A change will only take effect the next time the switch is turned on. |
| AutomaticOff | `72227266-CA42-4442-AB84-0A7D55A0F08D` | `FD92B7CF-A343-4D7E-9467-FD251E22C374` | READ, WRITE | Determines if the switch is shut off after the period has elapsed. If the switch is not automatically shut off, the timer will be restarted and the motion sensor will be triggered again until the switch is shut off externally. |

Both of these characteristics are provided on the custom SwitchProgramService.

### Custom security system characteristics

The security system provides an additional characteristic to trigger the Alarm state:

| Characteristic | UUID | Service | Properties | Description |
| Alarm | `72227266-CA42-4442-AB84-0A7D55A0F08D` | `0000008E-0000-1000-8000-0026BB765291` | READ, WRITE, EVENTS | This characteristic enables the triggering of an alarm. Can also be used for additional rules. |

This characteristic is provided as an extension on the standard security system service.

## Services

Each switch created by this accessory will provide the standard HomeKit services:

- AccessoryInformation service
- BridgingState service

### Automation switch

The automation switch additionally provides:

- Switch service
- MotionSensor service
- SwitchProgram service (see above)

### Lock mechanism

The lock mechanism service provides:

- LockMechanism service

### Security system

The security system switch provides:

- SecuritySystem service

### Switch

- Switch Service
55 changes: 55 additions & 0 deletions docs/LockMechanism.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Lock mechanism

This switch type represents a lock. A lock can be locked or unlocked and changing the state of the lock triggers built-in HomeKit notifications. Use it for things that can best be simulated by a lock.

## Appearance

The lock mechanism only provides means to lock/unlock via specifically labelled buttons.

![Preview](LockMechanism.png "Preview")

(Screenshot: Elgato Eve)

## Configuration

```json
{
"bridge": {
...
},
"platforms": [
{
"platform": "AutomationSwitches",
"switches": [
{
"type": "lock",
"name": "My simulated door lock",
"default": "unlocked",
"stored": false
}
]
}
]
}
```

## Options

| Field | Required | Description |
|---|---|---|
| type | Yes | Set this to ```lock``` to make this entry a lock mechanism. |
| name | Yes | Set this to the name of the lock as you want it to appear in HomeKit apps. |
| default | No | This configures the default state of the lock if it is not yet stored, never stored or the storage has become faulty. Set this to ```unlocked``` or ```locked``` depending on your needs. By default a lock is ```unlocked``` if this is not specified. |
| stored | No | Set this to true if you want the lock to retain its locked/unlocked state across restarts. The default setting for the ```lock``` type is ```false```. |

See [configuration](Configuration.md) for more advanced configuration examples.

## Usage

This type is best used to simulate a physical lock or things that are best described by a lock. An example use case for the lock is in conditions for HomeKit rules and thus use it to enable or disable the rules based on other conditions.

## HomeKit Notifications

HomeKit, by default, enables notifications for lock mechanisms. Once enabled you automatically get built-in notifications for this lock too. You can disable these notifications in the Home.app if you do not care for the notifications. To disable/enable the notifications, open the Home app, select the tile that represents the lock and long-press on it, choose Details and scroll down until you get to Notifications. You can disable them there.

There's unfortunately no way to change the notification text in HomeKit. If you're looking for something to send customized notifications I'd recommend one of the [IFTT plugins](https://www.npmjs.com/search?q=homebridge+ifttt) or my [homebridge-telegram](https://www.npmjs.com/packages/homebridge-telegram) plugin (shameless plug.)
Binary file added docs/LockMechanism.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4075614

Please sign in to comment.