homebridge-tesla-powerwall2 4.2.4-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +171 -0
- package/LICENSE +15 -0
- package/README.md +380 -0
- package/config.schema.json +119 -0
- package/dist/accessories/gridpowersensor.d.ts +63 -0
- package/dist/accessories/gridpowersensor.d.ts.map +1 -0
- package/dist/accessories/gridpowersensor.js +139 -0
- package/dist/accessories/gridstatus.d.ts +30 -0
- package/dist/accessories/gridstatus.d.ts.map +1 -0
- package/dist/accessories/gridstatus.js +85 -0
- package/dist/accessories/powermeter.d.ts +34 -0
- package/dist/accessories/powermeter.d.ts.map +1 -0
- package/dist/accessories/powermeter.js +118 -0
- package/dist/accessories/powerwall.d.ts +54 -0
- package/dist/accessories/powerwall.d.ts.map +1 -0
- package/dist/accessories/powerwall.js +213 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/lib/http-client.d.ts +41 -0
- package/dist/lib/http-client.d.ts.map +1 -0
- package/dist/lib/http-client.js +226 -0
- package/dist/platform.d.ts +51 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/platform.js +219 -0
- package/dist/settings.d.ts +9 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/settings.js +12 -0
- package/dist/types.d.ts +56 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/eslint.config.mjs +35 -0
- package/nodemon.json +10 -0
- package/package.json +58 -0
- package/src/accessories/gridpowersensor.ts +156 -0
- package/src/accessories/gridstatus.ts +96 -0
- package/src/accessories/powermeter.ts +130 -0
- package/src/accessories/powerwall.ts +237 -0
- package/src/index.ts +11 -0
- package/src/lib/http-client.ts +278 -0
- package/src/platform.ts +265 -0
- package/src/settings.ts +9 -0
- package/src/types.ts +68 -0
- package/test/integration/test-connection.js +188 -0
- package/test/integration/validate-grid-sensors.js +176 -0
- package/test/powerwall-charging-state.test.js +85 -0
- package/test/test.js +214 -0
- package/tsconfig.json +38 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [4.2.4] - 2026-06-??
|
|
6
|
+
|
|
7
|
+
Plugin renamed from homebridge-tesla-powerwall to homebridge-tesla-powerwall2 and maintainer changed to @dkerr64
|
|
8
|
+
- To disquinguish from the legacy plugin that no longer works
|
|
9
|
+
- To allow us to publish this new plugin on [npmjs](https://www.npmjs.com/) as maintainer of original plugin is not responding to outreach on whether he would accept a pull request and update the published plugin
|
|
10
|
+
- And reflects that the plugin is only tested with Powerwall 2
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Name of grid sensor changed from _Online_ to _Offline_ for consistency with other sensors that trigger when the state changes to the named state
|
|
15
|
+
- Name of home/load sensor changed from _Load_ to _Home_ for consistency with Tesla's own app
|
|
16
|
+
|
|
17
|
+
## [4.2.3] - 2026-06-11
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
- Power meters (solar/grid/load) now report the **actual watts** instead of
|
|
21
|
+
one-tenth of the reading. The previous `power / 10` scaling was removed;
|
|
22
|
+
HomeKit's ambient-light (lux) characteristic accepts up to 100000, which
|
|
23
|
+
comfortably covers any residential Powerwall. (#18)
|
|
24
|
+
- Battery level and the battery lightbulb brightness now **round down**
|
|
25
|
+
(`Math.floor`) instead of to the nearest integer, matching the Tesla and
|
|
26
|
+
Apple Home apps and the HomeKit integer 0–100 spec. (#19)
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
- `tsconfig.json` now uses `"module"`/`"moduleResolution": "nodenext"`
|
|
30
|
+
(the previous `"node"` value is deprecated), matching the current
|
|
31
|
+
homebridge-plugin-template. Relative dynamic imports were given explicit
|
|
32
|
+
`.js` extensions as required by `nodenext`. (#17)
|
|
33
|
+
- Added a `lint` script (`eslint . --max-warnings=0`) and made
|
|
34
|
+
`prepublishOnly` run lint before build, matching the plugin template.
|
|
35
|
+
Fixed the existing lint errors (switch-case indentation, unused import)
|
|
36
|
+
and renamed `eslint.config.js` → `eslint.config.mjs` to clear the
|
|
37
|
+
`MODULE_TYPELESS_PACKAGE_JSON` warning. (#16)
|
|
38
|
+
|
|
39
|
+
### Documentation
|
|
40
|
+
- Expanded the README's power-meter description to spell out what each
|
|
41
|
+
meter shows (Solar = generation, Grid = utility flow, Load = household
|
|
42
|
+
consumption) and to note that the lux value equals actual watts.
|
|
43
|
+
|
|
44
|
+
## [4.2.2] - 2026-06-10
|
|
45
|
+
|
|
46
|
+
### Changed (breaking for existing automations)
|
|
47
|
+
- Inverted the contact-sensor polarity for the `Exporting` and `Importing`
|
|
48
|
+
sensors so it now matches HomeKit's door-sensor convention: **Closed
|
|
49
|
+
while idle, Open while active**. Previously the sensors reported
|
|
50
|
+
`Closed` whenever export/import was actively flowing, which left both
|
|
51
|
+
tiles showing `Open` at rest and made automations read backwards. If you
|
|
52
|
+
built automations on the old polarity (triggering on "detects contact"
|
|
53
|
+
while flow was active), flip them to trigger on the sensor opening
|
|
54
|
+
instead. The `Grid Online` sensor is unchanged — it was already
|
|
55
|
+
Closed-at-rest.
|
|
56
|
+
- Renamed the three grid contact sensors to action-oriented labels so the
|
|
57
|
+
tile name alone conveys the meaning:
|
|
58
|
+
- `Tesla Powerwall Grid Status` → `Tesla Powerwall Grid Online`
|
|
59
|
+
- `Tesla Powerwall Grid Feeding` → `Tesla Powerwall Exporting`
|
|
60
|
+
- `Tesla Powerwall Grid Pulling` → `Tesla Powerwall Importing`
|
|
61
|
+
Accessory UUIDs are seeded by stable strings, so existing installs keep
|
|
62
|
+
their HomeKit identity; only new installs see the new defaults, and any
|
|
63
|
+
Home-app rename overrides the plugin label anyway. Config keys
|
|
64
|
+
(`enableGridStatus`, `enableGridPowerSensors`) are unchanged.
|
|
65
|
+
- `AccessoryInformation.Model` strings updated to match the new names.
|
|
66
|
+
- Homebridge UI titles/descriptions in `config.schema.json` reworded for
|
|
67
|
+
the new names (underlying property names unchanged).
|
|
68
|
+
|
|
69
|
+
### Documentation
|
|
70
|
+
- README "Accessories Provided" section rewritten with the new names and
|
|
71
|
+
explicit Open/Closed state mapping for each contact sensor, plus a note
|
|
72
|
+
on HomeKit's door-sensor terminology (Open = event, Closed = idle).
|
|
73
|
+
- Automation examples updated to reference the new accessory names and the
|
|
74
|
+
new "sensor opens" trigger phrasing.
|
|
75
|
+
|
|
76
|
+
## [4.2.1] - 2026-06-10
|
|
77
|
+
|
|
78
|
+
### Fixed
|
|
79
|
+
- Inverted Powerwall charging state (#10). The Tesla aggregates API reports
|
|
80
|
+
`battery.instant_power` as positive when discharging and negative when
|
|
81
|
+
charging; the comparison in `getChargingState` had the polarity reversed,
|
|
82
|
+
so HomeKit saw `CHARGING` during discharge and vice versa.
|
|
83
|
+
|
|
84
|
+
### Tests
|
|
85
|
+
- Added unit coverage for `PowerwallAccessory.getChargingState` around the
|
|
86
|
+
charging/discharging/noise-band cases.
|
|
87
|
+
|
|
88
|
+
## [4.2.0] - 2026-06-09
|
|
89
|
+
|
|
90
|
+
### Changed
|
|
91
|
+
- Replaced `node-fetch` with `undici` and Node's native fetch
|
|
92
|
+
- Bumped Homebridge dev dependency to 2.x (matches `engines` field)
|
|
93
|
+
- Updated `@types/node`, `typescript-eslint`, `mocha`, `nock`, `tough-cookie` to latest
|
|
94
|
+
- Switched coverage tooling from `nyc` to `c8` (no instrumentation, no vulnerable transitives)
|
|
95
|
+
- Shared cache window (3s default) on all Powerwall API calls so concurrent accessory polls share a single network request
|
|
96
|
+
- `HttpClient` interface now strongly typed in `TeslaPowerwallPlatformInterface` (was `any`)
|
|
97
|
+
|
|
98
|
+
### Removed
|
|
99
|
+
- Unused runtime deps: `moment`, `fakegato-history`, `node-fetch`, `@types/node-fetch`
|
|
100
|
+
- Unused dev deps: `chalk`, `tough-cookie`, `events`
|
|
101
|
+
- Orphaned `src/configUI.ts` (never wired up)
|
|
102
|
+
- Orphaned `src/helper/` JS files (pre-TypeScript-rewrite leftovers)
|
|
103
|
+
- Dead `createAccessoryHandler` method in `platform.ts`
|
|
104
|
+
- Legacy `.eslintrc.json` (superseded by flat `eslint.config.js`)
|
|
105
|
+
- `README.md.old`
|
|
106
|
+
- `enableHistory` config option (no implementation existed)
|
|
107
|
+
|
|
108
|
+
### Security
|
|
109
|
+
- Reduced `npm audit` findings from 12 → 0 by adding `overrides` for the
|
|
110
|
+
remaining mocha transitives (`diff` → `^9.0.0`, `serialize-javascript` →
|
|
111
|
+
`^7.0.5`). Mocha's runtime usage (`diffWordsWithSpace`, `createPatch`) is
|
|
112
|
+
stable across these majors; the test suite passes unchanged.
|
|
113
|
+
|
|
114
|
+
### Tests
|
|
115
|
+
- Replaced the legacy mocha suite (which targeted the pre-TypeScript static-platform shape with `0_powerwall`/`1_solar`/`PowerMeterService` etc.) with focused tests for the current `DynamicPlatformPlugin`: plugin registration, platform construction error paths, and HttpClient auth/401-retry/cache behaviour exercised through `undici.MockAgent`
|
|
116
|
+
- `HttpClient` now accepts an optional `dispatcher` and `autoStartLogin` flag so its HTTP layer is unit-testable
|
|
117
|
+
- Migrated `test/integration/*.js` scripts off `node-fetch`/`tough-cookie` onto `undici`
|
|
118
|
+
|
|
119
|
+
## [4.1.0] - 2026-01-16
|
|
120
|
+
|
|
121
|
+
### Added
|
|
122
|
+
- **Grid Power Sensors** (addresses Issue #35)
|
|
123
|
+
- New "Grid Feeding" sensor triggers when exporting power to grid
|
|
124
|
+
- New "Grid Pulling" sensor triggers when importing power from grid
|
|
125
|
+
- Configurable threshold (default 50W) to prevent false triggers
|
|
126
|
+
- Perfect for HomeKit automations and energy management
|
|
127
|
+
- Validation script for testing sensor behavior
|
|
128
|
+
|
|
129
|
+
- **Testing Tools**
|
|
130
|
+
- Grid sensor validation script (`test/integration/validate-grid-sensors.js`)
|
|
131
|
+
- Real-time power flow visualization
|
|
132
|
+
- Sensor state evaluation
|
|
133
|
+
|
|
134
|
+
- **Documentation**
|
|
135
|
+
- Comprehensive automation examples (4 use cases)
|
|
136
|
+
- API limitation documentation for operation mode control
|
|
137
|
+
- Testing instructions
|
|
138
|
+
- Configuration examples
|
|
139
|
+
|
|
140
|
+
### Changed
|
|
141
|
+
- Updated all dependencies to latest compatible versions
|
|
142
|
+
- @eslint/js: 9.8.0 → 9.39.2
|
|
143
|
+
- @types/node: 20.5.0 → 20.19.30
|
|
144
|
+
- eslint: 9.8.0 → 9.39.2
|
|
145
|
+
- homebridge: 1.8.0 → 1.11.1
|
|
146
|
+
- typescript: 5.2.2 → 5.9.3
|
|
147
|
+
- And more...
|
|
148
|
+
|
|
149
|
+
### Fixed
|
|
150
|
+
- Memory leaks in all accessories (added proper cleanup methods)
|
|
151
|
+
- Type safety improvements across the codebase
|
|
152
|
+
- Nullish coalescing for numeric config values (allows 0 as valid threshold)
|
|
153
|
+
- Parameter validation in validation script
|
|
154
|
+
|
|
155
|
+
### Security
|
|
156
|
+
- Fixed 4 npm audit vulnerabilities (6→2 remaining low-severity dev dependencies)
|
|
157
|
+
- CodeQL security scan: 0 alerts
|
|
158
|
+
|
|
159
|
+
### Documented
|
|
160
|
+
- **Operation Mode Control Limitations** (Issue #54)
|
|
161
|
+
- Local API does not support changing operation modes
|
|
162
|
+
- Requires Tesla Fleet API (cloud-based)
|
|
163
|
+
- Provided alternatives and future roadmap
|
|
164
|
+
|
|
165
|
+
## [4.0.1] - Previous Version
|
|
166
|
+
- TypeScript rewrite
|
|
167
|
+
- Homebridge 2.0 compatibility
|
|
168
|
+
- Modern dependency updates
|
|
169
|
+
|
|
170
|
+
[4.1.0]: https://github.com/nmuldoon/homebridge-tesla-powerwall/compare/v4.0.1...v4.1.0
|
|
171
|
+
[4.0.1]: https://github.com/nmuldoon/homebridge-tesla-powerwall/releases/tag/v4.0.1
|
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Copyright (c) 2018 Marvin Dostal, Timo Dostal
|
|
2
|
+
Copyright (c) 2020, 2021 Marvin Dostal
|
|
3
|
+
Copyright (c) 2021 Additional contributors
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
11
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
# homebridge-tesla-powerwall2
|
|
2
|
+
[](https://www.npmjs.com/package/homebridge-tesla-powerwall2)
|
|
3
|
+
[](https://www.npmjs.com/package/homebridge-tesla-powerwall2)
|
|
4
|
+
|
|
5
|
+
**Unofficial** Homebridge Plugin for the Tesla Powerwall - **Now Updated for Homebridge 2.0!**
|
|
6
|
+
|
|
7
|
+
Communication with the Tesla Powerwall is according to https://github.com/vloschiavo/powerwall2 .
|
|
8
|
+
|
|
9
|
+
This plugin has been completely modernized with TypeScript, updated dependencies, and Homebridge 2.0 compatibility while maintaining all original functionality. With thanks to @nmuldoon
|
|
10
|
+
|
|
11
|
+
See [CHANGELOG.md](https://github.com/dkerr64/homebridge-tesla-powerwall2/blob/master/CHANGELOG.md) for latest updates and history
|
|
12
|
+
|
|
13
|
+
## Requirements
|
|
14
|
+
|
|
15
|
+
- **Node.js**: 18.15.0 or higher
|
|
16
|
+
- **Homebridge**: 1.6.0 or higher
|
|
17
|
+
|
|
18
|
+
# Installation
|
|
19
|
+
|
|
20
|
+
## Recommended: Homebridge UI
|
|
21
|
+
1. Install [Homebridge](https://github.com/homebridge/homebridge): see the [Homebridge wiki](https://github.com/homebridge/homebridge/wiki)
|
|
22
|
+
2. In the Homebridge Web-GUI, search for the "Tesla Powerwall" plugin and install it.
|
|
23
|
+
3. Configure the plugin using the config UI interface.
|
|
24
|
+
|
|
25
|
+
## Command Line Installation
|
|
26
|
+
```bash
|
|
27
|
+
npm install -g homebridge-tesla-powerwall2
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Testing Your Connection
|
|
31
|
+
|
|
32
|
+
Before configuring the plugin, test your connection to ensure everything works:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# Navigate to the plugin directory (if installed globally)
|
|
36
|
+
cd $(npm root -g)/homebridge-tesla-powerwall2
|
|
37
|
+
|
|
38
|
+
# Run the connection test
|
|
39
|
+
node test/integration/test-connection.js <ip-address> <password>
|
|
40
|
+
|
|
41
|
+
# Example:
|
|
42
|
+
node test/integration/test-connection.js 192.168.1.50 your-password-here
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The test script will:
|
|
46
|
+
- ✅ Verify authentication
|
|
47
|
+
- ✅ Test battery status retrieval
|
|
48
|
+
- ✅ Test power flow data
|
|
49
|
+
- ✅ Test grid connectivity status
|
|
50
|
+
- 📋 Provide configuration template for Homebridge
|
|
51
|
+
|
|
52
|
+
### Testing Grid Power Sensors ⭐ **NEW**
|
|
53
|
+
|
|
54
|
+
To validate that the grid power sensors will work correctly:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# Run the grid sensor validator
|
|
58
|
+
node test/integration/validate-grid-sensors.js <ip-address> <password> [threshold]
|
|
59
|
+
|
|
60
|
+
# Example with 50W threshold:
|
|
61
|
+
node test/integration/validate-grid-sensors.js 192.168.1.50 your-password-here 50
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The validator will:
|
|
65
|
+
- ✅ Show current power flow (grid, solar, battery, home)
|
|
66
|
+
- ✅ Display grid sensor states based on your threshold
|
|
67
|
+
- ✅ Provide recommendations for automation setup
|
|
68
|
+
- 💡 Help you tune the threshold for your system
|
|
69
|
+
|
|
70
|
+
## Configuration
|
|
71
|
+
|
|
72
|
+
### Basic Configuration
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"platforms": [
|
|
76
|
+
{
|
|
77
|
+
"platform": "TeslaPowerwall",
|
|
78
|
+
"name": "Tesla Powerwall",
|
|
79
|
+
"ip": "192.168.1.50",
|
|
80
|
+
"password": "your-password-here",
|
|
81
|
+
"pollingInterval": 15,
|
|
82
|
+
"enableGridPowerSensors": true,
|
|
83
|
+
"gridSensorThreshold": 50
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Required Parameters
|
|
90
|
+
- `platform`: Must be "TeslaPowerwall"
|
|
91
|
+
- `name`: Display name for your Powerwall
|
|
92
|
+
- `ip`: IP address of your Tesla Powerwall
|
|
93
|
+
- `password`: Your Powerwall password
|
|
94
|
+
|
|
95
|
+
### Optional Parameters
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"platform": "TeslaPowerwall",
|
|
99
|
+
"name": "Tesla Powerwall",
|
|
100
|
+
"ip": "192.168.1.50",
|
|
101
|
+
"password": "your-password-here",
|
|
102
|
+
"port": "443",
|
|
103
|
+
"pollingInterval": 15,
|
|
104
|
+
"enableGridStatus": true,
|
|
105
|
+
"enableGridPowerSensors": true,
|
|
106
|
+
"gridSensorThreshold": 50,
|
|
107
|
+
"enablePowerMeters": true,
|
|
108
|
+
"enableHistory": false,
|
|
109
|
+
"debug": false
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Configuration Options Explained
|
|
114
|
+
|
|
115
|
+
#### Connection Settings
|
|
116
|
+
- `ip`: **Required** - The IP address of your Tesla Powerwall on your local network
|
|
117
|
+
- `password`: **Required** - Your Tesla Powerwall password (set via the Tesla app)
|
|
118
|
+
- `port`: Port number (default: "443")
|
|
119
|
+
|
|
120
|
+
#### Monitoring Settings
|
|
121
|
+
- `pollingInterval`: How often to poll the Powerwall for updates in seconds (default: 15, min: 5, max: 300)
|
|
122
|
+
- `enableGridStatus`: Show grid connectivity status as a Contact Sensor (default: true)
|
|
123
|
+
- `enableGridPowerSensors`: Show sensors for grid power flow detection (default: true) ⭐ **NEW**
|
|
124
|
+
- `gridSensorThreshold`: Power threshold in watts for sensor activation (default: 50W, helps avoid false triggers) ⭐ **NEW**
|
|
125
|
+
- `enablePowerMeters`: Show power flow meters (Solar, Grid, Home, Battery) as Light Sensors (default: true)
|
|
126
|
+
- `enableHistory`: Enable historical data logging for Eve app (default: false)
|
|
127
|
+
|
|
128
|
+
#### Troubleshooting
|
|
129
|
+
- `debug`: Enable detailed debug logging (default: false)
|
|
130
|
+
|
|
131
|
+
## Features
|
|
132
|
+
|
|
133
|
+
### Accessories Provided
|
|
134
|
+
|
|
135
|
+
1. **Battery Status** - Shows battery charge level, charging state, and low battery alerts
|
|
136
|
+
2. **Grid Offline Sensor** (`Tesla Powerwall Grid Offline`) - Contact sensor reflecting whether the Powerwall is grid-tied
|
|
137
|
+
- **Closed** = grid connected (`grid_status: SystemGridConnected`)
|
|
138
|
+
- **Open** = grid disconnected / islanded (`SystemIslandedActive` or similar)
|
|
139
|
+
3. **Exporting Sensor** (`Tesla Powerwall Exporting`) - Contact sensor that opens when you are exporting to the grid
|
|
140
|
+
- **Open** = exporting to the grid (site `instant_power` < -`gridSensorThreshold`)
|
|
141
|
+
- **Closed** = idle / not exporting
|
|
142
|
+
4. **Importing Sensor** (`Tesla Powerwall Importing`) - Contact sensor that opens when you are importing from the grid
|
|
143
|
+
- **Open** = importing from the grid (site `instant_power` > +`gridSensorThreshold`)
|
|
144
|
+
- **Closed** = idle / not importing
|
|
145
|
+
5. **Power Meters** - Light sensors showing instantaneous power flow, in watts
|
|
146
|
+
(the lux value equals watts). Three are provided:
|
|
147
|
+
- `Tesla Powerwall Solar` - power your panels are generating
|
|
148
|
+
- `Tesla Powerwall Grid` - power flowing to/from the utility grid
|
|
149
|
+
- `Tesla Powerwall Home` - total power your home is consuming
|
|
150
|
+
- `Tesla Powerwall Battery` - power flowing to/from the Powerwall battery
|
|
151
|
+
|
|
152
|
+
> HomeKit has no native power-sensor type, so watts are carried on a light
|
|
153
|
+
> sensor's lux value (range 0–100000, which covers any residential system).
|
|
154
|
+
> Values are reported as actual watts.
|
|
155
|
+
|
|
156
|
+
> **A note on "Open" vs "Closed"**: HomeKit contact sensors only have two
|
|
157
|
+
> labels — "Open" and "Closed" — borrowed from door/window sensors. The
|
|
158
|
+
> convention is **Closed = quiescent / resting state, Open = the noteworthy
|
|
159
|
+
> event** (which is what you usually build automations on). For these
|
|
160
|
+
> sensors:
|
|
161
|
+
> - `Grid Offline` is **Closed** while everything is normal (grid connected)
|
|
162
|
+
> and **Opens** when the Powerwall islands.
|
|
163
|
+
> - `Exporting` and `Importing` are **Closed** while idle and **Open** while
|
|
164
|
+
> that flow direction is actively above the threshold.
|
|
165
|
+
>
|
|
166
|
+
> If you'd prefer different labels, you can rename the accessories in the
|
|
167
|
+
> Home app (long-press → Settings → rename); your automations will keep
|
|
168
|
+
> working under the new names.
|
|
169
|
+
|
|
170
|
+
### Grid Power Sensors - Automation Examples
|
|
171
|
+
|
|
172
|
+
The grid power sensors enable powerful HomeKit automations:
|
|
173
|
+
|
|
174
|
+
#### Example 1: Get notified when exporting power to the grid
|
|
175
|
+
```
|
|
176
|
+
When: Tesla Powerwall Exporting opens
|
|
177
|
+
Then: Send notification "You're selling power to the grid! 💰"
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
#### Example 2: Notify when importing expensive peak power
|
|
181
|
+
```
|
|
182
|
+
When: Tesla Powerwall Importing opens
|
|
183
|
+
AND Time is between 4:00 PM and 9:00 PM
|
|
184
|
+
Then: Send notification "Using peak power from grid ⚡"
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
#### Example 3: Turn off non-essential loads when pulling from grid
|
|
188
|
+
```
|
|
189
|
+
When: Tesla Powerwall Importing opens
|
|
190
|
+
Then:
|
|
191
|
+
- Turn off pool pump
|
|
192
|
+
- Turn off EV charger
|
|
193
|
+
- Send notification "Reducing load to minimize grid usage"
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
#### Example 4: Start charging devices when exporting to grid
|
|
197
|
+
```
|
|
198
|
+
When: Tesla Powerwall Exporting opens
|
|
199
|
+
AND Battery level > 80%
|
|
200
|
+
Then:
|
|
201
|
+
- Start EV charging
|
|
202
|
+
- Turn on pool pump
|
|
203
|
+
- Send notification "Free solar power available! ☀️"
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Sensor Threshold Configuration
|
|
207
|
+
|
|
208
|
+
The `gridSensorThreshold` setting (default 50W) prevents false triggers from minor power fluctuations:
|
|
209
|
+
- **50W (default)**: Good balance for most installations
|
|
210
|
+
- **100W+**: Recommended for systems with frequent small fluctuations
|
|
211
|
+
- **0W**: Maximum sensitivity, may cause false triggers
|
|
212
|
+
|
|
213
|
+
## Legacy Configuration (from v3.x)
|
|
214
|
+
|
|
215
|
+
For users upgrading from version 3.x, the plugin has been simplified. The old `additionalServices` configuration is no longer needed. Simply use the new boolean flags:
|
|
216
|
+
- `enableGridStatus` - replaces gridstatus options
|
|
217
|
+
- `enableGridPowerSensors` - NEW feature for grid power flow detection
|
|
218
|
+
- `enablePowerMeters` - replaces individual meter options
|
|
219
|
+
- `enableHistory` - replaces eveHistory options
|
|
220
|
+
|
|
221
|
+
## API Limitations
|
|
222
|
+
|
|
223
|
+
### Operation Mode Control (Issue #54)
|
|
224
|
+
|
|
225
|
+
**Important Note**: Due to recent Tesla Powerwall firmware updates, **operation mode control (switching between Self-Powered, Time-based, or changing Backup Reserve) is NOT available via the local API**.
|
|
226
|
+
|
|
227
|
+
According to Tesla's architecture:
|
|
228
|
+
- The **local API** (used by this plugin) provides read-only access to system status and power flow data
|
|
229
|
+
- **Operation mode changes** require the Tesla Fleet API, which needs cloud authentication
|
|
230
|
+
|
|
231
|
+
If you need to automate operation mode changes, you have these options:
|
|
232
|
+
1. Use the Tesla mobile app manually
|
|
233
|
+
2. Integrate with Tesla's Fleet API (requires developer account and cloud access)
|
|
234
|
+
3. Use a separate automation system that supports the Tesla Fleet API
|
|
235
|
+
|
|
236
|
+
This plugin focuses on what's possible with the local API:
|
|
237
|
+
- Real-time monitoring of battery, grid, solar, and home
|
|
238
|
+
- Grid power flow detection (feeding/pulling sensors)
|
|
239
|
+
- Grid connectivity status
|
|
240
|
+
- Triggering HomeKit automations based on power flow
|
|
241
|
+
|
|
242
|
+
We may add Tesla Fleet API support in a future version if there's sufficient demand and if it can be implemented without compromising security or requiring complex cloud setups.
|
|
243
|
+
|
|
244
|
+
## Example Configurations
|
|
245
|
+
|
|
246
|
+
### Minimal Configuration
|
|
247
|
+
```json
|
|
248
|
+
{
|
|
249
|
+
"platform": "TeslaPowerwall",
|
|
250
|
+
"name": "Tesla Powerwall",
|
|
251
|
+
"ip": "192.168.1.50",
|
|
252
|
+
"password": "your-password-here",
|
|
253
|
+
"pollingInterval": 10
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### Full Configuration with All Features
|
|
258
|
+
```json
|
|
259
|
+
{
|
|
260
|
+
"platform": "TeslaPowerwall",
|
|
261
|
+
"name": "Tesla Powerwall",
|
|
262
|
+
"ip": "192.168.1.50",
|
|
263
|
+
"password": "your-password-here",
|
|
264
|
+
"pollingInterval": 15,
|
|
265
|
+
"enableGridStatus": true,
|
|
266
|
+
"enableGridPowerSensors": true,
|
|
267
|
+
"gridSensorThreshold": 50,
|
|
268
|
+
"enablePowerMeters": true,
|
|
269
|
+
"enableHistory": false,
|
|
270
|
+
"debug": false
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### Configuration with Disabled Sensors
|
|
275
|
+
```json
|
|
276
|
+
{
|
|
277
|
+
"platform": "TeslaPowerwall",
|
|
278
|
+
"name": "Tesla Powerwall",
|
|
279
|
+
"ip": "192.168.1.50",
|
|
280
|
+
"password": "your-password-here",
|
|
281
|
+
"pollingInterval": 15,
|
|
282
|
+
"enableGridStatus": false,
|
|
283
|
+
"enableGridPowerSensors": false,
|
|
284
|
+
"enablePowerMeters": false
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## Troubleshooting
|
|
289
|
+
|
|
290
|
+
### 🔧 Connection Testing
|
|
291
|
+
|
|
292
|
+
Always start with the connection test script:
|
|
293
|
+
```bash
|
|
294
|
+
node test/integration/test-connection.js <ip> <username> <password>
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### ❌ Login Errors
|
|
298
|
+
|
|
299
|
+
If you get login errors (403, authentication failed):
|
|
300
|
+
1. Verify your password is correct
|
|
301
|
+
2. Check if your Powerwall requires re-registration
|
|
302
|
+
3. Try the connection test script for detailed debugging
|
|
303
|
+
|
|
304
|
+
### 🔄 Plugin Stopped Working After Powerwall Update
|
|
305
|
+
|
|
306
|
+
- Ensure you're using the latest plugin version (4.1.0+)
|
|
307
|
+
- Verify the `password` field is correctly configured
|
|
308
|
+
|
|
309
|
+
### ⚡ Grid Power Sensors Not Triggering
|
|
310
|
+
|
|
311
|
+
If the new grid power sensors aren't working as expected:
|
|
312
|
+
1. Check the `gridSensorThreshold` setting - you may need to adjust it
|
|
313
|
+
2. Use debug logging to see actual power values: `"debug": true`
|
|
314
|
+
3. Verify your Powerwall is actually feeding/pulling power above the threshold
|
|
315
|
+
4. Check the Homebridge logs for sensor state changes
|
|
316
|
+
|
|
317
|
+
### 📊 For Older Powerwall Versions (< 20.49.0)
|
|
318
|
+
|
|
319
|
+
If your Powerwall firmware is older than 20.49.0, you may need to use the legacy version:
|
|
320
|
+
```bash
|
|
321
|
+
npm install -g homebridge-tesla-powerwall@1.1.0
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
## Development
|
|
325
|
+
|
|
326
|
+
### Building from Source
|
|
327
|
+
```bash
|
|
328
|
+
git clone https://github.com/dkerr64/homebridge-tesla-powerwall2.git
|
|
329
|
+
cd homebridge-tesla-powerwall2
|
|
330
|
+
npm install
|
|
331
|
+
npm run build
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### Running Tests
|
|
335
|
+
```bash
|
|
336
|
+
npm test
|
|
337
|
+
npm run lint
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
## Migration from v3.x to v4.1.0
|
|
341
|
+
|
|
342
|
+
The v4.x updates include major improvements:
|
|
343
|
+
|
|
344
|
+
1. **Node.js Requirement**: Now requires Node.js 18.15.0+
|
|
345
|
+
2. **Simplified Configuration**: The complex `additionalServices` object has been simplified to simple boolean flags
|
|
346
|
+
3. **New Features**: Grid power sensors for automation triggers
|
|
347
|
+
4. **Dependencies**: All dependencies updated to latest versions
|
|
348
|
+
5. **Testing**: Use the new test script to verify connectivity
|
|
349
|
+
|
|
350
|
+
### Breaking Changes from v3.x
|
|
351
|
+
- Configuration format has been simplified (old format still works but is deprecated)
|
|
352
|
+
- Some advanced Eve features may not be available in v4.x
|
|
353
|
+
|
|
354
|
+
Simply update the plugin and restart Homebridge. Your existing configuration should continue to work, but consider migrating to the new simpler format.
|
|
355
|
+
|
|
356
|
+
## Contributing
|
|
357
|
+
|
|
358
|
+
Contributions are welcome! Please:
|
|
359
|
+
1. Fork the repository
|
|
360
|
+
2. Create a feature branch
|
|
361
|
+
3. Add tests if applicable
|
|
362
|
+
4. Submit a pull request
|
|
363
|
+
|
|
364
|
+
## Feature Requests / Bug Reports
|
|
365
|
+
|
|
366
|
+
Please create an [Issue](https://github.com/dkerr64/homebridge-tesla-powerwall2/issues/new) with:
|
|
367
|
+
- Plugin version
|
|
368
|
+
- Homebridge version
|
|
369
|
+
- Node.js version
|
|
370
|
+
- Powerwall firmware version
|
|
371
|
+
- Detailed description of the issue
|
|
372
|
+
- Log output if applicable
|
|
373
|
+
|
|
374
|
+
## License
|
|
375
|
+
|
|
376
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
377
|
+
|
|
378
|
+
---
|
|
379
|
+
|
|
380
|
+
**Disclaimer**: This is an unofficial plugin and is not associated with Tesla, Inc. in any way.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
{
|
|
2
|
+
"pluginAlias": "TeslaPowerwall",
|
|
3
|
+
"pluginType": "platform",
|
|
4
|
+
"singular": true,
|
|
5
|
+
"headerDisplay": "A Homebridge plugin for Tesla Powerwall that provides battery status, power flow, and grid connectivity monitoring in HomeKit.",
|
|
6
|
+
"footerDisplay": "For help and support visit the [plugin repository](https://github.com/dkerr64/homebridge-tesla-powerwall2).",
|
|
7
|
+
"schema": {
|
|
8
|
+
"type": "object",
|
|
9
|
+
"properties": {
|
|
10
|
+
"name": {
|
|
11
|
+
"title": "Name",
|
|
12
|
+
"type": "string",
|
|
13
|
+
"default": "Tesla Powerwall",
|
|
14
|
+
"required": true,
|
|
15
|
+
"description": "The name that will appear in HomeKit for your Tesla Powerwall"
|
|
16
|
+
},
|
|
17
|
+
"ip": {
|
|
18
|
+
"title": "IP Address",
|
|
19
|
+
"type": "string",
|
|
20
|
+
"default": "192.168.1.100",
|
|
21
|
+
"required": true,
|
|
22
|
+
"format": "ipv4",
|
|
23
|
+
"description": "The IP address of your Tesla Powerwall on your local network"
|
|
24
|
+
},
|
|
25
|
+
"port": {
|
|
26
|
+
"title": "Port",
|
|
27
|
+
"type": "string",
|
|
28
|
+
"default": "443",
|
|
29
|
+
"required": false,
|
|
30
|
+
"description": "Port number (leave as 443 unless you've changed it)"
|
|
31
|
+
},
|
|
32
|
+
"password": {
|
|
33
|
+
"title": "Password",
|
|
34
|
+
"type": "string",
|
|
35
|
+
"required": true,
|
|
36
|
+
"description": "Your Tesla Powerwall password (set via the Tesla app)"
|
|
37
|
+
},
|
|
38
|
+
"pollingInterval": {
|
|
39
|
+
"title": "Polling Interval (seconds)",
|
|
40
|
+
"type": "integer",
|
|
41
|
+
"default": 15,
|
|
42
|
+
"minimum": 5,
|
|
43
|
+
"maximum": 300,
|
|
44
|
+
"required": false,
|
|
45
|
+
"description": "How often to poll the Powerwall for updates (5-300 seconds)"
|
|
46
|
+
},
|
|
47
|
+
"enableGridStatus": {
|
|
48
|
+
"title": "Enable Grid Offline Sensor",
|
|
49
|
+
"type": "boolean",
|
|
50
|
+
"default": true,
|
|
51
|
+
"required": false,
|
|
52
|
+
"description": "Show grid connectivity as a Contact Sensor (Closed = grid connected, Open = islanded)"
|
|
53
|
+
},
|
|
54
|
+
"enableGridPowerSensors": {
|
|
55
|
+
"title": "Enable Exporting / Importing Sensors",
|
|
56
|
+
"type": "boolean",
|
|
57
|
+
"default": true,
|
|
58
|
+
"required": false,
|
|
59
|
+
"description": "Show separate Contact Sensors that close while you are exporting to or importing from the grid (for automation triggers)"
|
|
60
|
+
},
|
|
61
|
+
"gridSensorThreshold": {
|
|
62
|
+
"title": "Grid Sensor Threshold (watts)",
|
|
63
|
+
"type": "integer",
|
|
64
|
+
"default": 50,
|
|
65
|
+
"minimum": 0,
|
|
66
|
+
"maximum": 1000,
|
|
67
|
+
"required": false,
|
|
68
|
+
"description": "Power threshold in watts for grid sensor activation (helps avoid false triggers from noise)"
|
|
69
|
+
},
|
|
70
|
+
"enablePowerMeters": {
|
|
71
|
+
"title": "Enable Power Meters",
|
|
72
|
+
"type": "boolean",
|
|
73
|
+
"default": true,
|
|
74
|
+
"required": false,
|
|
75
|
+
"description": "Show power flow meters (Solar, Grid, Load) as Light Bulbs with brightness representing power"
|
|
76
|
+
},
|
|
77
|
+
"debug": {
|
|
78
|
+
"title": "Debug Logging",
|
|
79
|
+
"type": "boolean",
|
|
80
|
+
"default": false,
|
|
81
|
+
"required": false,
|
|
82
|
+
"description": "Enable detailed debug logging for troubleshooting"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"layout": [
|
|
87
|
+
{
|
|
88
|
+
"type": "fieldset",
|
|
89
|
+
"title": "Connection Settings",
|
|
90
|
+
"expandable": false,
|
|
91
|
+
"items": [
|
|
92
|
+
"name",
|
|
93
|
+
"ip",
|
|
94
|
+
"port",
|
|
95
|
+
"password"
|
|
96
|
+
]
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"type": "fieldset",
|
|
100
|
+
"title": "Monitoring Settings",
|
|
101
|
+
"expandable": true,
|
|
102
|
+
"items": [
|
|
103
|
+
"pollingInterval",
|
|
104
|
+
"enableGridStatus",
|
|
105
|
+
"enableGridPowerSensors",
|
|
106
|
+
"gridSensorThreshold",
|
|
107
|
+
"enablePowerMeters"
|
|
108
|
+
]
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"type": "fieldset",
|
|
112
|
+
"title": "Troubleshooting",
|
|
113
|
+
"expandable": true,
|
|
114
|
+
"items": [
|
|
115
|
+
"debug"
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
}
|