├── .eslintrc.json ├── .gitignore ├── LICENSE ├── README.md ├── example-config.json ├── images ├── eve_overview.PNG └── homekit_overview.PNG ├── index.js └── package.json /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "es6": true, 4 | "node": true 5 | }, 6 | "extends": "eslint:recommended", 7 | "parserOptions": { 8 | "ecmaVersion": 8, 9 | "sourceType": "module" 10 | }, 11 | "rules": { 12 | "indent": [ 13 | "error", 14 | 2, 15 | { 16 | "SwitchCase": 1 17 | } 18 | ], 19 | "linebreak-style": [ 20 | "error", 21 | "unix" 22 | ], 23 | "quotes": [ 24 | "error", 25 | "single" 26 | ], 27 | "semi": [ 28 | "error", 29 | "always" 30 | ], 31 | "no-console": [ 32 | "off" 33 | ] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | 63 | images/ 64 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Seyd 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # homebridge-broadband v1 2 | Homebridge Plugin for Broadband speed measurement as Temperature sensor 3 | 4 | [![npm](https://img.shields.io/npm/v/homebridge-broadband.svg?style=flat-square)](https://www.npmjs.com/package/homebridge-broadband) 5 | [![npm](https://img.shields.io/npm/dt/homebridge-broadband.svg?style=flat-square)](https://www.npmjs.com/package/homebridge-broadband) 6 | [![GitHub last commit](https://img.shields.io/github/last-commit/SeydX/homebridge-broadband.svg?style=flat-square)](https://github.com/SeydX/homebridge-broadband) 7 | 8 | # Homebridge plugin for checking your broadband speed 9 | 10 | This homebridge plugin exposes a new temperature sensor to HomeKit to see your broadband speed at home. It also has new characteristics to see the download- and upload speed, also your ping within i.e. Elgato EVE app. It also supports Fakegato. 11 | 12 | See [Images](https://github.com/SeydX/homebridge-broadband/tree/master/images/) for more details. 13 | 14 | # Installation instructions 15 | 16 | After [Homebridge](https://github.com/nfarina/homebridge) has been installed: 17 | 18 | ```sudo npm install -g homebridge-broadband@latest --unsafe-perm``` 19 | 20 | 21 | ## Example config.json: 22 | 23 | ``` 24 | { 25 | "bridge": { 26 | ... 27 | }, 28 | "accessories": [ 29 | { 30 | "accessory": "Broadband", 31 | "name": "Broadband", 32 | "maxTime": 5, 33 | "interval": 60 34 | } 35 | ] 36 | } 37 | ``` 38 | 39 | 40 | ## Options 41 | 42 | | **Attributes** | **Required** | **Usage** | 43 | |------------|----------|-------| 44 | | accessory | **Yes** | Must be "Broadband" | 45 | | name | No | Name for the Accessory (Default: Broadband) | 46 | | maxTime | No | The maximum length of a single test run in seconds (Default: 5s) | 47 | | interval | No | Interval for checing the broadband in mins (Default: 60min) | 48 | 49 | See [Example Config](https://github.com/SeydX/homebridge-broadband/blob/master/example-config.json) for more details. 50 | 51 | ## Supported clients 52 | 53 | This plugin have been verified to work with the following apps on iOS 11.2.5: 54 | 55 | * Apple Home 56 | * Elgato Eve 57 | 58 | 59 | ## Known issues | TODO 60 | 61 | /// 62 | 63 | 64 | ## Contributing 65 | 66 | You can contribute to this homebridge plugin in following ways: 67 | 68 | - [Report issues](https://github.com/SeydX/homebridge-broadband/issues) and help verify fixes as they are checked in. 69 | - Review the [source code changes](https://github.com/SeydX/homebridge-broadband/pulls). 70 | - Contribute bug fixes. 71 | - Contribute changes to extend the capabilities 72 | 73 | Pull requests are accepted. 74 | -------------------------------------------------------------------------------- /example-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "bridge": { 3 | ... 4 | }, 5 | "accessories": [ 6 | { 7 | "accessory": "Broadband", 8 | "name": "Broadband", 9 | "maxTime": 5, 10 | "interval": 60 11 | } 12 | ], 13 | "platforms": [ 14 | ... 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /images/eve_overview.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seydx/homebridge-broadband/009b6967290dc8a7b58724356fe2de9174b16710/images/eve_overview.PNG -------------------------------------------------------------------------------- /images/homekit_overview.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seydx/homebridge-broadband/009b6967290dc8a7b58724356fe2de9174b16710/images/homekit_overview.PNG -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const speedTest = require('speedtest-net'); 4 | const inherits = require('util').inherits; 5 | const moment = require('moment'); 6 | 7 | var Service, Characteristic, FakeGatoHistoryService, HomebridgeAPI; 8 | 9 | module.exports = function(homebridge) { 10 | FakeGatoHistoryService = require('fakegato-history')(homebridge); 11 | HomebridgeAPI = homebridge; 12 | Service = homebridge.hap.Service; 13 | Characteristic = homebridge.hap.Characteristic; 14 | homebridge.registerAccessory('homebridge-broadband', 'Broadband', Broadband); 15 | }; 16 | 17 | function Broadband(log, config, api) { 18 | 19 | //HB 20 | this.config = config; 21 | this.log = log; 22 | this.api = api; 23 | 24 | //BASE 25 | this.name = config['name'] || 'Broadband'; 26 | this.displayName = config.name; 27 | this.maxTime = (config['maxTime'] * 1000) || 5 * 1000; 28 | this.interval = (config['interval'] * 60 * 1000) || 60 * 60 * 1000; 29 | !this.dlspeed ? this.dlspeed = 0 : this.dlspeed; 30 | !this.ulspeed ? this.ulspeed = 0 : this.ulspeed; 31 | !this.ping ? this.ping = 0 : this.ping; 32 | 33 | Characteristic.DownloadSpeed = function() { 34 | Characteristic.call(this, 'Download', 'da70da1f-da72-4db3-81c2-99f158a15a9a'); 35 | this.setProps({ 36 | format: Characteristic.Formats.FLOAT, 37 | unit: 'Mbps', 38 | maxValue: 99999, 39 | minValue: 0, 40 | minStep: 0.01, 41 | perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY] 42 | }); 43 | this.value = this.getDefaultValue(); 44 | }; 45 | inherits(Characteristic.DownloadSpeed, Characteristic); 46 | Characteristic.DownloadSpeed.UUID = 'da70da1f-da72-4db3-81c2-99f158a15a9a'; 47 | 48 | Characteristic.UploadSpeed = function() { 49 | Characteristic.call(this, 'Upload', 'ab74289e-d516-4a12-b2ae-1b32a74c035f'); 50 | this.setProps({ 51 | format: Characteristic.Formats.FLOAT, 52 | unit: 'Mbps', 53 | maxValue: 99999, 54 | minValue: 0, 55 | minStep: 0.01, 56 | perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY] 57 | }); 58 | this.value = this.getDefaultValue(); 59 | }; 60 | inherits(Characteristic.UploadSpeed, Characteristic); 61 | Characteristic.UploadSpeed.UUID = 'ab74289e-d516-4a12-b2ae-1b32a74c035f'; 62 | 63 | Characteristic.Ping = function() { 64 | Characteristic.call(this, 'Ping', 'cc65a09a-e052-410c-981d-c11bde2c3f60'); 65 | this.setProps({ 66 | format: Characteristic.Formats.INT, 67 | unit: 'ms', 68 | maxValue: 999, 69 | minValue: 0, 70 | minStep: 1, 71 | perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY] 72 | }); 73 | this.value = this.getDefaultValue(); 74 | }; 75 | inherits(Characteristic.Ping, Characteristic); 76 | Characteristic.Ping.UUID = 'cc65a09a-e052-410c-981d-c11bde2c3f60'; 77 | 78 | } 79 | 80 | Broadband.prototype = { 81 | 82 | getServices: function() { 83 | 84 | this.informationService = new Service.AccessoryInformation() 85 | .setCharacteristic(Characteristic.Name, this.name) 86 | .setCharacteristic(Characteristic.Identify, this.name) 87 | .setCharacteristic(Characteristic.Manufacturer, 'SeydX') 88 | .setCharacteristic(Characteristic.Model, 'Broadband Speedtest') 89 | .setCharacteristic(Characteristic.SerialNumber, '1234567890'); 90 | 91 | this.Sensor = new Service.TemperatureSensor(this.name); 92 | 93 | this.Sensor.getCharacteristic(Characteristic.CurrentTemperature) 94 | .setProps({ 95 | minValue: 0, 96 | maxValue: 9999, 97 | minStep: 0.01 98 | }) 99 | .updateValue(this.dlspeed); 100 | 101 | this.Sensor.addCharacteristic(Characteristic.DownloadSpeed); 102 | this.Sensor.getCharacteristic(Characteristic.DownloadSpeed) 103 | .updateValue(this.dlspeed); 104 | 105 | this.Sensor.addCharacteristic(Characteristic.UploadSpeed); 106 | this.Sensor.getCharacteristic(Characteristic.UploadSpeed) 107 | .updateValue(this.ulspeed); 108 | 109 | this.Sensor.addCharacteristic(Characteristic.Ping); 110 | this.Sensor.getCharacteristic(Characteristic.Ping) 111 | .updateValue(this.ping); 112 | 113 | this.historyService = new FakeGatoHistoryService('weather', this, { 114 | storage: 'fs', 115 | disableTimer: true, 116 | path: HomebridgeAPI.user.cachedAccessoryPath() 117 | }); 118 | 119 | this.getData(); 120 | this.getHistory(); 121 | 122 | return [this.informationService, this.Sensor, this.historyService]; 123 | 124 | }, 125 | 126 | getData: function() { 127 | 128 | const self = this; 129 | self.log('Starting broadband measurement...'); 130 | 131 | speedTest({ 132 | maxTime: self.maxTime 133 | }) 134 | .on('data', data => { 135 | self.dlspeed = data.speeds.download; 136 | self.ulspeed = data.speeds.upload; 137 | self.ping = data.server.ping; 138 | 139 | self.log('Download: ' + self.dlspeed + ' Mbps'); 140 | self.log('Upload: ' + self.ulspeed + ' Mbps'); 141 | self.log('Ping: ' + self.ping + ' ms'); 142 | 143 | self.Sensor.getCharacteristic(Characteristic.CurrentTemperature).updateValue(self.dlspeed); 144 | self.Sensor.getCharacteristic(Characteristic.DownloadSpeed).updateValue(self.dlspeed); 145 | self.Sensor.getCharacteristic(Characteristic.UploadSpeed).updateValue(self.ulspeed); 146 | self.Sensor.getCharacteristic(Characteristic.Ping).updateValue(self.ping); 147 | setTimeout(function() { 148 | self.getData(); 149 | }, self.interval); 150 | }) 151 | .on('error', err => { 152 | self.log('An error occured: ' + err + ' - Trying again in 1 min'); 153 | self.dlspeed = self.dlspeed; 154 | self.ulspeed = self.ulspeed; 155 | self.ping = self.ping; 156 | self.Sensor.getCharacteristic(Characteristic.CurrentTemperature).updateValue(self.dlspeed); 157 | self.Sensor.getCharacteristic(Characteristic.DownloadSpeed).updateValue(self.dlspeed); 158 | self.Sensor.getCharacteristic(Characteristic.UploadSpeed).updateValue(self.ulspeed); 159 | self.Sensor.getCharacteristic(Characteristic.Ping).updateValue(self.ping); 160 | setTimeout(function() { 161 | self.getData(); 162 | }, 60000); 163 | }); 164 | 165 | }, 166 | 167 | getHistory: function() { 168 | const self = this; 169 | 170 | if (self.dlspeed != 0 && self.ulspeed != 0 && self.ping != 0) { 171 | self.historyService.addEntry({ 172 | time: moment().unix(), 173 | temp: self.dlspeed, 174 | pressure: self.ping, 175 | humidity: self.ulspeed 176 | }); 177 | } 178 | setTimeout(function() { 179 | self.getHistory(); 180 | }, 8 * 60 * 1000); //every 8 mins 181 | }, 182 | 183 | identify: function(callback) { 184 | this.log(this.name + ': Identified!'); 185 | callback(); 186 | } 187 | 188 | }; 189 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "homebridge-broadband", 3 | "version": "1.0.3", 4 | "description": "homebridge-broadband", 5 | "main": "index.js", 6 | "devDependencies": {}, 7 | "scripts": { 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/SeydX/homebridge-broadband.git" 13 | }, 14 | "author": "SeydX (https://github.com/SeydX/homebridge-broadband)", 15 | "license": "MIT", 16 | "bugs": { 17 | "url": "https://github.com/SeydX/homebridge-broadband/issues" 18 | }, 19 | "homepage": "https://github.com/SeydX/homebridge-broadband#readme", 20 | "keywords": [ 21 | "broadband", 22 | "speed", 23 | "homebridge", 24 | "homebridge-plugin", 25 | "plugin" 26 | ], 27 | "engines": { 28 | "node": ">=0.12.0", 29 | "homebridge": ">=0.2.0" 30 | }, 31 | "dependencies": { 32 | "speedtest-net": "^1.4.2", 33 | "fakegato-history": "^0.5.1", 34 | "moment": "^2.22.1" 35 | } 36 | } 37 | --------------------------------------------------------------------------------