menahishayan / HomeScript

Python script for command line control of HomeBridge (HomeKit)
GNU General Public License v3.0
94 stars 16 forks source link
cli command-line home-automation homebridge homebridge-interface homebridge-plugin homekit ios lights linux modularity python python-script

HomeScript

Donate

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+

Examples

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

Easy Match

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

Group Actions

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.

Setup

Important: HomeBridge must be run in insecure mode for this script to work!

Running HomeBridge in Insecure Mode

Installation

Usage

Usage: hs.py [option] [value]

Options:

API

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...

Troubleshooting/Error Reporting/Contributing

The debug option helps generate a logfile for troubleshooting and error detection.

PRs and Commit Template

PRs and commits that you make to this repo must include the following:


To Do

☑️ 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


Changelog

v5.2

v5.1.1

v5.1

v5.0

v4.1

v4.0

v3.0.2

v3.0.1

v3.0

v2.2

v2.1

v2.0

v1.3

v1.2

v1.1

v1.0