Python script for command line control of HomeBridge (HomeKit)
Used to toggle Homebridge accessories On or Off via python script, no Home app required. You can set up a cronjob to enable automation, scripting and mimic other HomeKit functionalities
python homeScript.py MainLight 0
| Switch off
python homeScript.py MainLight 1
| Switch on
python homeScript.py MainLight
| Toggle
The script doesn't require full names of the accessories.
For example, if your light is called "MainLight", you can run:
python homeScript.py MainLight 0
or
python homeScript.py main 0
The script will automatically search for matching substrings and set the accessory value
You can set multiple accessories (of the same type) in a single command:
python homeScript.py all lights 1
python homeScript.py all switches 0
- Python requests library
- Python JSON library
- Install the requests library
pip install requests
orpip3 install requests
- On your client computer: Move homeScript.py to a convenient location
- Edit the script to include your homebridge URL, port and authorization key
- Change permissions
chmod +x /path/to/homeScript.py
(on linux)
- On your HomeBridge: edit your /etc/default/homebridge to run in insecure mode every time it starts.
HOMEBRIDGE_OPTS=-I -U /var/lib/homebridge
- Restart your homebridge for the changes to take effect:
sudo systemctl restart homebridge.service
or the equivalent command on your device.
python homeScript.py [option] [argument]
- list : lists all available HomeKit accessories
- Usage:
python homeScript.py list [argument]
- Arguments:
- <none> : lists accessory names
- aid : lists accessory names with AID value
- iid : lists accessory names with IID value
- id : lists accessory names with AID and IID
- type : lists accessory names with type [Lightbulb, Switch, Fan, etc.]
- value : lists accessory names current state
- all : lists all of the above
- json: prints all attributes in JSON string format
- Usage:
- <accessory-name> : [EasyMatch Supported] toggles the accessory On or Off, or sets to value
- Usage:
python homeScript.py <accessory-name> [value]
- Values:
- <none> : toggles the state
- 0 : sets to OFF
- 1 : sets to ON
- Usage:
- all : sets value of multiple HomeKit accessories
- Usage:
python homeScript.py all <accessory-type> value
- <accessory-type> : [EasyMatch Supported] sets all <accessory-type> to <value>
- Usage:
- help : prints usage info
- debug : generates debug log file.
- Usage:
python homeScript.py debug <command>
- Eg:
python homeScript.py debug all lights 0
- Usage:
The debug
option helps generate a logfile for troubleshooting and error detection.
- If you face an error, open a new issue on this repo prefixed by [Error] describing the error and attach your both your debug log and your exception log, along with any other outputs you receive.
- If you would like to help improve the tool or request features, open an issue prefixed by [Feature Request] describing the functionality.
- You must attach your debug log or else your issue will be closed. A simple debug log can be obtained from
python homeScript.py debug list
PRs and commits that you make to this repo must include the following:
- Type: bug-fix or enhancement
- Description: Brief description about what the commit achieves
- Notes: (heads ups/pointers to other developers if necessary)
- Added debug support
- Added group actions. You can now set values for all matching accessory types
- Added json listing support
- Added type support to identify accessory type
- Updated help doc
- List of accessories are now automatically fetched from the homebridge, instead of having to manually set them up in the script
- Added easy name matching
- Added help doc
- Added listing
- Added toggling
- Initial release