Skip to content

Commit

Permalink
Version 0.1.2
Browse files Browse the repository at this point in the history
* Added optional parameter "interval"
* Added debug library
* Added hint in readme for pws
  • Loading branch information
naofireblade committed Aug 18, 2017
1 parent 7161950 commit 98b5855
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 43 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@
* Added condition category for sunny weather
* Renamed condition values to condition categories
* Changed condition category values
* Changed service to temperature-sensor so that the device is recognized by apple home app
* Changed service to temperature-sensor so that the device is recognized by apple home app

## 0.1.2

* Added optional parameter "interval"
* Added debug library
33 changes: 27 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Feel free to leave any feedback [here](https://github.com/naofireblade/homebridg

This plugin is a fork of [homebridge-weather-station](https://github.com/kcharwood/homebridge-weather-station) that doesn't get code updates anymore which is a fork of [homebridge-wunderground](https://www.npmjs.com/package/homebridge-wunderground).

# Measured Values
## Measured Values

The following values can be displayed and used in HomeKit rules.

Expand All @@ -23,34 +23,55 @@ The following values can be displayed and used in HomeKit rules.
- Wind speed
- Station

The Apple Home app recognizes just temperature and relative humidity at the moment. So use e.g. Elgato Eve app to see all values.
The Apple Home app recognizes only temperature and relative humidity. So use e.g. Elgato Eve app to see all values.

# Example use cases
## Example use cases

- Switch on a blue light in the morning when it rains and you will need an umbrella today (or white when it snows / yellow when it's sunny).
- Start your automatic garden irrigation in the evening depending on the current weather condition and the amount of precip today.

**Hint:** To trigger rules based on time and weather condition you will need a pluging like [homebridge-delay-switch](https://www.npmjs.com/package/homebridge-delay-switch). Create a dummy switch that resets after some seconds. Set this switch to on with a timed rule. Then create a condition rule that triggers when the switch goes on depending on weather conditions of your choice.

# Installation
## Installation

1. Install homebridge using: `npm install -g homebridge`
2. Install this plugin using: `npm install -g homebridge-weather-station-extended`
3. Gather a free developer key for Weather Underground [here](http://www.wunderground.com/weather/api/).
4. Update your configuration file. See the sample below.

### Configuration
## Configuration

Add the following information to your config file. Make sure to add your API key and provice your city or postal code.

### Simple

```json
"accessories": [
{
"accessory": "WUWeatherStationExtended",
"name": "Weather Station",
"interval": "4",
"key": "XXXXXXXXXXXXXXX",
"location": "78613"
}
]
```

### Advanced

The following config contains an advanced optional setting that must not be specified.

The parameter **interval** sets the interval (minutes) in which the weather will be updated from Weather Underground. The default value is 4 minutes, which fits in the maximum of 400 updates per day for free accounts.

You can use a station from the **[Personal Weather Station Network](https://www.wunderground.com/weatherstation/overview.asp)** to receive weather information. Just enter pws:YOURID in the location parameter.

```json
"accessories": [
{
"accessory": "WUWeatherStationExtended",
"name": "Weather Station",
"interval": "4",
"key": "XXXXXXXXXXXXXXX",
"location": "pws:ICALIFOR123"
}
]
```
76 changes: 42 additions & 34 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
"use strict";
var Wunderground = require('wundergroundnode');
var inherits = require('util').inherits;
var Service, Characteristic;
var Wunderground = require('wundergroundnode'),
inherits = require('util').inherits,
debug = require('debug')('homebridge-weather-station-extended'),

var weatherStationService;
Service, Characteristic,

var WeatherCondition;
var WeatherConditionCategory;
var Rain1h;
var Rain24h;
var WindDirection;
var WindSpeed;
var AirPressure;
var Visibility;
var UVIndex;
var MeasuringStation;
weatherStationService,

var CustomUUID = {
// Eve
AirPressure: 'E863F10F-079E-48FF-8F27-9C2605A29F52',
// Other
WindSpeed: '49C8AE5A-A3A5-41AB-BF1F-12D5654F9F41',
// Weather Station
WeatherCondition: 'cd65a9ab-85ad-494a-b2bd-2f380084134d',
WeatherConditionCategory: 'cd65a9ab-85ad-494a-b2bd-2f380084134c',
// Weather Station Extended
Rain1h: '10c88f40-7ec4-478c-8d5a-bd0c3cce14b7',
Rain24h: 'ccc04890-565b-4376-b39a-3113341d9e0f',
WindDirection: '46f1284c-1912-421b-82f5-eb75008b167e',
Visibility: 'd24ecc1e-6fad-4fb5-8137-5af88bd5e857',
UVIndex: '05ba0fe0-b848-4226-906d-5b64272e05ce',
MeasuringStation: 'd1b2787d-1fc4-4345-a20e-7b5a74d693ed',
};
WeatherCondition,
WeatherConditionCategory,
Rain1h,
Rain24h,
WindDirection,
WindSpeed,
AirPressure,
Visibility,
UVIndex,
MeasuringStation,

CustomUUID = {
// Eve
AirPressure: 'E863F10F-079E-48FF-8F27-9C2605A29F52',
// Other
WindSpeed: '49C8AE5A-A3A5-41AB-BF1F-12D5654F9F41',
// Weather Station
WeatherCondition: 'cd65a9ab-85ad-494a-b2bd-2f380084134d',
WeatherConditionCategory: 'cd65a9ab-85ad-494a-b2bd-2f380084134c',
// Weather Station Extended
Rain1h: '10c88f40-7ec4-478c-8d5a-bd0c3cce14b7',
Rain24h: 'ccc04890-565b-4376-b39a-3113341d9e0f',
WindDirection: '46f1284c-1912-421b-82f5-eb75008b167e',
Visibility: 'd24ecc1e-6fad-4fb5-8137-5af88bd5e857',
UVIndex: '05ba0fe0-b848-4226-906d-5b64272e05ce',
MeasuringStation: 'd1b2787d-1fc4-4345-a20e-7b5a74d693ed',
},

var CustomCharacteristic = {};
CustomCharacteristic = {};

module.exports = function (homebridge) {
Service = homebridge.hap.Service;
Expand Down Expand Up @@ -172,6 +174,12 @@ function WUWeatherStationExtended(log, config) {
this.wunderground = new Wunderground(config['key']);
this.name = config['name'];
this.interval = config['interval'];
// default 4
this.interval = ('interval' in config ? parseInt(config['interval']) : 4);
// must be integer and positive
this.interval = (typeof this.interval !=='number' || (this.interval%1)!==0 || this.interval < 0) ? 4 : this.interval;
debug("Set update interval to: " + this.interval + " minutes.");

this.location = config['location'];
this.timestampOfLastUpdate = 0;

Expand Down Expand Up @@ -257,7 +265,7 @@ WUWeatherStationExtended.prototype = {
that.uvIndex = 0;
that.station = response['current_observation']['observation_location']['full'];

that.log("Current Weather Conditions -> Temperature: " + that.temperature + ", Humidity: " + that.humidity + ", WeatherConditionCategory: " + that.conditionValue + ", WeatherCondition: "
debug("Current Weather Conditions -> Temperature: " + that.temperature + ", Humidity: " + that.humidity + ", WeatherConditionCategory: " + that.conditionValue + ", WeatherCondition: "
+ that.condition + ", Rain1h: " + that.rain_1h_metric + ", Rain24h: " + that.rain_24h_metric + ", WindDirection: " + that.windDirection + ", WindSpeed: "
+ that.windSpeed + ", AirPressure: " + that.airPressure + ", Visibility: " + that.visibility + ", UVIndex: " + that.uvIndex + ", MeasuringStation: " + that.station);

Expand All @@ -278,7 +286,7 @@ WUWeatherStationExtended.prototype = {
}
});

// wunderground limits to 500 api calls a day. Making a call every 4 minutes == 360 calls
setTimeout(this.updateWeatherConditions.bind(this), (that.interval) * 60 * 1000);
// wunderground limits to 500 api calls a day. Making a call every x minutes (default 4 minutes = 360 calls)
setTimeout(this.updateWeatherConditions.bind(this), (this.interval) * 60 * 1000);
}
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebridge-weather-station-extended",
"version": "0.1.1",
"version": "0.1.2",
"description": "A comprehensive weather station plugin for homebridge.",
"license": "MIT",
"keywords": [
Expand All @@ -20,6 +20,7 @@
"url": "https://github.com/naofireblade/homebridge-weather-station-extended.git"
},
"dependencies": {
"wundergroundnode": ">=0.9"
"wundergroundnode": ">=0.9",
"debug": "^2.2.0"
}
}

0 comments on commit 98b5855

Please sign in to comment.