Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0.0 #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
language: node_js
node_js:
- "node"
addons:
apt:
packages:
- libavahi-compat-libdnssd-dev
53 changes: 3 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,60 +13,13 @@ It's possible to report MQTT topic's messages as current temperature of this the
"pin": "031-45-154"
},

"accessories": [{
"accessory": "EQ3-Thermostat",
"name": "Thermostat",
"address": "00:1a:22:07:48:77"
"platforms": [{
"platform": "EQ3BLE",
"disableBoostSwitch": false
}]
}
````

## Options

You can configure the homebridge integration for the thermostat with the following options

| Option | Default value | Description |
| --- | --- | --- |
| `address` *(required)* | | Address of the thermostat |
| `discoverTimeout` | `60000` | time in milliseconds before a timeout error will be triggered |
| `connectionTimeout` | `10000` | time in milliseconds before homebridge will disconnect from the device after last action |
| `disableBoostSwitch` | `false` | if set to true, the boost switch won't be published from homebridge |
| `currentTemperature` | | MQTT configuration for current temperature |

### External current temperature configuration options

| Option | Description |
| --- | --- |
| `url` *(required)* | MQTT URL |
| `topic` *(required)* | MQTT Topic name |
| `username` | Username for accessing MQTT server |
| `password` | Password for accessing MQTT server |

## Usage with external current temperature sensor
````json
{
"bridge": {
"name": "Homebridge",
"username": "CC:22:3D:E3:CE:30",
"port": 51826,
"pin": "031-45-154"
},

"accessories": [{
"accessory": "EQ3-Thermostat",
"name": "Bedroom Thermostat",
"address": "00:1a:22:07:48:77",
"currentTemperature": {
"url": "mqtt://localhost",
"topic": "/home/sensors/bedroom/temperature",
"username": "sensors",
"password": "Sensors!"
}
}]
}
````


## License
Licensed under GPLv3 license. Copyright (c) 2015 Max Nowack

Expand Down
52 changes: 18 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "homebridge-eq3ble",
"version": "1.3.2",
"description": "Homebridge plugin to control EQ3 bluetooth thermostats",
"version": "2.0.0-beta.0",
"description": "Homebridge platform to control EQ3 bluetooth thermostats",
"main": "dist/index.js",
"scripts": {
"start": "NODE=production node ./dist/index",
"dev": "npm run build && ./node_modules/.bin/homebridge -D -U ./homebridge-config -P ./",
"lint": "./node_modules/.bin/eslint src",
"test": "npm run lint",
"build": "./node_modules/.bin/babel src -d dist"
},
"author": "Max Nowack <[email protected]>",
Expand All @@ -33,8 +34,7 @@
},
"babel": {
"presets": [
"es2015",
"stage-0"
"env"
],
"plugins": [
"transform-class-properties"
Expand All @@ -44,39 +44,23 @@
"extends": [
"airbnb-base"
],
"parser": "babel-eslint",
"rules": {
"semi": [
2,
"never"
],
"no-param-reassign": [
2,
{
"props": false
}
]
}
"parser": "babel-eslint"
},
"dependencies": {
"babel-core": "6.18.2",
"dot-prop": "^4.1.0",
"eq3ble": "1.0.0",
"is-mac": "1.0.1",
"mqtt": "1.12.0",
"p-timeout": "1.0.0"
"babel-core": "6.26.0",
"dot-prop": "^4.2.0",
"eq3ble": "^2.0.0-beta.1"
},
"devDependencies": {
"babel-cli": "6.18.0",
"babel-eslint": "7.1.0",
"babel-plugin-transform-class-properties": "6.18.0",
"babel-preset-es2015": "6.18.0",
"babel-preset-stage-0": "6.16.0",
"babel-watch": "2.0.3",
"eslint": "3.9.1",
"eslint-config-airbnb-base": "10.0.1",
"eslint-plugin-babel": "3.3.0",
"eslint-plugin-import": "2.2.0",
"homebridge": "0.4.8"
"babel-cli": "6.26.0",
"babel-eslint": "8.0.1",
"babel-plugin-transform-class-properties": "6.24.1",
"babel-preset-env": "^1.6.0",
"babel-watch": "2.0.7",
"eslint": "4.8.0",
"eslint-config-airbnb-base": "12.0.2",
"eslint-plugin-babel": "4.1.2",
"eslint-plugin-import": "2.7.0",
"homebridge": "0.4.28"
}
}
154 changes: 154 additions & 0 deletions src/Accessory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import parseInfo from './parseInfo';

let Characteristic;
let Service;

export function setup(homebridge) {
Characteristic = homebridge.hap.Characteristic; // eslint-disable-line prefer-destructuring
Service = homebridge.hap.Service; // eslint-disable-line prefer-destructuring
}

export default class EQ3BLEAccessory {
constructor(log, device, disableBoostSwitch) {
this.state = {};
this.log = log;
this.name = device.address;
this.address = device.address;
this.disableBoostSwitch = disableBoostSwitch;
this.temperatureDisplayUnits = Characteristic.TemperatureDisplayUnits.CELSIUS;

this.thermostat = device;

this.thermostatService = new Service.Thermostat(this.name);
this.informationService = new Service.AccessoryInformation();
this.boostService = new Service.Switch(`${this.name} boost mode`);

this.currentTemperature = null;

this.setupServices();
}

getServices() {
const services = [
this.informationService,
this.thermostatService,
];
if (!this.disableBoostSwitch) services.push(this.boostService);
return services;
}

setBoost(boost, callback) {
if (boost === this.state.boost) {
callback(null);
return;
}
this.state.boost = boost;
this.log('set boost', this.name, boost);
this.thermostat.setBoost(boost)
.then(() => {
this.thermostat.getInfo();
callback(null);
})
.catch(err => callback(err));
}
setThermostatState(state) {
switch (state) {
case Characteristic.TargetHeatingCoolingState.OFF: return this.thermostat.turnOff();
case Characteristic.TargetHeatingCoolingState.HEAT: return this.thermostat.turnOn();
case Characteristic.TargetHeatingCoolingState.AUTO: return this.thermostat.automaticMode();
case Characteristic.TargetHeatingCoolingState.COOL: return this.thermostat.manualMode();
default: throw new Error('Unsupported mode');
}
}
setTargetHeatingCoolingState(state, callback) {
if (state === this.state.targetHeatingCoolingState) {
callback(null);
return;
}
this.state.targetHeatingCoolingState = state;
this.log('set state', this.name, state);
this.setThermostatState(state)
.then(() => {
this.thermostat.getInfo();
callback(null);
})
.catch(err => callback(err));
}
setTargetTemperature(temperature, callback) {
if (temperature === this.state.targetTemperature) {
callback(null);
return;
}
this.state.targetTemperature = temperature;
this.log('set temperature', this.name, temperature);
this.thermostat.setTemperature(temperature)
.then(() => {
this.thermostat.getInfo();
callback(null);
})
.catch(err => callback(err));
}

setupServices() {
this.boostService.setCharacteristic(Characteristic.Name, `${this.name} Boost Mode`);

this.informationService
.setCharacteristic(Characteristic.Manufacturer, 'eq-3')
.setCharacteristic(Characteristic.Model, 'CC-RT-BLE');

const boostOn = this.boostService.getCharacteristic(Characteristic.On);
const currHeatingCoolingState = this.thermostatService
.getCharacteristic(Characteristic.CurrentHeatingCoolingState);
const targetHeatingCoolingState = this.thermostatService
.getCharacteristic(Characteristic.TargetHeatingCoolingState);
const currentTemperature = this.thermostatService
.getCharacteristic(Characteristic.CurrentTemperature)
.setProps({
minValue: -100,
maxValue: 100,
});
const targetTemperature = this.thermostatService
.getCharacteristic(Characteristic.TargetTemperature)
.setProps({
minValue: 4.5,
maxValue: 30,
});
const heatingThresholdTemperature = this.thermostatService
.getCharacteristic(Characteristic.HeatingThresholdTemperature);

boostOn
.on('get', callback => callback(null, this.state.boost))
.on('set', this.setBoost.bind(this));

currHeatingCoolingState
.on('get', callback => callback(null, this.state.currentHeatingCoolingState));

targetHeatingCoolingState
.on('get', callback => callback(null, this.state.targetHeatingCoolingState))
.on('set', this.setTargetHeatingCoolingState.bind(this));

currentTemperature
.on('get', callback => callback(null, this.state.targetTemperature));

targetTemperature
.on('get', callback => callback(null, this.state.targetTemperature))
.on('set', this.setTargetTemperature.bind(this));

heatingThresholdTemperature
.on('get', callback => callback(null, this.state.targetTemperature));

this.thermostat.on('update', (data) => {
this.log('update', this.thermostat.address, data);
this.state = parseInfo(data, Characteristic);
boostOn.setValue(this.state.boost);
currHeatingCoolingState.setValue(this.state.currentHeatingCoolingState);
targetHeatingCoolingState.setValue(this.state.targetHeatingCoolingState);
targetTemperature.setValue(this.state.targetTemperature);
heatingThresholdTemperature.setValue(this.state.targetTemperature);
currentTemperature.setValue(this.state.targetTemperature);
});

this.thermostat.getInfo();
setInterval(() => this.thermostat.getInfo(), 10 * 60 * 1000);
}
}
37 changes: 0 additions & 37 deletions src/MQTTClient.js

This file was deleted.

41 changes: 41 additions & 0 deletions src/Platform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { discoverAll } from 'eq3ble';
import EQ3BLEAccessory from './Accessory';

export { setup } from './Accessory';

export default class EQ3BLEPlatform {
constructor(log, config, api) {
this.log = log;
this.config = config;
this.disableBoostSwitch = config.disableBoostSwitch;
this.api = api;

// if (!this.config) {
// this.log.warn('Ignoring EQ3BLE Platform setup because it is not configured');
// this.disabled = true;
// }
}

accessories(callback) {
const devices = [];

if (this.disabled) {
callback(devices);
return;
}

this.log('discovery started');
const helper = discoverAll((device) => {
devices.push(device);
this.log(`discovered eq3ble device with address ${device.address}`);
}, 30 * 1000);
helper.on('stopScanning', () => {
this.log(`found ${devices.length} devices`);
callback(devices.map(device => this.createAccessory(device)));
});
}

createAccessory(device) {
return new EQ3BLEAccessory(this.log, device, this.disableBoostSwitch);
}
}
Loading