diff --git a/README.md b/README.md index e69de29..a6d24f1 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,24 @@ +# Homebridge Homewizard Power Consumption +[![npm](https://img.shields.io/npm/dt/homebridge-homewizard-power-consumption.svg)](https://www.npmjs.com/package/homebridge-homewizard-power-consumption) +[![npm](https://img.shields.io/npm/v/homebridge-homewizard-power-consumption.svg)](https://www.npmjs.com/package/homebridge-homewizard-power-consumption) + +This Homebrudge plugin offers two sensors; one for the current power consumption and one for the current power return. + +## Installation +To install the *Homebridge Homewizard Power Consumption* plugin follow these steps: + +- Follow the instructions on the [Homebridge Wiki](https://homebridge.io/how-to-install-homebridge) to install Node.js and Homebridge; +- Install the *Homebridge Homewizard Power Consumption* plugin through Homebridge Config UI X or manually; + ``` + $ sudo npm -g i homebridge-homewizard-power-consumption + ``` +- Edit config.json and add the *HomewizardPowerConsumption* platform. E.g; + ``` + { + "platform": "HomewizardPowerConsumption", + "ip": "<>" + } + ``` + +## Caveats +Both sensors are exposed as Lux (light) sensors. The Lux level indicates the w level of the consumption. E.g. If your home has a power consumption of 2000w, the sensor will show 2000lux. diff --git a/package.json b/package.json index 0282bbc..a0dc3cd 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "displayName": "Homebridge Homewizard Power Consumption", "name": "homebridge-homewizard-power-consumption", - "version": "0.0.1", - "description": "", + "version": "1.0.0", + "description": "See current power consumption or power return in Homekit", "license": "Apache-2.0", "author": "Jasper Seinhorst", "repository": { @@ -24,7 +24,8 @@ "prepublishOnly": "npm run lint && npm run build" }, "keywords": [ - "homebridge-plugin" + "homebridge-plugin", + "Homewizard" ], "devDependencies": { "@types/node": "^20.2.5", diff --git a/src/Accessories/PowerConsumption.ts b/src/Accessories/PowerConsumption.ts index 249a080..ead6c09 100644 --- a/src/Accessories/PowerConsumption.ts +++ b/src/Accessories/PowerConsumption.ts @@ -18,7 +18,6 @@ export default class PowerConsumption implements HomewizardPowerConsumptionAcces const minimumLuxLevel = 0.0001; let newPowerConsumptionLevel = minimumLuxLevel; if (consumption > 0) { - console.log('consumption > 0'); newPowerConsumptionLevel = consumption; } this.chargingPower.setCharacteristic(this.Characteristic.CurrentAmbientLightLevel, newPowerConsumptionLevel); diff --git a/src/Accessories/PowerReturn.ts b/src/Accessories/PowerReturn.ts index 7bb3683..aa1a7c4 100644 --- a/src/Accessories/PowerReturn.ts +++ b/src/Accessories/PowerReturn.ts @@ -18,7 +18,6 @@ export default class PowerReturn implements HomewizardPowerConsumptionAccessory const minimumLuxLevel = 0.0001; let newPowerConsumptionLevel = minimumLuxLevel; if (consumption < 0) { - console.log('consumption < 0', consumption * -1); newPowerConsumptionLevel = consumption * -1; } this.chargingPower.setCharacteristic(this.Characteristic.CurrentAmbientLightLevel, newPowerConsumptionLevel); diff --git a/src/Platform.ts b/src/Platform.ts index 7f1165f..05cd22c 100644 --- a/src/Platform.ts +++ b/src/Platform.ts @@ -8,7 +8,7 @@ export class HomewizardPowerConsumption implements DynamicPlatformPlugin { public readonly Service: typeof Service = this.api.hap.Service; public readonly Characteristic: typeof Characteristic = this.api.hap.Characteristic; public readonly accessories: PlatformAccessory[] = []; - private readonly heartBeatInterval = 5 * 1000; // every minute + private readonly heartBeatInterval = 60 * 1000; // every minute private devices: HomewizardPowerConsumptionAccessory[] = []; @@ -67,11 +67,15 @@ export class HomewizardPowerConsumption implements DynamicPlatformPlugin { } private async heartBeat() { - const { data } = await axios.get(`http://${this.config.ip}/api/v1/data`); - const consumption = data.active_power_w as number; - - this.devices.forEach((device: HomewizardPowerConsumptionAccessory) => { - device.beat(consumption); - }); + try { + const { data } = await axios.get(`http://${this.config.ip}/api/v1/data`); + const consumption = data.active_power_w as number; + this.devices.forEach((device: HomewizardPowerConsumptionAccessory) => { + device.beat(consumption); + }); + } catch(error) { + this.log.error('Something went wrong'); + this.log.error(error); + } } }