Skip to content

Commit

Permalink
docs: add setup guide to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jasper-seinhorst committed Mar 3, 2024
1 parent af27317 commit 57a40fc
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 12 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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": "<<IP of your P1>>"
}
```

## 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.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -24,7 +24,8 @@
"prepublishOnly": "npm run lint && npm run build"
},
"keywords": [
"homebridge-plugin"
"homebridge-plugin",
"Homewizard"
],
"devDependencies": {
"@types/node": "^20.2.5",
Expand Down
1 change: 0 additions & 1 deletion src/Accessories/PowerConsumption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/Accessories/PowerReturn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 11 additions & 7 deletions src/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];


Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 57a40fc

Please sign in to comment.