node-red-contrib-octopus-intelligent 1.2.0 → 1.2.1
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/README.md +11 -1
- package/octopus-intelligent.js +45 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -339,13 +339,23 @@ return msg;
|
|
|
339
339
|
|
|
340
340
|
### Toggle Smart Charging from Flow
|
|
341
341
|
|
|
342
|
+
Send a boolean to enable or disable Octopus intelligent charging:
|
|
343
|
+
|
|
342
344
|
```javascript
|
|
343
345
|
msg.payload = { set_smart_charging: true }; // enable (unsuspend)
|
|
344
346
|
msg.payload = { set_smart_charging: false }; // disable (suspend)
|
|
345
347
|
return msg;
|
|
346
348
|
```
|
|
347
349
|
|
|
348
|
-
|
|
350
|
+
Wire an **Inject node** with a JSON payload, or build this in a function node and connect it to the Octopus Intelligent node's input. Non-boolean values are silently ignored.
|
|
351
|
+
|
|
352
|
+
**Example: suspend charging when home battery is in use**
|
|
353
|
+
```
|
|
354
|
+
[Inject: suspend] → [Function: set_smart_charging=false] → [Octopus Intelligent]
|
|
355
|
+
[Inject: resume] → [Function: set_smart_charging=true] → [Octopus Intelligent]
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
The node fetches your device ID at startup — if it hasn't been fetched yet (first few seconds after deploy), the command will log a warning and be ignored. The current smart charging state is always available in `msg.payload.smart_charging` (`true` = active, `false` = suspended, `null` = startup pending).
|
|
349
359
|
|
|
350
360
|
### Output Format
|
|
351
361
|
|
package/octopus-intelligent.js
CHANGED
|
@@ -436,19 +436,32 @@ module.exports = function (RED) {
|
|
|
436
436
|
const token = authResponse.data.data.obtainKrakenToken.token;
|
|
437
437
|
|
|
438
438
|
// B. Send Mutation
|
|
439
|
+
if (!krakenflexDeviceId) {
|
|
440
|
+
throw new Error('Device ID not available — cannot set preferences');
|
|
441
|
+
}
|
|
442
|
+
|
|
439
443
|
const mutation = `
|
|
440
|
-
mutation setPreferences($input:
|
|
441
|
-
|
|
444
|
+
mutation setPreferences($input: SmartFlexDevicePreferencesInput!) {
|
|
445
|
+
setDevicePreferences(input: $input) { __typename }
|
|
442
446
|
}`;
|
|
443
447
|
|
|
448
|
+
const DAYS = ['MONDAY','TUESDAY','WEDNESDAY','THURSDAY','FRIDAY','SATURDAY','SUNDAY'];
|
|
449
|
+
function buildDevicePreferencesInput(deviceId, socLimit, readyTime) {
|
|
450
|
+
return {
|
|
451
|
+
deviceId,
|
|
452
|
+
mode: 'CHARGE',
|
|
453
|
+
unit: 'PERCENTAGE',
|
|
454
|
+
schedules: DAYS.map(dayOfWeek => ({
|
|
455
|
+
dayOfWeek,
|
|
456
|
+
time: readyTime + ':00',
|
|
457
|
+
min: 0,
|
|
458
|
+
max: socLimit
|
|
459
|
+
}))
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
|
|
444
463
|
const variables = {
|
|
445
|
-
input:
|
|
446
|
-
accountNumber: account,
|
|
447
|
-
weekdayTargetSoc: limit,
|
|
448
|
-
weekendTargetSoc: limit,
|
|
449
|
-
weekdayTargetTime: time,
|
|
450
|
-
weekendTargetTime: time
|
|
451
|
-
}
|
|
464
|
+
input: buildDevicePreferencesInput(krakenflexDeviceId, limit, time)
|
|
452
465
|
};
|
|
453
466
|
|
|
454
467
|
const mutationResponse = await graphqlPost({
|
|
@@ -613,11 +626,17 @@ module.exports = function (RED) {
|
|
|
613
626
|
const token = authResponse.data.data.obtainKrakenToken.token;
|
|
614
627
|
|
|
615
628
|
const deviceResponse = await graphqlPost({
|
|
616
|
-
query: `query
|
|
629
|
+
query: `query getDevices($accountNumber: String!) { devices(accountNumber: $accountNumber) { id deviceType status { isSuspended } } }`,
|
|
617
630
|
variables: { accountNumber: account }
|
|
618
631
|
}, token);
|
|
619
632
|
|
|
620
|
-
if (deviceResponse.data.errors || !deviceResponse.data.data
|
|
633
|
+
if (deviceResponse.data.errors || !deviceResponse.data.data) {
|
|
634
|
+
scheduleSmartChargingVerification(expectedSuspended, intervals, index + 1);
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
const evDevice = (deviceResponse.data.data.devices || []).find(d => d.deviceType === 'ELECTRIC_VEHICLES');
|
|
639
|
+
if (!evDevice) {
|
|
621
640
|
scheduleSmartChargingVerification(expectedSuspended, intervals, index + 1);
|
|
622
641
|
return;
|
|
623
642
|
}
|
|
@@ -626,13 +645,14 @@ module.exports = function (RED) {
|
|
|
626
645
|
const ESTIMATED_VERIFICATION_COMPLEXITY = 200;
|
|
627
646
|
recordPoll(ESTIMATED_VERIFICATION_COMPLEXITY);
|
|
628
647
|
|
|
629
|
-
const actualSuspended =
|
|
648
|
+
const actualSuspended = evDevice.status.isSuspended;
|
|
630
649
|
if (actualSuspended === expectedSuspended) {
|
|
631
650
|
// Confirmed — clear remaining retries
|
|
632
651
|
smartChargingSuspended = actualSuspended;
|
|
633
652
|
smartChargingRetryTimeouts.forEach(t => clearTimeout(t));
|
|
634
653
|
smartChargingRetryTimeouts = [];
|
|
635
654
|
node.log(`Smart charging confirmed: suspended=${actualSuspended}`);
|
|
655
|
+
node.status({ fill: "green", shape: "dot", text: actualSuspended ? "Smart charging suspended" : "Smart charging enabled" });
|
|
636
656
|
} else {
|
|
637
657
|
scheduleSmartChargingVerification(expectedSuspended, intervals, index + 1);
|
|
638
658
|
}
|
|
@@ -1029,17 +1049,25 @@ module.exports = function (RED) {
|
|
|
1029
1049
|
const token = authResponse.data.data.obtainKrakenToken.token;
|
|
1030
1050
|
|
|
1031
1051
|
const deviceResponse = await graphqlPost({
|
|
1032
|
-
query: `query
|
|
1052
|
+
query: `query getDevices($accountNumber: String!) { devices(accountNumber: $accountNumber) { id deviceType status { isSuspended } } }`,
|
|
1033
1053
|
variables: { accountNumber: account }
|
|
1034
1054
|
}, token);
|
|
1035
1055
|
|
|
1036
|
-
if (deviceResponse.data.errors || !deviceResponse.data.data
|
|
1056
|
+
if (deviceResponse.data.errors || !deviceResponse.data.data) {
|
|
1037
1057
|
throw new Error(`Device fetch failed: ${JSON.stringify(deviceResponse.data.errors)}`);
|
|
1038
1058
|
}
|
|
1039
1059
|
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1060
|
+
function extractEvDevice(devices) {
|
|
1061
|
+
return (devices || []).find(d => d.deviceType === 'ELECTRIC_VEHICLES') || null;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
const evDevice = extractEvDevice(deviceResponse.data.data.devices);
|
|
1065
|
+
if (!evDevice) {
|
|
1066
|
+
throw new Error('No ELECTRIC_VEHICLES device found on account');
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
krakenflexDeviceId = evDevice.id;
|
|
1070
|
+
smartChargingSuspended = evDevice.status.isSuspended;
|
|
1043
1071
|
node.log(`Device ID cached: ${krakenflexDeviceId}, suspended: ${smartChargingSuspended}`);
|
|
1044
1072
|
} catch (e) {
|
|
1045
1073
|
node.warn(`Failed to fetch device ID at startup: ${e.message}. Smart charging toggle unavailable.`);
|
package/package.json
CHANGED