@vectronic/homebridge-script-switch 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +28 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -13,7 +13,7 @@
13
13
  |---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
14
14
  | name | The name for the accessory instance. |
15
15
  | set_state_on_script | Script to set state ON, optional. If not provided, setting switch On from Home App is not possible. |
16
- | set_state_on_script | Script to set state OFF, optional. If not provided, setting switch Off from Home App is not possible. |
16
+ | set_state_off_script | Script to set state OFF, optional. If not provided, setting switch Off from Home App is not possible. |
17
17
  | get_state_script | Script to get the current switch state. Should output on stdout text signifying "On" which matches `on_state_value` and anything else ot signify "Off". |
18
18
  | on_state_value | Return value from get_state_script which corresponds to ON state. |
19
19
 
@@ -32,6 +32,33 @@ Example `config.json` entry:
32
32
  ]
33
33
  ```
34
34
 
35
+ ## Examples
36
+
37
+ ### Switch that stays ON until a task completes
38
+
39
+ A common use case is to trigger a long-running task and have the switch remain ON for the duration, automatically switching OFF once the task finishes.
40
+
41
+ The key mechanism is that `set_state_on_script` **blocks** until the shell command exits. While the command is running the switch appears ON in the Home app. Once the command exits, Homebridge refreshes the switch state by calling `get_state_script`; if that returns something other than `on_state_value`, the switch will be shown as OFF.
42
+
43
+ ```json
44
+ "accessories": [
45
+ {
46
+ "accessory": "ScriptSwitch",
47
+ "name": "Run Backup",
48
+ "set_state_on_script": "/usr/local/bin/backup.sh",
49
+ "set_state_off_script": "echo 'OFF'",
50
+ "get_state_script": "echo 'OFF'",
51
+ "on_state_value": "ON"
52
+ }
53
+ ]
54
+ ```
55
+
56
+ How it works:
57
+
58
+ - **Turning the switch ON** triggers `set_state_on_script`, which runs `backup.sh` and blocks until it finishes. The switch appears ON in the Home app for the entire duration.
59
+ - **Once `backup.sh` exits**, Homebridge calls `get_state_script` to refresh the state. Because `get_state_script` outputs `OFF` (which does not match `on_state_value`), the switch automatically returns to OFF.
60
+ - **`set_state_off_script`** allows the switch to be turned OFF manually if needed before the task has finished.
61
+
35
62
  ## Help
36
63
 
37
64
  If you have a query or problem, raise an issue in GitHub, or better yet submit a PR!
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Homebridge Script Switch",
3
3
  "name": "@vectronic/homebridge-script-switch",
4
- "version": "0.2.0",
4
+ "version": "0.2.1",
5
5
  "description": "A switch plugin for Homebridge which integrates with shell scripts",
6
6
  "type": "module",
7
7
  "main": "dist/accessory.js",