node-red-contrib-senec-cloud-v2 0.2.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 ADDED
@@ -0,0 +1,77 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.2.0] - 2026-07-05
9
+
10
+ ### Fixed
11
+ - **Authentication failed / 404 errors**: Replaced placeholder API endpoints
12
+ with the real SENEC Cloud App API
13
+ - Implemented OAuth2 Authorization Code + PKCE login flow against the SENEC
14
+ Keycloak SSO (`sso.senec.com`), emulating the official SENEC app
15
+ - Token refresh now uses the OAuth2 `refresh_token` grant (access tokens
16
+ are only valid ~5 minutes; refresh tokens ~30 days)
17
+
18
+ ### Changed
19
+ - Data retrieval now uses `app-gateway.prod.senec.dev`:
20
+ - `GET /v1/senec/anlagen` to discover the system ID
21
+ - `GET /v2/senec/systems/{id}/dashboard` for energy data
22
+ - DataParser maps the v2 dashboard response (`currently`/`today` with
23
+ `powerGenerationInW`, `gridDrawInWh`, etc.) to the backward compatible
24
+ payload structure; today values converted from Wh to kWh
25
+
26
+ ## [Unreleased]
27
+
28
+ ### Added
29
+ - Initial project structure
30
+ - TypeScript configuration
31
+ - Core library components:
32
+ - AuthenticationManager for SENEC Cloud authentication
33
+ - SenecAPIClient for data retrieval
34
+ - DataParser for response parsing
35
+ - ErrorHandler for error classification and retry logic
36
+ - Comprehensive architecture documentation
37
+ - Feature definitions following AGENTS.md structure
38
+ - Implementation plan and technical requirements
39
+
40
+ ### TODO
41
+ - Implement Node-RED nodes (senec-config, senec-data, senec-image)
42
+ - Research actual SENEC Cloud API endpoints
43
+ - Add unit and integration tests
44
+ - Create example flows
45
+ - Test on CCU RedMatic hardware
46
+ - Complete image generation functionality
47
+ - Publish to npm
48
+
49
+ ## [0.1.0] - TBD
50
+
51
+ ### Added
52
+ - Initial pre-release version
53
+ - Basic SENEC Cloud API integration
54
+ - Configuration and data nodes
55
+ - Backward compatible payload structure
56
+
57
+ ## Future Releases
58
+
59
+ ### [1.0.0] - Target Release
60
+ - Full SENEC Cloud API integration
61
+ - Complete Node-RED node implementation
62
+ - Image generation for TRMNL
63
+ - CCU RedMatic optimization
64
+ - Comprehensive documentation
65
+ - npm package publication
66
+
67
+ ### [1.1.0] - Planned
68
+ - Additional layout templates
69
+ - Custom template support
70
+ - Enhanced error reporting
71
+ - Performance improvements
72
+
73
+ ### [2.0.0] - Future
74
+ - Historical data support
75
+ - Multi-device support
76
+ - Advanced visualization options
77
+ - WebAPI wrapper (optional)
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SENEC Node-RED Integration Contributors
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.
package/README.md ADDED
@@ -0,0 +1,279 @@
1
+ # node-red-contrib-senec-cloud-v2
2
+
3
+ Node-RED nodes for SENEC Cloud API integration - supports the new SENEC Cloud API (2025+), optimized for CCU RedMatic.
4
+
5
+ ## Features
6
+
7
+ - ✅ **SENEC Cloud API Integration** - Works with the new SENEC Cloud API (August 2025+)
8
+ - ✅ **Backward Compatible** - Drop-in replacement for existing flows
9
+ - ✅ **CCU RedMatic Optimized** - Low resource usage, tested on CCU hardware
10
+ - ✅ **Automatic Error Recovery** - Exponential backoff retry logic
11
+ - ✅ **Image Generation** - Create PNG images for TRMNL e-ink displays
12
+ - ✅ **Secure** - Credentials encrypted using Node-RED's credential system
13
+
14
+ ## Installation
15
+
16
+ ### Via Node-RED Palette Manager (Recommended)
17
+
18
+ 1. Open Node-RED editor
19
+ 2. Click menu (☰) → Manage palette
20
+ 3. Go to "Install" tab
21
+ 4. Search for `senec-cloud-v2`
22
+ 5. Click "Install"
23
+
24
+ ### Via npm
25
+
26
+ ```bash
27
+ cd ~/.node-red
28
+ npm install node-red-contrib-senec-cloud-v2
29
+ node-red-restart
30
+ ```
31
+
32
+ ### On CCU RedMatic
33
+
34
+ 1. Open CCU WebUI
35
+ 2. Navigate to RedMatic add-on
36
+ 3. Open Node-RED editor
37
+ 4. Use Palette Manager as described above
38
+
39
+ ## Quick Start
40
+
41
+ ### 1. Add Configuration Node
42
+
43
+ 1. Drag a `senec-data` node into your flow
44
+ 2. Double-click to edit
45
+ 3. Click the pencil icon next to "SENEC Config"
46
+ 4. Enter your SENEC Cloud credentials:
47
+ - **Username**: Your SENEC Cloud username/email
48
+ - **Password**: Your SENEC Cloud password
49
+ 5. Click "Test Connection" to verify
50
+ 6. Click "Add" to save
51
+
52
+ ### 2. Configure Data Node
53
+
54
+ 1. Set poll interval (default: 60 seconds, recommended 120s for CCU)
55
+ 2. Enable/disable automatic polling
56
+ 3. Deploy your flow
57
+
58
+ ### 3. Use the Data
59
+
60
+ The node outputs energy data in `msg.payload`:
61
+
62
+ ```javascript
63
+ {
64
+ steuereinheitState: "online",
65
+ gridimport: { today: 2.5, now: 150 }, // kWh, W
66
+ powergenerated: { today: 18.5, now: 3200 }, // kWh, W
67
+ consumption: { today: 12.3, now: 1800 }, // kWh, W
68
+ gridexport: { today: 8.2, now: 1400 }, // kWh, W
69
+ acculevel: { now: 85 } // %
70
+ }
71
+ ```
72
+
73
+ ## Nodes
74
+
75
+ ### senec-config
76
+
77
+ Configuration node for SENEC Cloud credentials. Shared across multiple data nodes.
78
+
79
+ **Configuration**:
80
+ - Username (required)
81
+ - Password (required)
82
+ - Test Connection button
83
+
84
+ ### senec-data
85
+
86
+ Retrieves energy data from SENEC Cloud.
87
+
88
+ **Configuration**:
89
+ - SENEC Config: Reference to config node
90
+ - Poll Interval: Seconds between automatic updates (default: 60)
91
+ - Enable Polling: Automatic periodic updates
92
+
93
+ **Input**: Any message triggers immediate data retrieval (independent of polling)
94
+
95
+ **Output**: `msg.payload` contains SENEC energy data
96
+
97
+ **Status Indicators**:
98
+ - 🟢 Connected - Successfully connected and retrieving data
99
+ - 🟡 Retrying - Temporary error, retrying automatically
100
+ - 🔴 Error - Persistent error, check credentials or connection
101
+
102
+ ### senec-image
103
+
104
+ Generates PNG images from SENEC data for displays.
105
+
106
+ **Configuration**:
107
+ - Template: trmnl, compact, or detailed
108
+ - Width/Height: Image dimensions
109
+ - Output Format: buffer, base64, or file
110
+ - Color Scheme: monochrome (e-ink) or color
111
+
112
+ **Input**: `msg.payload` with SENEC data
113
+
114
+ **Output**: PNG image as Buffer, base64 string, or file path
115
+
116
+ ## Examples
117
+
118
+ ### Basic Monitoring
119
+
120
+ ```
121
+ [senec-data] → [debug]
122
+ ```
123
+
124
+ ### TRMNL Display
125
+
126
+ ```
127
+ [inject: every 5 min] → [senec-data] → [senec-image: TRMNL] → [http response]
128
+ ```
129
+
130
+ ### CCU Homematic Integration
131
+
132
+ ```
133
+ [senec-data] → [function: extract battery] → [ccu-value: battery variable]
134
+ ```
135
+
136
+ ### Automation Example
137
+
138
+ ```javascript
139
+ // In a function node after senec-data
140
+ var battery = msg.payload.acculevel.now;
141
+ var solar = msg.payload.powergenerated.now;
142
+
143
+ if (battery > 80 && solar > 2000) {
144
+ // Excess solar available - turn on devices
145
+ return { payload: true };
146
+ }
147
+ ```
148
+
149
+ ## Configuration Tips
150
+
151
+ ### For CCU RedMatic
152
+
153
+ - Use poll interval of 120 seconds (2 minutes) to reduce resource usage
154
+ - Monitor memory usage in CCU WebUI
155
+ - Disable polling if only triggered retrieval needed
156
+
157
+ ### For Raspberry Pi / Standard Node-RED
158
+
159
+ - Default 60 second interval works well
160
+ - Can use shorter intervals if needed (minimum 10 seconds)
161
+
162
+ ### For TRMNL Displays
163
+
164
+ - Use `senec-image` node with TRMNL template
165
+ - Set dimensions to 800x480 (or your display size)
166
+ - Use monochrome color scheme for e-ink
167
+ - Serve via HTTP endpoint for TRMNL to fetch
168
+
169
+ ## Troubleshooting
170
+
171
+ ### Authentication Failed
172
+
173
+ - Verify credentials in config node
174
+ - Check SENEC Cloud account is active
175
+ - Try logging in to SENEC web portal to confirm credentials
176
+
177
+ ### Connection Timeout
178
+
179
+ - Check internet connectivity
180
+ - Verify firewall allows HTTPS outbound
181
+ - SENEC Cloud may be temporarily unavailable (automatic retry)
182
+
183
+ ### Rate Limited
184
+
185
+ - Reduce poll frequency
186
+ - Default backoff will handle this automatically
187
+ - Check for multiple flows polling the same account
188
+
189
+ ### High Memory Usage on CCU
190
+
191
+ - Increase poll interval to 120-300 seconds
192
+ - Disable polling, use triggered retrieval only
193
+ - Check for other resource-intensive flows
194
+
195
+ ## API Changes
196
+
197
+ This package supports the **new SENEC Cloud API** (August 2025+). The old API is no longer supported by SENEC.
198
+
199
+ **Migration from old package**:
200
+ - Payload structure is identical - existing flows work without changes
201
+ - Simply replace old nodes with new ones
202
+ - Update credentials in config node
203
+
204
+ ## Development
205
+
206
+ ### Setup
207
+
208
+ ```bash
209
+ git clone https://github.com/aunovis-fitting/node-red-contrib-senec-cloud-v2.git
210
+ cd node-red-contrib-senec-cloud-v2
211
+ npm install
212
+ ```
213
+
214
+ ### Build
215
+
216
+ ```bash
217
+ npm run build
218
+ ```
219
+
220
+ ### Test
221
+
222
+ ```bash
223
+ npm test
224
+ npm run test:coverage
225
+ ```
226
+
227
+ ### Local Testing in Node-RED
228
+
229
+ ```bash
230
+ npm run build
231
+ npm link
232
+ cd ~/.node-red
233
+ npm link node-red-contrib-senec-cloud-v2
234
+ node-red-restart
235
+ ```
236
+
237
+ ## Architecture
238
+
239
+ See [`docs/00-ARCHITECTURE_SUMMARY.md`](docs/00-ARCHITECTURE_SUMMARY.md) for complete architecture documentation.
240
+
241
+ ## Contributing
242
+
243
+ Contributions welcome! Please:
244
+
245
+ 1. Fork the repository
246
+ 2. Create a feature branch
247
+ 3. Make your changes
248
+ 4. Add tests
249
+ 5. Submit a pull request
250
+
251
+ ## Support
252
+
253
+ - **Issues**: [GitHub Issues](https://github.com/yourusername/node-red-contrib-senec-cloud-v2/issues)
254
+ - **Discussions**: [GitHub Discussions](https://github.com/yourusername/node-red-contrib-senec-cloud-v2/discussions)
255
+ - **Node-RED Forum**: [Node-RED Community](https://discourse.nodered.org/)
256
+ - **HomeMatic Forum**: [HomeMatic-Forum.de](https://homematic-forum.de/) (German)
257
+
258
+ ## License
259
+
260
+ MIT License - see [LICENSE](LICENSE) file
261
+
262
+ ## Acknowledgments
263
+
264
+ - SENEC for their solar energy storage systems
265
+ - Node-RED community
266
+ - CCU RedMatic project
267
+ - Original senec-cloud package contributors
268
+
269
+ ## Disclaimer
270
+
271
+ This is an unofficial integration. Not affiliated with or endorsed by SENEC GmbH.
272
+
273
+ ---
274
+
275
+ **Status**: 🚧 In Development
276
+
277
+ **Current Version**: 0.1.0 (Pre-release)
278
+
279
+ **Target Release**: v1.0.0
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Authentication Manager
3
+ *
4
+ * Handles SENEC Cloud authentication, token management, and refresh logic.
5
+ *
6
+ * Since the SENEC API change (August 2025), authentication uses the
7
+ * SENEC Keycloak SSO with the OAuth2 Authorization Code + PKCE flow,
8
+ * emulating the official SENEC app:
9
+ *
10
+ * 1. GET /auth (login page, collects session cookies)
11
+ * 2. POST username to the login form
12
+ * 3. POST password to the second-step form
13
+ * 4. Receive redirect to senec-app-auth://keycloak.prod?code=...
14
+ * 5. Exchange authorization code for access + refresh tokens
15
+ *
16
+ * Access tokens are short-lived (~5 minutes); refresh tokens last ~30 days.
17
+ * Token refresh uses the standard OAuth2 refresh_token grant.
18
+ */
19
+ import { SenecCredentials, AuthToken } from '../types/senec';
20
+ export declare class AuthenticationManager {
21
+ private credentials;
22
+ private token;
23
+ private tokenExpiry;
24
+ private refreshTokenValue;
25
+ private refreshTokenExpiry;
26
+ private httpClient;
27
+ constructor(credentials: SenecCredentials);
28
+ /**
29
+ * Authenticate with SENEC Cloud (OAuth2 Authorization Code + PKCE)
30
+ */
31
+ authenticate(): Promise<AuthToken>;
32
+ /**
33
+ * Refresh the authentication token using the OAuth2 refresh_token grant.
34
+ * Falls back to a full re-authentication if no valid refresh token exists
35
+ * or the refresh fails.
36
+ */
37
+ refreshToken(): Promise<AuthToken>;
38
+ /**
39
+ * Check if the current token is valid
40
+ */
41
+ isTokenValid(): boolean;
42
+ /**
43
+ * Whether a (probably valid) refresh token is available
44
+ */
45
+ canRefresh(): boolean;
46
+ /**
47
+ * Get the current token
48
+ */
49
+ getToken(): string | null;
50
+ /**
51
+ * Clear the stored tokens
52
+ */
53
+ clearToken(): void;
54
+ /**
55
+ * Store tokens from a Keycloak token endpoint response
56
+ */
57
+ private storeTokens;
58
+ /**
59
+ * Build a user-friendly error description without leaking credentials
60
+ */
61
+ private describeError;
62
+ }
63
+ //# sourceMappingURL=auth-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-manager.d.ts","sourceRoot":"","sources":["../../src/lib/auth-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAKH,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAsB7D,qBAAa,qBAAqB;IAChC,OAAO,CAAC,WAAW,CAAmB;IACtC,OAAO,CAAC,KAAK,CAAuB;IACpC,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,iBAAiB,CAAuB;IAChD,OAAO,CAAC,kBAAkB,CAAqB;IAC/C,OAAO,CAAC,UAAU,CAAgB;gBAEtB,WAAW,EAAE,gBAAgB;IAOzC;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,SAAS,CAAC;IAwHxC;;;;OAIG;IACG,YAAY,IAAI,OAAO,CAAC,SAAS,CAAC;IAoCxC;;OAEG;IACH,YAAY,IAAI,OAAO;IAWvB;;OAEG;IACH,UAAU,IAAI,OAAO;IAOrB;;OAEG;IACH,QAAQ,IAAI,MAAM,GAAG,IAAI;IAIzB;;OAEG;IACH,UAAU,IAAI,IAAI;IAOlB;;OAEG;IACH,OAAO,CAAC,WAAW;IAYnB;;OAEG;IACH,OAAO,CAAC,aAAa;CAsBtB"}