From 98b58559eded67d3cc3daa46561a6d0552c71628 Mon Sep 17 00:00:00 2001 From: naofireblade Date: Fri, 18 Aug 2017 18:49:42 +0200 Subject: [PATCH] Version 0.1.2 * Added optional parameter "interval" * Added debug library * Added hint in readme for pws --- CHANGELOG.md | 7 ++++- README.md | 33 ++++++++++++++++++----- index.js | 76 +++++++++++++++++++++++++++++----------------------- package.json | 5 ++-- 4 files changed, 78 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6fc17d..15af55b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 \ No newline at end of file +* 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 \ No newline at end of file diff --git a/README.md b/README.md index 50fd5f1..adce388 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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" + } +] +``` \ No newline at end of file diff --git a/index.js b/index.js index 6330ed3..5abe67a 100644 --- a/index.js +++ b/index.js @@ -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; @@ -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; @@ -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); @@ -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); } }; diff --git a/package.json b/package.json index 5f4576f..c5b5f8b 100644 --- a/package.json +++ b/package.json @@ -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": [ @@ -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" } } \ No newline at end of file