This Homebridge plugin can be used to integrate your curtain which has an HTTP api into HomeKit. This controller supports push notification without the need for HomeBridge to periodically pull the curtain position value. There are a few other HTTP based curtain / window blinds plugins available, but I have not found any yet that does not poll the curtain controller continuously for position or state updates.
This is a fork of Supereg's homebridge-http-temperature-sensor modified to function as an curtain controller.
Features:
First of all you need to have Homebridge installed. Refer to the repo for
instructions.
Then run the following command to install homebridge-http-curtain
sudo npm install -g homebridge-http-curtain
The 'CurrentPosition' characteristic from the 'WindowCovering' service has the permission to notify
the
HomeKit controller of state changes.
homebridge-http-curtain
supports two ways to send window blinds/curtain position changes to HomeKit.
The 'pull' way is probably the easiest to set up and supported in every scenario. homebridge-http-curtain
requests the value of the curtain/window blind in an specified interval (pulling) and sends the value to HomeKit.
Look for pullInterval
in the list of configuration options if you want to configure it.
When using the 'push' concept the HTTP device itself sends the updated value itself to homebridge-http-curtain
whenever the value changes. This is more efficient as the new value is updated instantly and
homebridge-http-curtain
does not need to make needless requests when the value didn't actually change.
However because the http device needs to actively notify the homebridge-http-curtain
plugin there is more
work needed to implement this method into your http device.
How to implement the protocol into your http device can be read in the chapter Notification Server
The configuration can contain the following properties:
name
\<string> required: Defines the name which is later displayed in HomeKitgetCurrentPosUrl
\<string | urlObject> required: Defines the url
(and other properties when using an urlObject) to query the current position from the curtain.
It expects the http server to return a integer ranging from 0-100 (step 1) leaving out any html markup when no getCurrentPosRegEx
is provided.getCurrentPosRegEx
\<string> optional: A regular expression from which the first matched group determines the current position.getPositionStateUrl
\<string | urlObject> optional: Defines the url
(and other properties when using an urlObject) to query the current state from the curtain.
It expects the http server to return a integer '0' (Closing), '1' (Opening) or '2' (Idle) leaving out any html markup.
Note that Homekit ignores this state as it rather compares CurrentPosition with TargetPosition.setTargetPosUrl
\<string | urlObject> required: Defines the url
(and other properties when using an urlObject) to set the target position at the curtain.
Any %d
format specifier will be replaced by the requested target position.getTargetPosUrl
\<string | urlObject> optional: Defines the url
(and other properties when using an urlObject) to retrieve the target position at the curtain.getTargetPosRegEx
\<string> optional: A regular expression from which the first matched group determines the target position.identifyUrl
\<string | urlObject> optional: URL to call when the HomeKit identify action is requested.pullInterval
\<integer> optional: The property expects an interval in milliseconds in which the plugin
pulls updates from your http device. For more information read pulling updates. invertPosition
\<boolean> optional: True: interpret 0% as fully open and 100% as fully closed.Below is an example configuration. One URL is using a simple string URL and the other is using an urlObject.
Both configs can be used for a basic plugin configuration.
{
"accessories": [
{
"accessory": "HttpCurtain",
"name": "Living Room Left Curtain",
"getCurrentPosUrl": "http://livingroom-curtain-left/api/v1/pos",
"setTargetPosUrl": {
"url": "http://livingroom-curtain-left/api/v1/pos/%d",
"method": "PUT"
}
}
]
}
A urlObject can have the following properties:
url
\<string> required: Defines the url pointing to your http servermethod
\<string> optional (Default: "GET"): Defines the http method used to make the http requestbody
\<string> optional: Defines the body sent with the http requestauth
\<object> optional: If your http server uses basic authentication you can specify your credential in this
object. When defined the object must contain the following properties:
username
\<string>password
\<string>headers
\<object> optional: Using this object you can define any http headers which are sent with the http
request. The object must contain only string key value pairs. Below is an example of an urlObject containing all properties:
{
"url": "http://example.com:8080",
"method": "GET",
"body": "exampleBody",
"auth": {
"username": "yourUsername",
"password": "yourPassword"
},
"headers": {
"Content-Type": "text/html"
}
}
homebridge-http-curtain
can be used together with
homebridge-http-notification-server in order to receive
updates when the state changes at your home automation device. For details on how to implement those updates and how to
install and configure homebridge-http-notification-server
, please refer to the
README of that repository.
Down here is an example on how to configure homebridge-http-curtain
to work with your implementation of the
homebridge-http-notification-server
.
{
"accessories": [
{
"accessory": "HttpCurtain",
"name": "Living Room Curtain",
"notificationID": "my-curtain",
"notificationPassword": "SuperSecretPassword",
"getUrl": "http://localhost/api/pos"
}
]
}
notificationID
is an per Homebridge instance unique id which must be included in any http request. notificationPassword
is optional. It can be used to secure any incoming requests.To get more details about the configuration have a look at the README.
Available characteristics (for the POST body)
Down here are all characteristics listed which can be updated with an request to the homebridge-http-notification-server
characteristic
"CurrentPosition": expects an integer value
in a range of 0 up to and including 100.