The below continues to work, but homebridge-http-webhooks is much easier to set up and use as it only requires a HTTP request. With this package, you configure individual switches from config.json
.
"platforms": [
[...]
{
"platform": "HttpWebHooks",
"webhook_port": 4051,
"switches": [
{
"id": "sleep",
"name": "Go to Sleep"
}
]
}
]
Trigger it by GETing http://<server>:4051/?accessoryId=sleep&state=true
, which will return {"success":true}
. This is a lot more amenable to direct automation from apps such as Workflow.
There's no easy way to trigger a HomeKit scene from a URL scheme. You could build your own non-App Store iOS app, or decide it might be more fun to play with Pythonista, as I did.
You'll need homebridge and homebridge-websocket set up.
I use the following in my ~/.homebridge/config.json
:
"platforms": [
[...]
{
"platform": "websocket",
"name": "WebSockets",
"port": 4050
}
]
Then install Pythonista 3, StaSh and pip install websockets
(the asynchronous WebSockets library here) from StaSh.
Copy switch.py
to Pythonista. Change the hostname at the top. Run it and you'll get prompted for the name of a switch to create. You can bind a separate action to the switch being turned on and off.
Create a rule/action which triggers your scene whenever the fake switch is turned on or off. Most advanced HomeKit apps will let you do this; Eve and Hesperus are the best free ones I've used.
Then trigger your URL. I use Launch Center Pro as follows:
pythonista3://switch.py?action=run&argv=«switch name»&argv=«true/false/flip»&argv={{«URL to chain»}}
The 3rd argument gives you x-callback-url
style behavior.
You can also run the script from a Mac or other computer with Python 3.5 on it.
Note that the action will only trigger when the switch "position" changes; if it's already on and you turn it on, nothing happens. To work around this, you can pass flip
instead of true
or false
and the switch will be turned off then immediately on; this should mean that your scene will always be triggered.