node-red-contrib-octopus-intelligent 1.3.1 → 1.3.3

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 CHANGED
@@ -5,6 +5,33 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.3.3] — 2026-05-22
9
+
10
+ ### Fixed
11
+ - **Saving Sessions card showed a 2-year-old session as "next"** — the category was emitting `events[0]` with no filter/sort, so stale historical events surfaced in `saving_session_start/end` and `saving_session_available` was effectively true forever. Now matches the `free-electricity` pattern: filter out ended events, sort earliest-first, take the first. `saving_session_available` now means "an upcoming session exists" as originally intended.
12
+ - **Octoplus "Enrolled" and "Loyalty points user" stuck at "unavailable"** — both binary sensors were published with `entity_category: config`, which makes read-only sensor state stick at "unavailable" on some HA installs. Removed — same fix as the v1.3.0 tariff-sensor cleanup. Entity IDs are unchanged; not a breaking change.
13
+ - **Example dashboard — Wheel of Fortune cards showed "Entity not found"** — `examples/ha-dashboard.yaml` referenced `..._wheel_of_fortune_*_spins`, but the entities are named "WoF …" so HA generates `..._wof_*_spins`. Corrected.
14
+ - **Example dashboard — Home Mini gauge showed "Entity is non-numeric"** on accounts with no Home Mini — the gauge is now wrapped in a conditional card that hides until the entity reports a value.
15
+
16
+ ### Added
17
+ - `saving_session_window_active` (binary sensor) — true when an upcoming session window is currently happening, regardless of whether you joined.
18
+ - `saving_session_active` (binary sensor) — true only when you have joined the current session AND we are inside its window. Use this to drive automations that should only run when there is a payoff.
19
+
20
+ ### Changed (HA-side breaking)
21
+ - `saving_session_joined` now publishes as `binary_sensor` instead of `sensor` — fixes the "False" display anomaly caused by HA's sensor domain rejecting raw booleans. **Update automations and dashboards referencing `sensor.saving_session_joined` to use `binary_sensor.saving_session_joined`.** Payload field name (`msg.payload.saving_session_joined`) is unchanged. Mirror of the v1.3.0 `octoplus_enrolled` migration. The plugin publishes an empty config to the old `sensor/.../config` topic on startup to clean the orphan from HA.
22
+
23
+ ## [1.3.2] — 2026-05-14
24
+
25
+ Defensive hardening pass following the v1.3.1 hotfix audit. No user-facing behaviour change against the current live Kraken API — every affected field already arrives as a JSON number today. The fix forecloses the same latent crash class (`TypeError: ...toFixed is not a function`) if Kraken ever serialises these scalars as strings, matching how `energyAddedKwh` is already returned.
26
+
27
+ ### Fixed
28
+ - `lib/categories/electricity.js` — `tariff.unitRate` and `tariff.standingCharge` (both import and export branches) now coerce via `parseFloat()` before emitting. Prevents string passthrough that would (a) break `device_class: monetary` sensors in HA and (b) crash any downstream arithmetic.
29
+ - `lib/categories/gas.js` — same treatment for `tariff.unitRate` and `tariff.standingCharge`.
30
+ - `lib/categories/account.js` — `balance` (pence) now coerces via `parseFloat()` before emitting `account_balance_pence`. JavaScript's `/` operator was already coercing for `account_balance_pounds`, so this only tightens type consistency on the integer pence field.
31
+
32
+ ### Tests
33
+ - Added string-input regression tests for each coerced field, asserting `typeof === 'number'`. 4 new tests, 237 total (was 233).
34
+
8
35
  ## [1.3.1] — 2026-05-14
9
36
 
10
37
  Critical hotfix for v1.3.0. Users on 1.3.0 should upgrade immediately.
@@ -290,11 +290,15 @@ sections:
290
290
  entities:
291
291
  - entity: binary_sensor.octopus_intelligent_octopus_saving_session_available
292
292
  name: Next session available
293
+ - entity: binary_sensor.octopus_intelligent_octopus_saving_session_window_active
294
+ name: Session window active
295
+ - entity: binary_sensor.octopus_intelligent_octopus_saving_session_active
296
+ name: Session active (joined)
293
297
  - entity: sensor.octopus_intelligent_octopus_saving_session_start
294
298
  name: Next session — starts
295
299
  - entity: sensor.octopus_intelligent_octopus_saving_session_end
296
300
  name: Next session — ends
297
- - entity: sensor.octopus_intelligent_octopus_saving_session_joined
301
+ - entity: binary_sensor.octopus_intelligent_octopus_saving_session_joined
298
302
  name: Joined
299
303
 
300
304
  - type: grid
@@ -317,23 +321,35 @@ sections:
317
321
  - type: glance
318
322
  title: Wheel of Fortune
319
323
  entities:
320
- - entity: sensor.octopus_intelligent_octopus_wheel_of_fortune_electricity_spins
324
+ - entity: sensor.octopus_intelligent_octopus_wof_electricity_spins
321
325
  name: Elec spins
322
- - entity: sensor.octopus_intelligent_octopus_wheel_of_fortune_gas_spins
326
+ - entity: sensor.octopus_intelligent_octopus_wof_gas_spins
323
327
  name: Gas spins
324
328
 
325
329
  - type: grid
326
330
  cards:
327
- - type: gauge
328
- entity: sensor.octopus_intelligent_octopus_home_mini_demand
329
- name: Home Mini — live demand
330
- unit: kW
331
- min: 0
332
- max: 10
333
- severity:
334
- green: 0
335
- yellow: 3
336
- red: 6
331
+ # Conditional wrapper: the gauge card errors with "Entity is non-numeric"
332
+ # on accounts without a Home Mini (mini_demand_kw is null). Hide it until
333
+ # the entity reports a real value.
334
+ - type: conditional
335
+ conditions:
336
+ - condition: state
337
+ entity: sensor.octopus_intelligent_octopus_home_mini_demand
338
+ state_not: unknown
339
+ - condition: state
340
+ entity: sensor.octopus_intelligent_octopus_home_mini_demand
341
+ state_not: unavailable
342
+ card:
343
+ type: gauge
344
+ entity: sensor.octopus_intelligent_octopus_home_mini_demand
345
+ name: Home Mini — live demand
346
+ unit: kW
347
+ min: 0
348
+ max: 10
349
+ severity:
350
+ green: 0
351
+ yellow: 3
352
+ red: 6
337
353
 
338
354
  - type: grid
339
355
  cards:
@@ -13,7 +13,9 @@ function buildQuery(account) {
13
13
  }
14
14
 
15
15
  function parseResponse(data) {
16
- const balancePence = ((data.account || {}).balance) ?? null;
16
+ // Kraken numeric scalars can serialise as strings — coerce defensively
17
+ const raw = ((data.account || {}).balance) ?? null;
18
+ const balancePence = raw !== null ? parseFloat(raw) : null;
17
19
  return {
18
20
  account_balance_pence: balancePence,
19
21
  account_balance_pounds: balancePence !== null ? parseFloat((balancePence / 100).toFixed(2)) : null,
@@ -55,9 +55,10 @@ function parseRatesResponse(data) {
55
55
  const fieldsFor = (prefix, agreements) => {
56
56
  const latest = agreements[0];
57
57
  const tariff = (latest && latest.tariff) || {};
58
+ // Kraken Float scalars can serialise as strings — coerce defensively
58
59
  return {
59
- [`${prefix}_unit_rate`]: tariff.unitRate ?? null,
60
- [`${prefix}_standing_charge`]: tariff.standingCharge ?? null,
60
+ [`${prefix}_unit_rate`]: tariff.unitRate != null ? parseFloat(tariff.unitRate) : null,
61
+ [`${prefix}_standing_charge`]: tariff.standingCharge != null ? parseFloat(tariff.standingCharge) : null,
61
62
  [`${prefix}_tariff_code`]: tariff.productCode || null,
62
63
  [`${prefix}_valid_from`]: (latest && latest.validFrom) || null,
63
64
  [`${prefix}_valid_to`]: (latest && latest.validTo) || null,
@@ -52,9 +52,10 @@ function parseRatesResponse(data) {
52
52
  }
53
53
  const latest = agreements[0];
54
54
  const tariff = latest.tariff || {};
55
+ // Kraken Float scalars can serialise as strings — coerce defensively
55
56
  return {
56
- gas_unit_rate: tariff.unitRate ?? null,
57
- gas_standing_charge: tariff.standingCharge ?? null,
57
+ gas_unit_rate: tariff.unitRate != null ? parseFloat(tariff.unitRate) : null,
58
+ gas_standing_charge: tariff.standingCharge != null ? parseFloat(tariff.standingCharge) : null,
58
59
  gas_tariff_code: tariff.productCode || null,
59
60
  gas_valid_from: latest.validFrom || null,
60
61
  gas_valid_to: latest.validTo || null,
@@ -26,25 +26,39 @@ function buildQuery(account) {
26
26
  }
27
27
 
28
28
  function parseResponse(data) {
29
+ const now = new Date();
29
30
  const ss = data.savingSessions || {};
30
31
  const acct = ss.account || {};
31
32
  const events = ss.events || [];
32
- const nextEvent = events[0] || null;
33
+
34
+ // Filter to events not yet ended; sort earliest-first; take the first
35
+ const upcoming = events
36
+ .filter(e => new Date(e.endAt) > now)
37
+ .sort((a, b) => new Date(a.startAt) - new Date(b.startAt));
38
+ const next = upcoming[0] || null;
39
+
33
40
  const joinedIds = (acct.joinedEvents || []).map(e => e.eventId);
34
- const isJoined = nextEvent ? joinedIds.includes(nextEvent.id) : false;
41
+ const isJoined = next ? joinedIds.includes(next.id) : false;
42
+
43
+ const inWindow = next
44
+ && new Date(next.startAt) <= now
45
+ && new Date(next.endAt) > now;
35
46
 
36
47
  return {
37
- saving_session_available: events.length > 0,
38
- saving_session_start: nextEvent ? nextEvent.startAt : null,
39
- saving_session_end: nextEvent ? nextEvent.endAt : null,
48
+ saving_session_available: next !== null,
49
+ saving_session_start: next ? next.startAt : null,
50
+ saving_session_end: next ? next.endAt : null,
40
51
  saving_session_joined: isJoined,
52
+ saving_session_window_active: !!inWindow,
53
+ saving_session_active: !!(inWindow && isJoined),
41
54
  saving_sessions_error: null
42
55
  };
43
56
  }
44
57
 
45
58
  const defaultData = {
46
59
  saving_session_available: null, saving_session_start: null, saving_session_end: null,
47
- saving_session_joined: null, saving_sessions_error: null
60
+ saving_session_joined: null, saving_session_window_active: null, saving_session_active: null,
61
+ saving_sessions_error: null
48
62
  };
49
63
 
50
64
  module.exports = { buildQuery, parseResponse, defaultData };
package/lib/payload.js CHANGED
@@ -59,7 +59,8 @@ function buildDefaultPayload(state) {
59
59
  wheel_of_fortune_gas_used: null, wheel_of_fortune_error: null,
60
60
  mini_demand_kw: null, mini_consumption_delta_kwh: null, mini_read_at: null, home_mini_error: null,
61
61
  saving_session_available: null, saving_session_start: null, saving_session_end: null,
62
- saving_session_joined: null, saving_session_points: null, saving_sessions_error: null,
62
+ saving_session_joined: null, saving_session_window_active: null, saving_session_active: null,
63
+ saving_session_points: null, saving_sessions_error: null,
63
64
  free_electricity_active: null, free_electricity_available: null,
64
65
  free_electricity_start: null, free_electricity_end: null, free_electricity_error: null,
65
66
  intelligent_error: null,
@@ -190,7 +190,6 @@ module.exports = function (RED) {
190
190
  { id: 'home_mini_error', name: 'Home Mini Error', icon: 'mdi:alert-circle', val: 'home_mini_error', category: 'diagnostic' },
191
191
 
192
192
  // --- Saving Sessions (main) ---
193
- { id: 'saving_session_joined', name: 'Saving Session Joined', icon: 'mdi:lightning-bolt-circle', val: 'saving_session_joined' },
194
193
  { id: 'saving_session_points', name: 'Octopus Points', icon: 'mdi:star', val: 'saving_session_points' },
195
194
  // --- Saving Sessions (config) ---
196
195
  { id: 'saving_session_start', name: 'Saving Session Start', class: 'timestamp', icon: 'mdi:calendar-clock', val: 'saving_session_start' },
@@ -327,6 +326,51 @@ module.exports = function (RED) {
327
326
  };
328
327
  node.broker.client.publish(`${mqttPrefix}/binary_sensor/${uniqueIdPrefix}_saving_session_available/config`, JSON.stringify(savingSessionBinarySensor), { retain: true });
329
328
 
329
+ // G2a. Saving Session Window Active Binary Sensor (v1.3.3)
330
+ const savingSessionWindowActiveSensor = {
331
+ name: "Octopus Saving Session Window Active",
332
+ unique_id: `${uniqueIdPrefix}_saving_session_window_active`,
333
+ state_topic: stateTopic,
334
+ value_template: "{{ value_json.saving_session_window_active }}",
335
+ payload_on: "True",
336
+ payload_off: "False",
337
+ icon: "mdi:clock-check-outline",
338
+ device: device
339
+ };
340
+ node.broker.client.publish(`${mqttPrefix}/binary_sensor/${uniqueIdPrefix}_saving_session_window_active/config`, JSON.stringify(savingSessionWindowActiveSensor), { retain: true });
341
+
342
+ // G2b. Saving Session Active Binary Sensor (v1.3.3) — joined AND in window
343
+ const savingSessionActiveSensor = {
344
+ name: "Octopus Saving Session Active",
345
+ unique_id: `${uniqueIdPrefix}_saving_session_active`,
346
+ state_topic: stateTopic,
347
+ value_template: "{{ value_json.saving_session_active }}",
348
+ payload_on: "True",
349
+ payload_off: "False",
350
+ icon: "mdi:home-export-outline",
351
+ device: device
352
+ };
353
+ node.broker.client.publish(`${mqttPrefix}/binary_sensor/${uniqueIdPrefix}_saving_session_active/config`, JSON.stringify(savingSessionActiveSensor), { retain: true });
354
+
355
+ // G2c. v1.3.3 migration: delete the deprecated sensor.saving_session_joined
356
+ // entity. HA's sensor domain doesn't render booleans cleanly. Empty
357
+ // payload on the discovery topic with retain tells HA the entity no
358
+ // longer exists. Safe to keep across releases.
359
+ node.broker.client.publish(`${mqttPrefix}/sensor/${uniqueIdPrefix}_saving_session_joined/config`, "", { retain: true });
360
+
361
+ // G2d. Saving Session Joined Binary Sensor (v1.3.3 migration)
362
+ const savingSessionJoinedSensor = {
363
+ name: "Octopus Saving Session Joined",
364
+ unique_id: `${uniqueIdPrefix}_saving_session_joined`,
365
+ state_topic: stateTopic,
366
+ value_template: "{{ value_json.saving_session_joined }}",
367
+ payload_on: "True",
368
+ payload_off: "False",
369
+ icon: "mdi:account-check",
370
+ device: device
371
+ };
372
+ node.broker.client.publish(`${mqttPrefix}/binary_sensor/${uniqueIdPrefix}_saving_session_joined/config`, JSON.stringify(savingSessionJoinedSensor), { retain: true });
373
+
330
374
  // G3. Free Electricity Active Binary Sensor
331
375
  const freeElectricityActiveSensor = {
332
376
  name: "Octopus Free Electricity Active",
@@ -356,7 +400,9 @@ module.exports = function (RED) {
356
400
  // G5. Octoplus Enrolled Binary Sensor
357
401
  // Published as binary_sensor (not sensor) because the value is a boolean —
358
402
  // HA's sensor domain rejects booleans without a device_class, leaving the
359
- // entity unregistered.
403
+ // entity unregistered. No entity_category: 'config' on a read-only sensor
404
+ // makes its state stick at "unavailable" on some HA installs (same fix as
405
+ // the v1.3.0 tariff-sensor cleanup — see CHANGELOG).
360
406
  const octoplusEnrolledBinarySensor = {
361
407
  name: "Octopus Octoplus Enrolled",
362
408
  unique_id: `${uniqueIdPrefix}_octoplus_enrolled`,
@@ -365,12 +411,12 @@ module.exports = function (RED) {
365
411
  payload_on: "True",
366
412
  payload_off: "False",
367
413
  icon: "mdi:star-circle",
368
- entity_category: "config",
369
414
  device: device
370
415
  };
371
416
  node.broker.client.publish(`${mqttPrefix}/binary_sensor/${uniqueIdPrefix}_octoplus_enrolled/config`, JSON.stringify(octoplusEnrolledBinarySensor), { retain: true });
372
417
 
373
418
  // G6. Octoplus Loyalty Points (boolean) Binary Sensor
419
+ // No entity_category — see G5.
374
420
  const octoplusLoyaltyBinarySensor = {
375
421
  name: "Octopus Octoplus Loyalty Points",
376
422
  unique_id: `${uniqueIdPrefix}_octoplus_loyalty_points_user`,
@@ -379,7 +425,6 @@ module.exports = function (RED) {
379
425
  payload_on: "True",
380
426
  payload_off: "False",
381
427
  icon: "mdi:star",
382
- entity_category: "config",
383
428
  device: device
384
429
  };
385
430
  node.broker.client.publish(`${mqttPrefix}/binary_sensor/${uniqueIdPrefix}_octoplus_loyalty_points_user/config`, JSON.stringify(octoplusLoyaltyBinarySensor), { retain: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-octopus-intelligent",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "Node-RED integration for Octopus Energy Intelligent Octopus Go with Home Assistant MQTT discovery",
5
5
  "main": "octopus-intelligent.js",
6
6
  "scripts": {