A homebridge switch which changes state only if the shell command is successful. Shows pending state while command is being run.
Suppose you to run a bash script on your homebridge host system, but it isn't guaranteed to work. You want to retry that command in a little while until it works.
- This switch won't change state until the script returns a successful exit code (zero).
- If anything else happens, the switch will remain in its previous state.
- We'll show the "pending" switch state while the command is running.
The switch will maintain state between homebridge reboots, using node-persist, except for those switches marked as stateless by setting stateful to false. Those switches are always showing state as ON and thus only the onCmd is executed. The offCmd is ignored. Usefull e.g. for rebooting your router via shell command. Default stateful is true.
Many thanks to hans-1 for providing a lovely base for this plugin to grow on.
Example config.json:
"accessories": [
{
"accessory": "ShellSwitch",
"name": "TV Power",
"onCmd": "/home/homebridge/control/tv_on.sh",
"offCmd": "/home/homebridge/control/tv_off.sh",
"stateful" : true
}
]