Http temperature sensor for Homebridge
npm install homebridge-http-temperature-sensorThis Homebridge plugin can be used integrate your temperature sensor which has a
http api into HomeKit.
First of all you need to have Homebridge installed. Refer to the repo for
instructions.
Then run the following command to install homebridge-http-temperature-sensor
```
sudo npm install -g homebridge-http-temperature-sensor
The _'CurrentTemperature'_ characteristic has the permission to notify the HomeKit controller of state homebridge-http-temperature-sensor
changes. supports two concepts to send temperature changes to HomeKit.
The 'pull' way is probably the easiest to set up and supported in every scenario. homebridge-http-temperature-sensor pullInterval
requests the temperature of the sensor in an specified interval (pulling) and sends the value to HomeKit.
Look for 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 to homebridge-http-temperature-sensor homebridge-http-temperature-sensor
whenever values change. This is more efficient as the new value is updated instantly and does not need to make needless requests when the value didn't actually change. homebridge-http-temperature-sensor
However because the http device needs to actively notify the there is more
work needed to implement this method into your http device.
#### Using MQTT:
MQTT (Message Queuing Telemetry Transport) is a protocol widely used by IoT devices. IoT devices can publish messages
on a certain topic to the MQTT broker which then sends this message to all clients subscribed to the specified topic.
In order to use MQTT you need to setup a broker server (mosquitto is a solid
open source MQTT broker running perfectly on a device like the Raspberry Pi) and then instruct all clients to
publish/subscribe to it.
#### Using 'homebridge-http-notification-server':
For those of you who are developing the http device by themselves I developed a pretty simple 'protocol' based on http
to send push-updates.
How to implement the protocol into your http device can be read in the chapter
Notification Server
The configuration can contain the following properties:
##### Basic configuration options:
* accessory \name
* \getUrl
* \unit
and urlObject) to query the current temperature (in celsius) from the sensor. By default it expects the http server
to return the temperature as a float ranging from 0-100 (step 0.1).
* \
are available:
* "celsius": Using celsius to calculate temperature
* "fahrenheit": Using fahrenheit to calculate temperature
##### Advanced configuration options:
* statusPattern \getUrl
temperature is extracted from the body of the http response from the . The group which shouldpatternGroupToExtract
be extracted can be configured with the property. patternGroupToExtract
More about regex pattern.
* \statusCache
is extracted.
* \
of the _CurrentTemperature_ characteristic is cached before a new request is made to the http device.
Default is 0 which indicates no caching. A value of -1 will indicate infinite caching.
- pullInterval \
pulls updates from your http device. For more information read pulling updates.
* mqtt \<mqttObject\> optional: Defines all properties used for mqtt connection (More on MQTT).
For configuration see mqttObject.
- debug \
Below are two example configurations. One is using a simple string url and the other is using a simple urlObject.
Both configs can be used for a basic plugin configuration.
`json`
{
"accessories": [
{
"accessory": "HTTP-TEMPERATURE",
"name": "Temperature Sensor",
"getUrl": "http://localhost/api/getTemperature"
}
]
}`json`
{
"accessories": [
{
"accessory": "HTTP-TEMPERATURE",
"name": "Temperature Sensor",
"getUrl": {
"url": "http://localhost/api/getTemperature",
"method": "GET"
}
}
]
}
#### UrlObject
A urlObject can have the following properties:
* url \method
* \body
* \strictSSL
converted to a JSON string automatically.
* \auth
the whole certificate chain must be trusted. The default is false because most people will work with self signed
certificates in their homes and their devices are already authorized since being in their networks.
* \username \password
* \sendImmediately
* \WWW-Authenticate
credentials immediately to the http server. This is best practice for basic authentication.
When set to false the plugin will send the proper authentication header after receiving an 401 error code
(unauthenticated). The response must include a proper header. headers
Digest authentication requires this property to be set to false!
* \requestTimeout \`
for http response and also setting socket timeout).
Below is an example of an urlObject containing the basic properties:json`
{
"url": "http://example.com:8080",
"method": "GET",
"body": "exampleBody",
"strictSSL": false,
"auth": {
"username": "yourUsername",
"password": "yourPassword"
},
"headers": {
"Content-Type": "text/html"
}
}
#### MQTTObject
A mqttObject can have the following properties:
##### Basic configuration options:
* host \port
* \credentials
* \username \password
* \subscriptions
- \topic \characteristic
- \messagePattern
- \messagePattern is not specified the patternGroupToExtract
message received will be used as value. If the characteristic expects a boolean value it is tested if the
specified regex is contained in the received message. Otherwise the pattern is matched against the message
and the data from regex group can be extracted using the given .patternGroupToExtract
- \
extracted.
##### Advanced configuration options:
* protocol \qos
* \0
must also be configured accordingly).
In contrast to most implementations the default value is 1.
* : 'At most once' - the message is sent only once and the client and broker take no additional steps to 1
acknowledge delivery (fire and forget).
* : 'At least once' - the message is re-tried by the sender multiple times until acknowledgement is 2
received (acknowledged delivery).
* : 'Exactly once' - the sender and receiver engage in a two-level handshake to ensure only one copy of the clientId
message is received (assured delivery).
* \'mqttjs_' + Math.random().toString(16).substr(2, 8)\): Defines clientIdkeepalive
* \clean
* \reconnectPeriod
* \connectTimeout
* \
CONNECT needs to be acknowledged (CONNACK).
Note: Updating values over mqtt is currently only supported for the default unit (celsius).
Below is an example of an mqttObject containing the basic properties for a temperature service:
`json`
{
"host": "127.0.0.1",
"port": "1883",
"credentials": {
"username": "yourUsername",
"password": "yourPassword"
},
"subscriptions": [
{
"topic": "your/topic/here",
"characteristic": "CurrentTemperature",
"messagePattern": "(-?[0-9]{1,3}(\\.[0-9]))"
}
]
}
homebridge-http-temperature-sensor can be used together with homebridge-http-notification-server
homebridge-http-notification-server in order to receive
updates when the state changes at your external program. For details on how to implement those updates and how to
install and configure , please refer to the
README of the repository.
Down here is an example on how to configure homebridge-http-temperature-sensor to work with your implementation of the homebridge-http-notification-server.
`json`
{
"accessories": [
{
"accessory": "HTTP-TEMPERATURE",
"name": "Temperature Sensor",
"notificationID": "my-temperature-sensor",
"notificationPassword": "superSecretPassword",
"getUrl": "http://localhost/api/getTemperature"
}
]
}
* 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 "CurrentTemperature": expects an float value` in a range of 0-100 (step 0.1)