Skip to content

Commit 8220970

Browse files
author
QuickSander
committed
feat: Added min and max sensor config parameters.
1 parent 8a06709 commit 8220970

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ The configuration can contain the following properties:
4646
It currently expects the http server to return a float ranging from 0-100 (step 0.1) leaving out any html markup.
4747
* `pullInterval` \<integer\> **optional**: The property expects an interval in **milliseconds** in which the plugin
4848
pulls updates from your http device. For more information read [pulling updates](#the-pull-way).
49-
* `debug` \<boolean\> **optional**: Enable debug mode and write more logs.
49+
* `debug` \<boolean\> **optional**: Enable debug mode and write more logs.
50+
* `minValue` \<float>\> **optional**: Minimum lux value the sensor can return. Defaults to BH1750 light sensor module value: 2^16 -1 = 65535.
51+
* `maxValue` \<float>\> **optional**: Maximum lux value the sensor can return. Default to 0.0.
5052

5153
Below are two example configurations. One is using a simple string url and the other is using a simple urlObject.
5254
Both configs can be used for a basic plugin configuration.
@@ -78,6 +80,24 @@ Both configs can be used for a basic plugin configuration.
7880
}
7981
```
8082

83+
Specifying a custom min and max value for an 8 bit sensor:
84+
85+
```json
86+
{
87+
"accessories": [
88+
{
89+
"accessory": "HttpAmbientLightSensor",
90+
"name": "Outdoor Light Sensor",
91+
92+
"getUrl": "http://localhost/api/lux",
93+
94+
"minValue": 1.0,
95+
"maxValue": 255
96+
}
97+
]
98+
}
99+
```
100+
81101
#### UrlObject
82102

83103
A urlObject can have the following properties:

index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const MODEL = PACKAGE_JSON.name;
2323
const FIRMWARE_REVISION = PACKAGE_JSON.version;
2424

2525
const MIN_LUX_VALUE = 0.0;
26-
const MAX_LUX_VALUE = Math.pow(2, 16) - 1.0;
26+
const MAX_LUX_VALUE = Math.pow(2, 16) - 1.0; // Default BH1750 max 16bit lux value.
2727

2828
// -----------------------------------------------------------------------------
2929
// Exports
@@ -46,6 +46,8 @@ function HttpAmbientLightSensor(log, config) {
4646
this.log = log;
4747
this.name = config.name;
4848
this.debug = config.debug || false;
49+
this.minSensorValue = config.minValue || MIN_LUX_VALUE;
50+
this.maxSensorValue = config.maxValue || MAX_LUX_VALUE;
4951

5052
if (config.getUrl) {
5153
try {
@@ -65,8 +67,8 @@ function HttpAmbientLightSensor(log, config) {
6567
this.homebridgeService = new Service.LightSensor(this.name);
6668
this.homebridgeService.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
6769
.setProps({
68-
minValue: MIN_LUX_VALUE,
69-
maxValue: MAX_LUX_VALUE
70+
minValue: this.minSensorValue,
71+
maxValue: this.maxSensorValue
7072
})
7173
.on("get", this.getSensorValue.bind(this));
7274

0 commit comments

Comments
 (0)