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
Note: as of HomeScript 4.1 the minimum requirement is Python3+ and HomeBridge 1.x.x+
hs.py -s MainLight 0
| Switch off
hs.py -s MainLight 1
| Switch on
hs.py -s MainLight
| Toggle
hs.py -s lifx -hue 140
| RGB Lights Support (brightness, hue, saturation, temperature)
hs.py -s desk -b +10
| Increment/Decrement values
The script doesn't require full names of the accessories.
For example, if your light is called "MainLight", you can run:
hs.py -s MainLight 0
or
hs.py -s 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:
hs.py -s all lights 1
hs.py -s all switches 0
Looking for maintainers: If you are interested in maintaining this project, feel free to reach out.
Important: HomeBridge must be run in insecure mode for this script to work!
via Command Line
homebridge -I
via Systemd
HOMEBRIDGE_OPTS=-U /var/lib/homebridge -I
via pm2
pm2 stop homebridge; pm2 delete homebridge; pm2 start homebridge -- -I
pip install homescript
or pip3 install homescript
chmod +x /path/to/hs.py
(on linux)Usage: hs.py [option] [value]
hs.py -l [argument]
hs.py -g <accessory-name>
hs.py -s <accessory-name> [value]
hs.py -g all <accessory-type>
hs.py -s all \<accessory-type> valuehs.py -d <command>
hs.py -d -s all lights 0
As of v5.1+ HomeScript is now a fully importable API
import homescript
# Initialize with hostname, port and auth code. Debug and sys.argv are optional
hs = homescript.HomeScript(hostname, port, auth, [debug], [sys.argv])
# Select an accessory or group of accessories. Any get/set/print operation requires accessories to be selected first.
hs.selectAccessory('mainlight')
hs.selectGroup('lights')
hs.printSelectedItems()
# Operates on all selected items
hs.setStates(1)
hs.setValues('Brightness',250)
Function | Description |
---|---|
HomeScript( hostname: str, port: str, auth: str, debug: Boolean, argv: list ) | Constructor to initialize HomeBridge Connection. Debug: Set to True if you want to create debug and exception logfile. Default: None. argv: Only required if debug is True |
getAccessories() | Returns raw list of all available accessories on the Bridge |
selectAccessories( searchString: str ) | Saves matching accessory into selectedAccessories and returns them |
selectGroup( searchString: str ) | Saves all matching accessories into selectedAccessories and returns them |
printAccessories() | Prints all available accessories on the Bridge |
printSelectedItems() | Prints selectedAccessories |
getSelectedItems() | Returns selectedAccessories |
setStates(state: Boolean) | Sets state as the on/off value of all item(s) in selectedAccessories. If no argument is specified it toggles the state of all selectedAccessories |
setValues(attribute: str, value: int) | Sets numeric value to attribute of the item(s) in selectedAccessories. Attrubute: Brightness/Hue/Saturation/Color Temperature |
getVersion() | Does what it says on the can... |
The debug
option helps generate a logfile for troubleshooting and error detection.
hs.py -d -l
PRs and commits that you make to this repo must include the following:
☑️ Color control for RGB and Hue Lights
⬜️ Control for PositionOpeners, GarageDoorOpener, LockMechanism
⬜️ WebColors
☑️ Increment/Decrement values
☑️ Querying API interface to return status of devices to stdout
☑️ Automation creation, viewing and monitoring without Home Hub