node-red-contrib-octopus-intelligent 1.5.0 → 1.7.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +597 -442
  2. package/README.md +1234 -980
  3. package/examples/basic-monitoring.json +1 -1
  4. package/examples/boost-on-cheap-or-surplus.json +171 -0
  5. package/examples/charging-and-error-alerts.json +95 -0
  6. package/examples/cheapest-window-planner.json +165 -0
  7. package/examples/daily-charging-summary.json +165 -0
  8. package/examples/ha-dashboard.yaml +667 -599
  9. package/examples/mqtt-integration.json +1 -1
  10. package/examples/node-red-dashboard-flow.json +1377 -1199
  11. package/examples/set-preferences.json +1 -1
  12. package/lib/active-now.js +33 -0
  13. package/lib/api-metrics.js +31 -31
  14. package/lib/auth.js +25 -20
  15. package/lib/boost.js +85 -0
  16. package/lib/categories/account.js +32 -32
  17. package/lib/categories/applicable-rates.js +137 -127
  18. package/lib/categories/completed-dispatches.js +36 -35
  19. package/lib/categories/electricity.js +156 -146
  20. package/lib/categories/flex-planned-dispatches.js +36 -36
  21. package/lib/categories/free-electricity.js +73 -61
  22. package/lib/categories/gas.js +102 -95
  23. package/lib/categories/home-mini.js +45 -37
  24. package/lib/categories/intelligent.js +221 -124
  25. package/lib/categories/octoplus.js +35 -32
  26. package/lib/categories/saving-sessions.js +78 -64
  27. package/lib/categories/smartflex-inverter.js +95 -0
  28. package/lib/categories/smartflex-vehicle.js +198 -0
  29. package/lib/categories/wheel-of-fortune.js +50 -49
  30. package/lib/commands.js +69 -0
  31. package/lib/discovery-retry.js +16 -0
  32. package/lib/discovery.js +154 -85
  33. package/lib/graphql-errors.js +174 -0
  34. package/lib/graphql.js +141 -44
  35. package/lib/http-get-json.js +80 -22
  36. package/lib/payload.js +104 -88
  37. package/lib/poll-retry.js +71 -0
  38. package/lib/poll-tick.js +112 -44
  39. package/lib/preferences.js +34 -0
  40. package/lib/scheduler.js +85 -47
  41. package/lib/sensor-definitions.js +269 -0
  42. package/lib/timezone.js +67 -49
  43. package/lib/update-check.js +38 -38
  44. package/lib/values.js +47 -0
  45. package/octopus-intelligent.html +258 -205
  46. package/octopus-intelligent.js +2816 -1807
  47. package/package.json +54 -54
package/CHANGELOG.md CHANGED
@@ -1,442 +1,597 @@
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
- ## [1.5.0] — 2026-06-13
9
-
10
- Schedule visibility, tariff rate bands, proactive update notification, and a Node-RED Dashboard 2.0 example.
11
-
12
- ### Added — Schedule visibility (import & export)
13
- - 24h schedule stats: `applicable_rates_{min,max,median,avg}_pence` and `electricity_export_rate_*` equivalents — min/max/median/avg over the next 24h of half-hourly rates.
14
- - The full `applicable_rates` / `electricity_export_rate` slot arrays are now exposed as MQTT entity attributes on the existing `*_count` sensors, accessible via `state_attr(...)` in HA templates.
15
-
16
- ### Added — Tariff rate bands
17
- - `electricity_day_rate`, `electricity_night_rate`, `electricity_ev_peak_rate`, `electricity_ev_off_peak_rate` — raw tariff-defined bands from the Kraken `DayNightTariff` / `FourRateEvTariff` types. Null on tariffs without banding (half-hourly/Agile users see nulls; Economy 7 / FourRateEv users see values).
18
-
19
- ### Added — Update notification
20
- - HA MQTT Update entity (`update.octopus_intelligent_node_update`) surfacing newer-version availability in HA's Settings → Updates panel. Requires HA ≥ 2022.4.
21
- - Node-RED debug log emits `node.warn` once per detected new version, with install instructions.
22
- - New payload fields: `installed_version`, `latest_version`, `update_available`, `update_check_at`, `update_check_error`. Checked once per 24h via the unified scheduler.
23
-
24
- ### Added — Promotion to MQTT entities (closing v1.3.0 gaps)
25
- - 8 previously payload-only fields promoted to MQTT entities: `applicable_rates_prev_pence/_gbp/_to`, `applicable_rates_next_pence/_gbp/_from`, `electricity_export_rate_prev_gbp`, `electricity_export_rate_next_gbp`.
26
-
27
- ### Added — Per-category error binary sensors
28
- - 15 new `binary_sensor`s with `device_class: problem`, one per category. `OFF` when healthy / `ON` when the corresponding `<category>_error` payload field is set. Existing string error sensors retained — no breakage.
29
-
30
- ### Added — Node-RED Dashboard 2.0 example
31
- - `examples/node-red-dashboard-flow.json` — importable Dashboard 2.0 flow with 32 widgets across 6 pages (Controls, Status, Tariff, Optimization, Account, Diagnostics), plus writable controls routed back into the node input.
32
- - Two annotated **sample function nodes** (`find-cheapest-window`, `is-cheapest-now`) demonstrating user-side derivation over `applicable_rates`. Example code only — not part of the published payload, keeping with the "expose raw data, no inference" principle.
33
-
34
- ### Fixed — Example HA dashboard (`examples/ha-dashboard.yaml`)
35
- - Home Mini live-demand gauge now floors at `-10 kW` (was `min: 0`) so solar export displays, with the green severity band extended to cover the negative range.
36
- - Tariff rate-bands card is hidden on half-hourly/Agile tariffs (null bands render to `"None"`/`unknown`, not `unavailable` — the conditional now excludes all three).
37
- - Gas cards are hidden for electricity-only homes (gated on `gas_tariff_code`).
38
-
39
- ### Backwards compatibility
40
- - All existing payload field names, MQTT topics, HA entity `unique_id`s, input commands, and node config fields are preserved. v1.4.0 → v1.5.0 is a zero-config upgrade.
41
-
42
- ## [1.4.0] — 2026-05-29
43
-
44
- Single poll loop. The V1 `setInterval(fetchData)` intelligent loop and the V2 `createScheduler(pollDueCategories)` category loop are merged into one clock-aligned scheduler with one auth and one emit per tick. No HA-side changes.
45
-
46
- ### Fixed
47
- - **Intermittent `KT-CT-1199` "Too many requests"** on `flexPlannedDispatches` — the standalone `flex_planned_dispatches` V2 category queried the same endpoint as the V1 intelligent poll, and the two unsynchronised loops phase-drifted into bursts that tripped Kraken's burst limit. The intelligent poll now owns `flexPlannedDispatches`; the standalone category is removed.
48
- - **Whole payload was nuked on any single-category error**, and `intelligent_error` was never set. Every category now follows one error policy: record `<category>_error`, keep last-good data, retry next interval. No permanent disable.
49
- - **Slow polls could overlap a tick** — added an in-flight guard around the scheduler.
50
-
51
- ### Changed (internal architecture; no HA-side breakage)
52
- - Every category exposes `async poll(token) → partialPayload`. Simple categories use a `simplePoll` factory; the intelligent poll is a bespoke category that owns both the devices and dispatch queries.
53
- - Tick / poll / error-merge logic moved into `lib/poll-tick.js` and `lib/scheduler.js` for unit-test coverage.
54
- - Manual refresh, MQTT refresh, and post-mutation validation re-polls all go through the same scheduler / intelligent-poll path.
55
-
56
- ### Unchanged
57
- - All payload field names, MQTT topics, `unique_id`s, HA entity IDs, input commands, and node config fields.
58
-
59
- ## [1.3.3] — 2026-05-22
60
-
61
- ### Fixed
62
- - **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.
63
- - **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.
64
- - **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.
65
- - **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.
66
-
67
- ### Added
68
- - `saving_session_window_active` (binary sensor) — true when an upcoming session window is currently happening, regardless of whether you joined.
69
- - `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.
70
-
71
- ### Changed (HA-side breaking)
72
- - `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.
73
-
74
- ## [1.3.2] — 2026-05-14
75
-
76
- 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.
77
-
78
- ### Fixed
79
- - `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.
80
- - `lib/categories/gas.js` — same treatment for `tariff.unitRate` and `tariff.standingCharge`.
81
- - `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.
82
-
83
- ### Tests
84
- - Added string-input regression tests for each coerced field, asserting `typeof === 'number'`. 4 new tests, 237 total (was 233).
85
-
86
- ## [1.3.1] — 2026-05-14
87
-
88
- Critical hotfix for v1.3.0. Users on 1.3.0 should upgrade immediately.
89
-
90
- ### Fixed
91
- - **Intelligent category crash on numeric string inputs** — `flexPlannedDispatches.energyAddedKwh` is returned by the live Kraken API as a string. The intelligent category's reduce accumulator concatenated strings instead of summing, then called `.toFixed()` on the resulting string, raising `TypeError: totalEnergy.toFixed is not a function`. Whole intelligent payload section fell back to `defaultData` (null slot times, `total_energy: 0`, `next_kwh: "0"`), which surfaced in Home Assistant as "Error updating entity" for every intelligent sensor. Fixed by coercing `energyAddedKwh` via `parseFloat()` before arithmetic and formatting in `lib/categories/intelligent.js`, matching the pattern already used in `lib/categories/flex-planned-dispatches.js`. Added regression tests covering both positive and negative (export dispatch) string inputs.
92
- - `next_kwh` now consistently formats with two decimal places (e.g. `"5.50"`, `"15.20"`) per the documented contract in README, HTML help, and `test-mocks.js`. The v1.3.0 path stripped trailing zeros via `String(parseFloat(...))` — that branch is unreachable now because it always crashed before reaching it, but the format is corrected for completeness.
93
-
94
- ## [1.3.0] — 2026-05-12
95
-
96
- Major additive release covering the full Octopus Energy consumer read surface. No breaking changes to v1.2.x payload fields, entity IDs, MQTT topics, input commands, or node config fields. All v1.2.x automations and dashboards continue to work unchanged.
97
-
98
- ### Added — Electricity (import)
99
- - `electricity_standing_charge` — daily standing charge (p/day)
100
- - `electricity_unit_rate` — fixed unit rate (p/kWh); `null` on half-hourly tariffs
101
- - `electricity_tariff_code`, `electricity_valid_from`, `electricity_valid_to`
102
- - `electricity_consumption_kwh` — previous day import consumption
103
- - `electricity_consumption_from`, `electricity_consumption_to` — period boundaries
104
- - `applicable_rates`, `applicable_rates_count` — full 48-slot half-hourly schedule
105
- - `applicable_rates_current_pence`, `applicable_rates_current_gbp` — live rate (use these on half-hourly tariffs)
106
- - `applicable_rates_prev_pence/_gbp/_to`, `applicable_rates_next_pence/_gbp/_from` — adjacent slot rates and transition timestamps (payload-only; not currently exposed as MQTT entities — see README)
107
-
108
- ### Added — Electricity (export)
109
- - `electricity_export_standing_charge` — typically `0` for Agile Outgoing
110
- - `electricity_export_unit_rate` — fixed; `null` on half-hourly export tariffs
111
- - `electricity_export_tariff_code` (e.g. `AGILE-OUTGOING-19-05-13`), `electricity_export_valid_from`, `electricity_export_valid_to`
112
- - `electricity_export_consumption_kwh`, `_from`, `_to` — previous day export from the export meter
113
- - `electricity_export_rate`, `electricity_export_rate_count` — full 48-slot half-hourly export schedule
114
- - `electricity_export_rate_current_pence/_gbp` — live export rate
115
- - `electricity_export_rate_prev_pence/_to`, `electricity_export_rate_next_pence/_from` — adjacent export slot rates
116
-
117
- ### Added — Gas
118
- - `gas_standing_charge`, `gas_unit_rate`, `gas_tariff_code`, `gas_valid_from`, `gas_valid_to`
119
- - `gas_consumption_kwh`, `gas_consumption_from`, `gas_consumption_to`
120
-
121
- ### Added — Home Mini
122
- - `mini_demand_kw` (kW, numeric) — real-time grid demand
123
- - `mini_consumption_delta_kwh` (kWh, numeric) — half-hour period consumption
124
- - `mini_read_at` — timestamp of most recent telemetry
125
- - Opt-in via "Enable Home Mini" checkbox in node config
126
-
127
- ### Added — Rewards
128
- - `saving_session_available` (binary), `saving_session_start`, `saving_session_end`, `saving_session_joined`
129
- - `free_electricity_active` (binary), `free_electricity_available` (binary), `free_electricity_start`, `free_electricity_end`
130
- - `wheel_of_fortune_electricity_spins`, `wheel_of_fortune_gas_spins` — opt-in via node config checkbox
131
- - `octoplus_enrolled` (binary sensor), `octoplus_enrollment_status` (string), `octoplus_loyalty_points_user` (binary sensor)
132
-
133
- ### Added — Account & dispatches
134
- - `account_balance_pounds`, `account_balance_pence`
135
- - `completed_dispatches` (array), `completed_dispatches_count` — completed intelligent dispatch history
136
- - `flex_planned_dispatches` (array), `flex_planned_dispatches_count` — upcoming flex dispatches (replaces deprecated `plannedDispatches`)
137
-
138
- ### Added — Infrastructure
139
- - **Account discovery** — automatic product detection at startup; categories auto-enable based on registered products and discover both import and export meter points by `direction`, not array position
140
- - **Per-category poll intervals** — configurable in node editor for each data source
141
- - **1-second clock-aligned category scheduler** — independent polling; one slow category doesn't block others
142
-
143
- ### Changed
144
- - **Octopus `wheelOfFortuneSpins` migrated to `wheelOfFortuneSpinsAllowed`** on `api.backend.octopus.energy` — the old field was deprecated and scheduled for removal 2026-04-20
145
- - **Octopus `savingSessions` migrated to `api.backend.octopus.energy`** endpoint — the field was removed from the main endpoint
146
- - **`octoplus_enrolled` and `octoplus_loyalty_points_user` now publish as `binary_sensor` instead of `sensor`** — these are boolean values and HA's sensor domain rejects raw booleans. **HA-side breaking change for users referencing the old `sensor.*` entity IDs**: update automations and dashboards to use `binary_sensor.*`. Payload field names (`msg.payload.octoplus_enrolled`, `msg.payload.octoplus_loyalty_points_user`) are unchanged.
147
- - **`entity_category: config` removed** from read-only tariff/validity sensors (`electricity_unit_rate`, `electricity_tariff_code`, `electricity_valid_from/to`, `gas_*`, `electricity_export_*`, `saving_session_start/end`, `free_electricity_start/end`, `octoplus_enrollment_status`). These now appear in the main device entity list rather than a separate Configuration section. HA's `entity_category: config` is intended for user-configurable entities (switches, numbers, selects) — applying it to read-only sensors caused state to stick at "unavailable" on some installs.
148
-
149
- ### Fixed
150
- - **Import/export meter point selection** — discovery now selects meter points by the `direction` field (`IMPORT` or `EXPORT`), not array position. Earlier dev builds on accounts with both meters could surface export data as import (live "current rate" showing the export Agile rate instead of the import tariff). No stable v1.x release was affected; caught and fixed before v1.3.0 ship.
151
- - **MQTT transport headers** — `lib/graphql.js` now sends `User-Agent: node-red-contrib-octopus-intelligent/<version>` on every request. Without it, `api.backend.octopus.energy` returns 403 at the edge — which previously surfaced as "WoF returns HTML" and silently broken saving sessions.
152
- - **MQTT auth format** — uses raw JWT in the Authorization header (no `JWT ` prefix). Main endpoint accepts both; backend endpoint sub-resolvers require the raw form.
153
- - **Saving sessions schema migration** — removed deprecated `octopoints` field from `SavingSessionsAccountType` query (Octopus moved loyalty points to the Octoplus query).
154
- - **Gas tariff query fragments** — `GasTariffType` is an object type, not a union — removed inline fragments that caused "Fragment cannot be spread here" errors.
155
-
156
- ### Unchanged (no breaking changes)
157
- - All v1.2.x payload field names in `msg.payload`
158
- - All v1.2.x MQTT topics, `unique_id` values, and HA entity IDs (except the Octoplus domain change noted above)
159
- - All v1.2.x input commands: `set_limit`, `set_time`, `set_smart_charging`, `set_timezone`
160
- - All v1.2.x node config fields: `accountNumber`, `apiKey`, `broker`, `enableMqtt`, `name`, `refreshInterval`, `timezoneOverride`
161
- - Intelligent Octopus Go charging schedule, smart charging toggle, charging preferences
162
-
163
- ---
164
-
165
- ## [1.2.1] — 2026-04-29
166
-
167
- ### Fixed
168
- - **Deprecated API migration** — moved smart-charging verification from the deprecated `registeredKrakenflexDevice` query to the current `devices` query
169
- - **Mutation migration** — `setVehicleChargePreferences` (deprecated) replaced with `setDevicePreferences` using the 7-day schedule input
170
- - **Startup device fetch** — uses the current `devices` query instead of deprecated `registeredKrakenflexDevice`
171
-
172
- ### Unchanged
173
- - All v1.2.0 payload fields, MQTT topics, and entity IDs preserved
174
-
175
- ---
176
-
177
- ## [1.2.0] - 2026-04-26
178
-
179
- ### Added
180
- - **Smart Charging Toggle** — suspend or unsuspend Octopus intelligent charging from Node-RED or Home Assistant
181
- - `msg.payload = { set_smart_charging: true }` — enable (unsuspend)
182
- - `msg.payload = { set_smart_charging: false }` — disable (suspend)
183
- - **HA MQTT Switch** — "Smart Charging" switch entity in Home Assistant (auto-discovered)
184
- - **`smart_charging` payload field** — `true` = active, `false` = suspended, `null` = unknown (startup fetch pending or failed)
185
- - **Device ID startup fetch** — `krakenflexDeviceId` fetched once at startup via `registeredKrakenflexDevice` query; cached permanently
186
-
187
- ### Technical
188
- - Mirrors `setPreferences` pattern: auth → mutation → optimistic update → exponential backoff verification (15s/30s/60s/120s)
189
- - Verification re-fetches `registeredKrakenflexDevice.suspended` to confirm state change
190
- - Zero new npm dependencies
191
-
192
- ---
193
-
194
- ## [1.1.1] - 2026-04-26
195
-
196
- ### Security
197
- - **Removed `axios` dependency** — replaced with Node.js built-in `https` module; eliminates 13 transitive packages and all associated supply chain risk
198
- - **Removed test/mock files from npm package** — `__tests__/` and `test-mocks.js` no longer published; removes 139 kB of dev artefacts from end-user installs
199
- - **Removed images from npm package** — 364 kB of images no longer bundled; README images now reference GitHub raw URLs and render correctly on npmjs.com
200
-
201
- ### Changed
202
- - Package size reduced from 369 kB → 27 kB (93% reduction)
203
- - Zero production dependencies (was: `axios ^1.6.0`)
204
-
205
- ---
206
-
207
- ## [1.1.0] - 2026-04-24
208
-
209
- ### Added
210
- - **Locale Timestamps** — new `*_locale` fields in every payload, always in server auto-detected timezone
211
- - `slot1_start_locale`, `slot1_end_locale`, `slot2_start_locale`, `slot2_end_locale`
212
- - `slot3_start_locale`, `slot3_end_locale`, `window_start_locale`, `window_end_locale`
213
- - `next_start_locale`
214
- - **Timezone Metadata** — `timezone_detected` (server auto-detect) and `timezone_applied` (active TZ for display fields)
215
- - **HA Timezone Select Entity** — `select.octopus_timezone` with 15 curated IANA timezones covering all Octopus operating countries (UK, AU, DE, ES, NZ, US)
216
- - Selection persists across Node-RED restarts via node context storage
217
- - State republished to HA on Node-RED startup
218
- - **`set_timezone` Input Command** — `msg.payload = { set_timezone: "Europe/London" }`, same pattern as `set_limit`/`set_time`
219
- - **`timezoneOverride` Node Config Field** — optional IANA timezone in node editor, leave blank for auto-detect
220
- - **Timezone Diagnostic Sensors** — `sensor.octopus_timezone_detected` and `sensor.octopus_timezone_applied`
221
-
222
- ### Changed
223
- - **Display timestamp fields now output resolved timezone** instead of raw UTC
224
- - Affected fields: `slot1_start`, `slot1_end`, `slot2_start`, `slot2_end`, `slot3_start`, `slot3_end`, `window_start`, `window_end`, `next_start`
225
- - Resolution order: HA-persisted selection → `timezoneOverride` config → server auto-detected
226
- - **Raw fields (`*_raw`) remain unchanged** — always exact UTC strings from the API
227
-
228
- ### Technical
229
- - Zero new npm dependencies — native `Intl.DateTimeFormat` API (Node 14 compatible)
230
- - `convertToTimezone(dateStr, tz)` — handles DST correctly, falls back to original string on error
231
- - `resolveTimezone(node)` — reads node context storage, config field, or server auto-detect
232
-
233
- ## [1.0.5] - 2025-12-31
234
-
235
- ### Fixed
236
- - **README Documentation** - Removed misleading "Octopus Energy branded device cards" claim
237
- - Changed to accurate description: "Clean Organization" and "Professional Layout"
238
- - No actual Octopus Energy branding exists in Home Assistant device cards
239
- - Avoids potential trademark/copyright concerns
240
-
241
- ## [1.0.4] - 2025-12-11
242
-
243
- ### Added
244
- - **Manual Refresh Button (MQTT)** - "Octopus Refresh API" button in Home Assistant
245
- - Hardcoded 30-second rate limiting to prevent API spam
246
- - Shows warning in Node-RED when rate limited
247
- - Publishes refresh cooldown state to MQTT
248
- - **Refresh Available At Sensor** - Diagnostic timestamp sensor
249
- - Shows ISO timestamp when manual refresh becomes available
250
- - Displays as countdown in Home Assistant ("in 25 seconds")
251
- - Automatically clears to `null` after 30 seconds
252
- - Leverages Home Assistant's native timestamp handling
253
- - **Next Poll Time Sensors** - Shows when next automatic poll will occur
254
- - `sensor.octopus_next_poll_time` - Main sensor (timestamp class)
255
- - `sensor.octopus_next_poll_time_raw` - Diagnostic raw timestamp
256
- - Updates after each successful poll
257
- - **API Complexity Tracking** - Monitor API usage against 50,000 hourly limit
258
- - `sensor.octopus_api_requests_hour` - Count of requests (last 60 min)
259
- - `sensor.octopus_api_complexity_hour` - Total complexity used
260
- - `sensor.octopus_api_complexity_usage` - Percentage of limit used
261
- - Estimated complexity: Regular poll (300), Mutation (250), Pre-validation (200)
262
- - All API complexity sensors in Diagnostics section
263
- - **Enhanced Debug Output** - `msg.debug` now includes:
264
- - `responseHeaders` - Full HTTP response headers from API
265
- - `extensions` - GraphQL extensions field (if present)
266
- - `api_usage` - Comprehensive API usage metrics per request
267
- - **Comprehensive Test Coverage** - Added 5 new tests
268
- - Tests for MQTT refresh button rate limiting
269
- - Tests for countdown expiry behavior
270
- - Validates countdown doesn't go negative
271
- - Tests timer cleanup and MQTT message structure
272
-
273
- ### Changed
274
- - **Rate Limiting Strategy** - Different behavior for MQTT vs Node-RED
275
- - MQTT Button: Hardcoded 30-second cooldown (enforced)
276
- - Node-RED Input: No rate limiting (programmers control this)
277
- - Timestamp-based cooldown (not seconds counter)
278
- - **State Output** - Node-RED now outputs state on every poll
279
- - Previously only output on changes
280
- - Now outputs full `statusPayload` every poll cycle
281
- - Better for automations and monitoring
282
- - **Global Setter** - Updated `NodeRed_Global_Setter.js` with new fields:
283
- - `octopus_next_poll`
284
- - `octopus_refresh_available_at`
285
- - `octopus_api_requests_hour`
286
- - `octopus_api_complexity_hour`
287
- - `octopus_api_complexity_percent`
288
-
289
- ### Fixed
290
- - **Cooldown Timer Expiry** - Properly publishes `null` at 30 seconds
291
- - Prevents countdown showing negative values in Home Assistant
292
- - Timer cleanup prevents memory leaks
293
- - Exactly 2 MQTT messages per refresh (start + expiry)
294
-
295
- ### Technical Details
296
- - **API Complexity Estimation** - Since Octopus API doesn't provide actual complexity:
297
- - Uses estimated values based on query types
298
- - Tracks rolling 60-minute window
299
- - If actual complexity becomes available, will use it automatically
300
- - **Timestamp-Based Cooldown** - Uses ISO timestamps instead of seconds
301
- - Home Assistant handles countdown display automatically
302
- - Zero MQTT spam during countdown
303
- - Clean `null` state when ready
304
-
305
- ## [1.0.3] - 2025-12-04
306
-
307
- ### Added
308
- - **State reconciliation loop** for charging detection (every 10 seconds)
309
- - Automatically detects charging state based on cached slot timestamps
310
- - No API calls - uses local data only
311
- - Handles imminent/immediate slots when car is plugged in
312
- - Self-healing: corrects state if timers miss edge cases
313
- - **Flow Library scorecard compliance**
314
- - Added `version` field to `node-red` section in package.json (>=2.0.0)
315
- - Added `examples/` folder with 3 demonstration flows
316
- - Satisfies Node-RED Flow Library requirements
317
-
318
- ### Fixed
319
- - **Home Assistant sensors going "unknown"** when adjusting controls
320
- - Sensors now maintain last known values while editing pending preferences
321
- - Only update when fresh data arrives from API
322
- - Added `lastKnownState` cache and state merging in `publishCurrentState()`
323
- - **Charging state not updating** for imminent/immediate slots
324
- - Fixed edge case where slots starting <30s after poll were not detected
325
- - Reconciliation loop catches these within 10 seconds
326
- - Ensures accurate "Charging Now" sensor in Home Assistant
327
-
328
- ### Changed
329
- - Improved charging state management with redundant detection methods
330
- - Enhanced MQTT state publishing to preserve sensor data during control updates
331
-
332
- ## [1.0.2] - 2025-11-30
333
-
334
- ### Changed
335
- - Updated flow example description in Node-RED help panel for better clarity
336
- - Improved explanation of default behavior: reads by default, manually refreshable, and accepts commands
337
-
338
- ## [1.0.1] - 2025-11-30
339
-
340
- ### Added
341
- - **Node.js and Node-RED version requirements** in package.json engines field
342
- - Minimum Node.js: >=14.0.0
343
- - Minimum Node-RED: >=2.0.0
344
- - Addresses Flow Library scorecard requirements
345
- - **Comprehensive example flows** in Node-RED help panel
346
- - Basic monitoring flow (inject every 5 min)
347
- - Set preferences from flow (JSON payload with set_limit/set_time)
348
- - Home Assistant MQTT integration example
349
- - **Visual documentation** with screenshots
350
- - Node-RED flow examples showing monitoring, preferences, and preset buttons
351
- - MQTT integration flow example
352
- - Home Assistant device page with all entities
353
- - **Visual Examples section** in Node-RED help panel with embedded GitHub-hosted images
354
- - **Screenshots section** in README.md showing real-world usage
355
-
356
- ### Changed
357
- - Updated README.md with Screenshots section after Features
358
- - Updated .npmignore to exclude images/ folder (keeps npm package lightweight)
359
- - Updated .gitignore to exclude local documentation files
360
-
361
- ### Fixed
362
- - Flow Library scorecard now shows supported Node-RED and Node.js versions
363
- - Flow Library scorecard "Nodes have examples" requirement now satisfied
364
-
365
- ## [1.0.0] - 2025-11-30
366
-
367
- ### Added
368
- - Initial public release
369
- - **Octopus Energy GraphQL API integration**
370
- - Authentication via API key
371
- - Fetch planned charging dispatches (smart-charge and bump-charge slots)
372
- - Query vehicle charging preferences (target SOC and ready time)
373
- - Update charging preferences via GraphQL mutations
374
- - **Home Assistant MQTT auto-discovery**
375
- - Number entity: Target charge limit (50-100%)
376
- - Select entity: Ready time (04:00-11:00)
377
- - Button entity: Apply changes
378
- - Sensor entities: Confirmed settings, next charge time, total energy, slot times
379
- - Binary sensor: Charging now (ON/OFF)
380
- - Organized into Controls, Sensors, and Diagnostics categories
381
- - **Real-time charging slot detection**
382
- - Detects currently active charging slots
383
- - Calculates next charging start time
384
- - Provides individual slot start/end times (up to 3 slots)
385
- - Calculates overall charging window
386
- - Shows charge source (smart-charge vs bump-charge)
387
- - **Exponential backoff validation**
388
- - Smart retry mechanism when updating preferences
389
- - Prevents sensors from becoming "unavailable" during API updates
390
- - Validates changes at 15s, 30s, 60s, 120s intervals
391
- - **Comprehensive debugging**
392
- - Full API call tracking in msg.debug
393
- - Success/failure status for each operation
394
- - Detailed error messages
395
- - **Node-RED flow control**
396
- - Accept input messages to set preferences programmatically
397
- - Output payload with all charging data
398
- - 5-minute default refresh interval (configurable)
399
- - **Octopus Energy branding**
400
- - Professional pink theme (#E8146F)
401
- - Device branded as "Octopus Intelligent" in Home Assistant
402
- - Suggested "Energy" area in Home Assistant
403
- - **Unit test coverage**
404
- - Data processing tests (10 tests)
405
- - Timer management tests (10 tests)
406
- - Mock API responses for consistent testing
407
-
408
- ### Security
409
- - API key stored securely as Node-RED credential (not exposed in flows)
410
- - Account numbers sanitized in MQTT topics and entity IDs
411
-
412
- ### Documentation
413
- - Comprehensive README.md with:
414
- - Feature list and capabilities
415
- - Installation instructions (npm and palette manager)
416
- - Configuration guide
417
- - Home Assistant setup instructions
418
- - Node-RED usage examples
419
- - Home Assistant automation examples
420
- - Troubleshooting section
421
- - Support options (GitHub Star, Sponsor, PayPal donate)
422
- - MIT License
423
- - GitHub repository with issue tracking
424
-
425
- ## Release Notes
426
-
427
- ### Version Numbering
428
- This project follows [Semantic Versioning](https://semver.org/):
429
- - **MAJOR** version (X.0.0): Breaking changes
430
- - **MINOR** version (1.X.0): New features (backwards compatible)
431
- - **PATCH** version (1.0.X): Bug fixes (backwards compatible)
432
-
433
- ### Links
434
- - [npm Package](https://www.npmjs.com/package/node-red-contrib-octopus-intelligent)
435
- - [GitHub Repository](https://github.com/ASomerN/node-red-contrib-octopus-intelligent)
436
- - [Node-RED Flow Library](https://flows.nodered.org/node/node-red-contrib-octopus-intelligent)
437
- - [Issues & Bug Reports](https://github.com/ASomerN/node-red-contrib-octopus-intelligent/issues)
438
-
439
- ### Support
440
- - ⭐ [Star on GitHub](https://github.com/ASomerN/node-red-contrib-octopus-intelligent)
441
- - 💖 [Become a Sponsor](https://github.com/sponsors/ASomerN)
442
- - ☕ [Donate via PayPal](https://www.paypal.com/donate?hosted_button_id=A2B8ZFEJBE2S6)
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
+ ## [1.7.0] — 2026-10-16
9
+
10
+ ### Added
11
+ - **SmartFlex vehicle data.** If Octopus controls your car or charge point, `msg.payload` now includes its details every 30 minutes. It turns on by itself when the node finds the device.
12
+ - `vehicle_make`, `vehicle_model`, `vehicle_battery_kwh`, `charger_power_kw`
13
+ - `device_state`: what Octopus says the device is doing, for example `SMART_CONTROL_IN_PROGRESS`, `BOOSTING` or `LOST_CONNECTION`. The charging poll reads it, so it updates every refresh interval and always agrees with `boosting`.
14
+ - `device_alerts`: Octopus alert messages, as `[{ message, published_at }]`. Only the 10 newest are kept, newest first, and each message is cut to 250 characters.
15
+ - `charging_sessions`: your last 5 charging sessions, newest first, with `start`, `end`, `kwh_added`, `soc_change`, `soc_final`, `type`, `cost`, and `problems`. `last_session` is the latest finished one. `kwh_added` is in kWh, even if Octopus sends watt-hours.
16
+ - `last_session_kwh`, `last_session_soc_final`, `last_session_problem`: the latest finished session as single values.
17
+ - `smartflex_vehicle_error`: the last error as a short `KT-CT-xxxx: message`, or `null`. If Octopus returns only part of the data (for example the sessions fail), the node keeps what came back and the last values for the rest, and logs a warning.
18
+ - **SmartFlex inverter data (experimental, off by default).** Not yet verified on a real inverter. Tick **Inverter** in the node settings to read it every 5 minutes. It only runs if Octopus lists a SmartFlex inverter on your account. Fields: `inverter_make`, `inverter_model`, `solar_peak_kw`, `inverter_power_kw`, `inverter_connection_status`, `inverter_online`, `home_battery_power_kw`, `home_battery_soc`, `solar_power_kw`, `grid_power_kw`, `site_consumption_kw`, `site_export_kw` and `smartflex_inverter_error`.
19
+ - Home Assistant (MQTT), on the same Octopus Intelligent device. The vehicle entities are only published when Octopus lists a SmartFlex car or charge point on the account, and the inverter entities only when the Inverter option is ticked and Octopus lists an inverter. Otherwise they are removed, but only when Octopus lists devices and none is of that kind. If Octopus lists no devices at all, which can happen for a moment, they are left as they are. If you go back to an older version, these entities stay in Home Assistant and show Unavailable, not a problem. The broker still holds their retained discovery config, so Home Assistant will not delete them one by one. To remove them, clear their retained discovery topics on the broker, or delete the Octopus Intelligent device in Home Assistant (you then lose the names and areas you set).
20
+ - Each of these entities checks that its field is in the state message. A missing field reads Unavailable. Number sensors show unknown when the value is empty. The text sensors (Vehicle Make, Vehicle Model, Vehicle Device State, Inverter Make, Inverter Model and Inverter Connection Status) show Unavailable when the value is empty, not the word "None".
21
+ - Last Charge Session Energy (the session list and alerts are its attributes), Last Charge Session Final Charge and a Last Charge Session Problem binary sensor. Last Charge Session Energy has state class `total`, reset at the end of each session. Home Assistant keeps its statistics, and you can add it to the Energy dashboard. Last Charge Session Final Charge is a percentage with no battery device class, so low-battery alerts do not pick it up.
22
+ - Diagnostic sensors: Vehicle Make, Vehicle Model, Vehicle Battery Size, Charger Power, Vehicle Device State, SmartFlex Vehicle Error and its error binary sensor.
23
+ - Octopus lists a charge point as an electric vehicle. So a charge point gets the Boost Charge switch and the charging poll, like a car. Vehicle Make and Vehicle Model then show the charger's make and model.
24
+ - With the Inverter option ticked and an inverter listed: Solar Power, Home Battery Power, Home Battery Charge, Grid Power, Site Consumption, Site Export and Inverter Power. Diagnostic entities: Inverter Make, Inverter Model, Solar Peak Power, Inverter Connection Status, an Inverter Online binary sensor, SmartFlex Inverter Error and its error binary sensor. Unticking the option removes them.
25
+ - **Boost Charge.** New `set_boost` input (`true` starts a boost, `false` cancels it), a Boost Charge switch in Home Assistant (only when Octopus lists a car or charger it controls), and `boosting` and `boost_error` payload fields. A boost charges now, outside the Octopus plan. It is not the same as `set_smart_charging`. `charging_now` is now `true` during a boost too.
26
+ - Octopus can refuse a boost, for example when the car is unplugged. The node then logs the Octopus error, sends `boost_error` straight away and does not retry. That message has `msg.debug.trigger` set to `boost_failed`, with `request` (`BOOST` or `CANCEL`) and `error`, so a flow can tell it from a poll. A boost that works clears `boost_error`, and so does the first charging poll that reads the device state a minute or more later.
27
+ - If Octopus refuses the same choice 3 times in 10 minutes, the node ignores that choice for the next 10 minutes and logs one warning. This stops a flow that asks again after each refusal from calling Octopus all day. A request Octopus accepts ends the pause.
28
+ - Only `true` and `false` work. Any other `set_boost` value gives a node error and sends nothing. On MQTT, a payload other than `ON` or `OFF` logs a warning.
29
+ - The node sends one boost request at a time, at least 5 seconds apart, and only your last choice. A repeat of a choice Octopus has just accepted is dropped. After a failure, the same choice is sent again once the 5 seconds have passed. If Octopus does not answer a boost request within 75 seconds, the node gives up on it, sets `boost_error` and polls Octopus to check. Later requests are then sent as normal.
30
+ - When Octopus accepts a boost or a cancel, the node polls Octopus soon after. That poll waits if 3 planned-dispatch queries have already gone out in the last minute. After a refusal it does not poll, because nothing changed. If the answer is not clear, for example an error on the part Octopus reads back, the node leaves the switch as it was, sets no `boost_error` and polls to check.
31
+ - Octopus can take a moment to show the new state, so the switch shows what you asked for until Octopus agrees, for up to 2 minutes.
32
+ - `boosting` goes back to `null` if no charging poll has confirmed it for twice the refresh interval, for example during an Octopus outage. `charging_now` then follows the plan again, and the Boost Charge switch shows unknown.
33
+
34
+ ### Changed
35
+ - The Octopus Intelligent device in Home Assistant now shows the node's version as its software version. Before, it always showed 2.0.0. No entity changes.
36
+ - If Octopus lists more than one car or charger, the node now uses the one Octopus says is live. Before, it used the first in the list, which could be an old car you have replaced. If none is live, it still uses the first. Smart charging, boost, the charging poll and the vehicle entities all use this one device.
37
+ - Error text in the Node-RED log, the node status and `msg.payload` now shows what Octopus sent, including an API key it echoes back, so a wrong key can be seen and fixed. API keys and tokens are still hidden in what the node publishes to Home Assistant, which keeps it in its history.
38
+ - Retained MQTT messages on `submit_changes`, `refresh`, `set_smart_charging`, `set_charge_cap`, and `set_boost` are now ignored, with one warning per topic. The broker replays a retained message on every restart, so a retained command used to run again each time. Home Assistant does not retain these commands, so its buttons and switches work as before.
39
+
40
+ ### Documentation
41
+ - The example dashboards show the Boost Charge switch. The Home Assistant example adds SmartFlex vehicle and last session cards, and the Dashboard 2.0 example adds a Vehicle panel with recent charging sessions.
42
+ - The `set-preferences.json` example flow has Boost now and Cancel boost Inject nodes.
43
+ - Four new example flows. Each one links to your existing node and has a Read me note.
44
+ - `examples/boost-on-cheap-or-surplus.json`: starts a boost when the import rate is low or you export spare power, and cancels it when that ends.
45
+ - `examples/charging-and-error-alerts.json`: sends an alert when charging or a boost starts or stops, when an `*_error` field changes, and when Octopus posts a device alert.
46
+ - `examples/cheapest-window-planner.json`: finds the cheapest run of half hours for an appliance before a deadline, and sends a message when it starts.
47
+ - `examples/daily-charging-summary.json`: sends a morning summary of the last day's charging sessions, and a message when a session ends.
48
+ - The Dashboard 2.0 Category Errors panel now uses the real `*_error` field names. Before, it looked for `electricity_tariff_error` and `gas_tariff_error`, so it never showed rates errors. It also left out the dispatch errors. It now lists the dispatch, SmartFlex and boost errors too.
49
+ - The node help now says which errors get the quick charging poll retry (`KT-CT-4340` and `KT-CT-4339`). Other errors wait for the next normal poll.
50
+
51
+ ## [1.6.2] — not released on its own; included in 1.7.0
52
+
53
+ These fixes were prepared as 1.6.2 (and 1.6.3) and ship in 1.7.0. If you are upgrading from 1.6.1, read this section as well as 1.7.0.
54
+
55
+ ### Upgrading from 1.6.1
56
+ - The `*_error` fields now hold short text, not the raw error JSON from Octopus. A Kraken error reads `CODE: message`, for example `KT-CT-1111: Unauthorized`, or just the message when there is no code. An outage page or rate limit reads `HTTP 503` or `HTTP 429`. `intelligent_error` no longer starts with `Devices query failed` or `Dispatches query failed` when Octopus sends a code. If a flow runs `JSON.parse` on an `*_error` value, or looks for `"errorCode"` in it, change it to read the code at the start of the text. Home Assistant error sensors only check whether the field is empty, so they work as before.
57
+ - The node now sends an extra output message when a saving session, free electricity session or rate slot starts or ends (`msg.debug.trigger` is `active_fields_change`). This also happens on accounts without a car or charger. If a flow treats any message with `msg.debug` as a change to `charging_now`, check `msg.debug.trigger === 'charging_state_change'` instead.
58
+
59
+ ### Changed
60
+ - **Faster recovery when Octopus can't return the charging plan.** When the charging poll fails with `KT-CT-4340` (planned dispatches) or `KT-CT-4339` (charging preferences), the node tries the charging poll again after 30 seconds, 1 minute, and 2 minutes, then every 2 minutes, until it works or the next normal poll is due. A retry waits if 3 planned-dispatch queries have already gone out in the last minute, counting normal polls and the check 30 seconds before a slot. The known plan and charging timers stay in place while it retries.
61
+ - The Node-RED log now shows a warning for each failed charging poll or retry, for example `Charging poll failed: KT-CT-4340 Unable to fetch planned dispatches (retry 2 in 60s)`, and one line when it works again, for example `Charging poll recovered after 4m 30s`.
62
+ - `msg.payload.intelligent_error` and the node status now show a short error with the Octopus code, for example `KT-CT-4340: Unable to fetch planned dispatches`, instead of the raw error JSON. It is always under 255 characters. The node status still starts with `Error: `, as in 1.6.1, for example `Error: KT-CT-4340: Unable to fetch planned dispatches`.
63
+ - Every other `*_error` field now shows a short error too, for example `KT-CT-1111: Unauthorized`, or just the message when Octopus sends no code. Timeouts and auth failures are also cut to under 255 characters. Before, a long error could be rejected by Home Assistant, which does not accept a state over 255 characters.
64
+
65
+ ### Fixed
66
+ - If Octopus can't return the charging preferences (`KT-CT-4339`), the node keeps the last confirmed target and ready-by time and still updates the charging slots. Before, the whole charging poll failed.
67
+ - Home Assistant commands could run twice after a partial redeploy. The node now removes its MQTT command subscriptions and releases the MQTT broker when it is closed.
68
+ - **Polling could stop for good after one request with no answer.** Requests to Octopus had no time limit, so a request that never answered blocked every later poll until Node-RED restarted, with no log line. Every request now gives up if Octopus sends nothing for 30 seconds. If a poll is still running after 10 minutes, the next poll starts anyway and the Node-RED log shows a warning. The old poll stops after its current request. Anything the old poll had already read is read again by the new one.
69
+ - The npm update check also gives up after 30 seconds with no answer.
70
+ - A poll that finished after the node was closed or redeployed could still restart charging timers. It now stops instead.
71
+ - Redeploying the node in the first second after it started could leave an extra poll loop running. Stopping the node now cancels it.
72
+ - A reply from Octopus that stopped part way, or arrived very slowly, could hold up every poll for 10 minutes. A request now fails as soon as the connection closes early, and gives up after 30 seconds in total.
73
+ - An outage page or rate limit from Octopus now shows as `HTTP 503` or `HTTP 429` in the log and the `_error` fields. Before, it showed a parse error or `Response missing data`.
74
+ - After you changed the target, the ready-by time or Charge Cap, a poll that was already running could put the old values back in Home Assistant until the next charging poll. The new values now stay.
75
+ - Redeploying the node during a poll no longer lets the old node send the rest of that poll's requests to Octopus.
76
+ - Pressing Submit twice quickly, or while a change was still being checked, no longer runs two sets of checks. Only the latest change is checked.
77
+ - If a change to the target, ready-by time or Charge Cap got no answer from Octopus, for example after a time-out, the node reported it as failed, even if Octopus had made it. The node now shows the change as unconfirmed and polls straight away to read the real values. If that poll shows the change was not made, the status turns red (`Update Failed` or `Charge Cap update failed`) and the log shows a warning. Only a time-out, a connection that closed after the change was sent, or an HTTP 5xx error counts as no answer. A change that could not reach Octopus, for example after a DNS or connection error, or that got an HTTP 4xx error or a reply the node could not read, still fails straight away with an error, as in 1.6.1. The Smart Charging switch now follows the same rule: a change with no answer is checked with Octopus after 15 seconds, 30 seconds, 1 minute and 2 minutes, instead of being reported as failed.
78
+ - An Octopus API key or login token is now hidden in what the node publishes to Home Assistant. Octopus can repeat part of a request in an error message, so a key could have been shown there. A login token that follows a dotted word is hidden in full. (1.7.0 shows the key in the Node-RED log, the node status and `msg.payload`, so a wrong key can be seen and fixed. See 1.7.0 Changed.)
79
+ - If the node could not log in to Octopus for a poll, sensors that update hourly stayed empty or out of date for up to an hour, and the update check failed for a day. The update check now runs anyway, as it does not use Octopus. The other polls try again after 1 minute, then 2, 4 and 8 minutes, and then every 10 minutes until the login works. If Octopus says how long to wait (a rate limit with `Retry-After`), the node waits at least that long, up to 10 minutes.
80
+ - If the system clock was set back, for example after starting with a clock that was ahead, polls stopped until the clock caught up again, and charging poll retries were held back. Polls now carry on straight away. A small correction of under a minute, for example from NTP, does not make every poll run again.
81
+ - If Octopus briefly returned no devices when the node started, charging polls stayed off until the node was restarted. The node now checks again after 30 seconds, 1 minute, 2 minutes and then every 5 minutes, up to 6 times. When it finds the car or charger, charging polls start.
82
+ - During an Octopus outage where requests got no answer, one round of polls could take up to 10 minutes, and refreshes and retries had to wait. After the first request that times out, loses its connection or gets an HTTP 5xx error, the node now leaves the other polls for the next round.
83
+ - After a new target was confirmed, a charging poll that had started before the change could put the old target back, for example "Confirmed: 90%" instead of 50%, until the next charging poll. The same could happen to the ready-by time and Charge Cap. Such a poll now keeps only its charging slots, and the node reads the settings again straight away. This also covers a change confirmed after the charging poll but before the rest of that round of polls had finished, and a target or ready-by time picked in Home Assistant but not applied yet, which used to jump back at the end of that round.
84
+ - A node that kept failing its start-up check with Octopus, for example with a wrong account number, used a little more memory every 5 minutes until it was restarted. It no longer does.
85
+ - A very large reply from Octopus or the npm registry, such as an error page sent over and over, is now cut off at 2 MB and the request fails. Before, the node kept all of it in memory until the 30 second time limit.
86
+ - If Octopus or the npm registry sent a reply that was not the expected JSON object, for example `null`, the `_error` fields showed a code error such as `Cannot read properties of null`. They now show `Unexpected response shape`.
87
+ - If the node could not read the car or charger when it started, the Smart Charging and Charge Cap switches and target changes failed with `Device ID not available` until a charging poll worked. The node now uses the device found by its start-up check.
88
+ - If the node could not log in to Octopus during normal polling, the Node-RED log showed nothing. It now shows one warning when the login starts failing and one line when it works again.
89
+ - On an account with no car or charger, the node status stayed green while polls failed. It now shows the first error, in red when every Octopus poll failed and in yellow when only some did. Accounts with a car or charger show the charging status as before.
90
+ - A number field could show `NaN` or `Infinity` in `msg.payload`, and `unknown` in Home Assistant, when Octopus sent a value that was not a number. Rates, standing charges, consumption, the account balance, Home Mini readings, the rate summary, dispatch energy and Wheel of Fortune spins now show no value (`null`) instead. A daily consumption reading that Octopus has not filled in yet is skipped, so consumption no longer shows `NaN`.
91
+ - `set_timezone` accepted any text, from a flow or from Home Assistant. A wrong name was saved, and every display time then showed the raw UTC text. The node now checks the name and writes an error to the Node-RED log if it does not know it, or if it is over 64 characters. The timezone is then not changed.
92
+ - A very long text value from Octopus, such as a tariff code or a time it could not read, could stop a Home Assistant sensor updating, because Home Assistant does not accept a state over 255 characters. Such text is now cut to 254 characters.
93
+ - A bad `set_limit` or `set_time` value is now shown cut to 40 characters in the error and the node status. A very long value used to fill the log. A value a flow cannot turn into text, such as a Symbol, now gives the usual error instead of a code error.
94
+ - If Octopus could not return the smart charging state (for example `KT-CT-4360`) when the node started, the start-up check failed and nothing was polled at all, not even rates or consumption, until it worked. The check now asks again without the smart charging state, finds the car or charger, and starts polling. The log shows one warning.
95
+ - A failed poll of rates, consumption, the account and the other data, or a failed update check, showed only in its `_error` field. The Node-RED log now shows one warning when a poll starts failing, for example `account poll failed: HTTP 502`, and one line when it works again.
96
+ - A very long error from Octopus could fill the Node-RED log with one line of about 8,000 characters, and the end of the line, such as `Retrying in 30s.`, was lost. Error text in a log line is now cut to 300 characters, and a log line to 500, keeping its end.
97
+
98
+ ### Fixed (prepared as 1.6.3)
99
+ - The Electricity Export Rate Error sensors were always empty, because export rate errors were only saved in `applicable_rates_export_error`. They are now saved in `electricity_export_rate_error` too, so the sensors show them.
100
+ - The Octoplus poll no longer asks Octopus for `isOctoplusEnrolled`, which Octopus has marked for removal. If Octopus removed it, the whole Octoplus poll would fail. `octoplus_enrolled` now comes from the enrolment status.
101
+ - A refresh, a plan-change re-poll, or the check after a change you sent could be skipped if it was asked for while that data was already being polled. It then waited for the next normal poll, up to the refresh interval. It now runs straight after the current poll.
102
+ - The node now publishes `charging_now` on the first poll after it starts. Before, a restart that spanned the end of a charging slot could leave Home Assistant showing Charging Now as on until the next slot.
103
+ - The node no longer creates timers or sends messages after it is closed or redeployed, even when a request to Octopus answers late.
104
+ - The check 30 seconds before a slot now handles an Octopus error such as `KT-CT-4340`. It logs a warning and starts the slot on time from the known plan. Before, it did nothing and the slot started up to 10 seconds late. If that check is still waiting for Octopus when the slot starts, the slot now starts on time anyway. Before, a slow answer could start it a few seconds late.
105
+ - `msg.payload.charging_now` and the JSON state topic now match the Charging Now sensor on every message. Before, messages from other polls (such as Home Mini) could carry the old value until the next charging poll.
106
+ - The Smart Charging switch now follows changes made in the Octopus app. The charging poll reads the smart charging state and updates the switch when it changes. After a slow start, the switch no longer stays unknown. If Octopus can't return the smart charging state, for example with `KT-CT-4360`, the switch keeps its last state and the rest of the charging poll still works. The log shows one warning until the state is back.
107
+ - The node no longer makes a second, untracked MQTT subscription to each command topic.
108
+ - Saving session, free electricity, and current rate sensors now change at the start and end time. Before, they could be wrong until the next poll of that data, up to an hour. The node sends an extra output message when these change (`msg.debug.trigger` is `active_fields_change`), so on a half-hourly tariff there is one more message every 30 minutes.
109
+ - `next_kwh` no longer shows `NaN` when Octopus sends an energy value that is not a number. It shows `0`, as `total_energy` already did.
110
+
111
+ ### Documentation
112
+ - Removed `msg.debug` from the poll output docs. Poll messages carry only `msg.payload`. The extra message sent when `charging_now` changes still carries `msg.debug`.
113
+ - Documented refresh from a flow and the checks on command values, including the `set_timezone` check.
114
+ - Corrected the polling description. Intervals, run order, clock alignment, and which groups poll are now accurate.
115
+ - Corrected timezone notes. Persistence needs a persistent context store, and daily consumption uses the editor Timezone field.
116
+ - Listed the rate band, rate summary, previous and next rate, saving session, and update entities. Marked the always-empty Wheel of Fortune and error sensors.
117
+ - Fixed the property names and the Inject nodes in the example flows, and in the node help.
118
+ - Replaced the stale field count, the old changelog copy, and the "covers every entity" wording for the dashboard.
119
+
120
+ ## [1.6.1] — 2026-10-03
121
+
122
+ First public 1.6 release. 1.6.0 was only distributed as a preview build; everything in it is included here.
123
+
124
+ ### Added
125
+ - **Charge Cap** — new Home Assistant switch, `set_charge_cap` input and `charge_cap` payload field (limit smart charging to off-peak rates only, as in the Octopus app).
126
+ - One input message can now carry several commands; each is applied independently.
127
+
128
+ **Dashboard 2.0 example flow**
129
+ - `examples/node-red-dashboard-flow.json` — complete importable Dashboard 2.0 flow with 34 widgets across 6 pages (Controls, Status, Tariff, Optimization, Account, Diagnostics).
130
+ - Two annotated **sample function nodes** embedded in the flow (`find-cheapest-window`, `is-cheapest-now`) demonstrating user-side derivation patterns over the `applicable_rates` array. Marked as user-modifiable example code, not part of the node's published payload — keeping with the "expose raw data, no inference" principle.
131
+ - Writable controls (target limit slider, ready-by dropdown, smart-charging switch, Charge Cap switch, refresh button, timezone override) routed back into the node input.
132
+
133
+ ### Changed
134
+ - Ready-by time accepts any half-hour slot from 00:00 to 23:30, matching the Octopus app (was 04:00–11:00).
135
+ - Target charge accepts 5–100%, matching the Octopus app (was 50–100). Values still round to the nearest 5. The Home Assistant slider and the Dashboard 2.0 example go down to 5%.
136
+ - Invalid values are now rejected with an error and nothing is sent to Octopus, including `set_limit: 0` and empty strings. Previously an invalid time was silently replaced with 08:00 and sent. Partly numeric limits such as `"8O"` or `"85%"` are rejected rather than truncated. `null` values are ignored as before.
137
+ - Dashboard 2.0 example flow and HA dashboard example updated for 1.6: the ready-by dropdown offers all 48 half-hour times, and both include the Charge Cap switch.
138
+
139
+ ### Fixed
140
+ - Ready-by times after 11:00 were rejected (#3).
141
+ - Target charge values below 50% were silently raised to 50% (#3).
142
+ - **Day/Night and EV Peak/Off-Peak rate sensors stuck at "unavailable"** —
143
+ `electricity_day_rate`, `electricity_night_rate`, `electricity_ev_peak_rate`,
144
+ `electricity_ev_off_peak_rate` were published with `entity_category: config`, which
145
+ is invalid for read-only sensors (same issue fixed for tariff codes in v1.3.0; missed
146
+ on these four when added in v1.5.0). On some HA Core versions this now causes outright
147
+ entity-registration failure rather than just a stuck state. Removed the category — no
148
+ entity ID changes, not a breaking change. On upgrade these four sensors move from the
149
+ Configuration section to the Sensors section of the Home Assistant device page. Sensor definitions also extracted to
150
+ `lib/sensor-definitions.js` with regression coverage asserting no read-only sensor
151
+ carries `entity_category: config`.
152
+ - **Node stopped polling after a transient Octopus error at startup** — if Octopus's API returned a
153
+ temporary error while the node was starting (seen live as `KT-CT-4360` on device status), the node
154
+ gave up on product discovery and never started polling; a manual refresh then stayed on
155
+ "Manual refresh..." until Node-RED restarted. Discovery now retries (30 s, 1 min, 2 min, then every
156
+ 5 min) and shows "Discovery failed — retrying in …" while it does, and a failure on the device
157
+ status field alone no longer blocks discovery.
158
+ - **Slot sensors could show an out-of-date charging plan** — the check made 30 s before each slot
159
+ picks up a re-planned schedule and `charging_now` follows it, but the slot and window sensors kept
160
+ the old plan until the next scheduled poll. The node now polls immediately when that check finds
161
+ the plan has changed.
162
+ - **One failing field could stop all charging updates** — if Octopus returned an error for the Charge Cap
163
+ setting alone, the whole charging poll failed and slot sensors stopped updating. Charge Cap is now read
164
+ separately, so slots, limit and ready-by time keep updating and the switch keeps its last known state.
165
+
166
+ ### Backwards compatibility
167
+ - No MQTT topic, `unique_id` or entity ID changes from npm 1.5.0 or the 1.6.0 preview. New since 1.5.0: the Charge Cap switch, its `set_charge_cap` command topic, and 48 options on the Ready Time select. Pinned by `__tests__/discovery-snapshot.test.js`.
168
+
169
+ ## [1.5.0] — 2026-06-13
170
+
171
+ Schedule visibility, tariff rate bands, and proactive update notification.
172
+
173
+ ### Added — Schedule visibility (import & export)
174
+ - 24h schedule stats: `applicable_rates_{min,max,median,avg}_pence` and `electricity_export_rate_*` equivalents. Min/max/median/avg of the next 24h's half-hourly rate schedule.
175
+ - The full `applicable_rates` / `electricity_export_rate` slot arrays now exposed as MQTT entity attributes on the existing `*_count` sensors, accessible via `state_attr(...)` in HA templates.
176
+
177
+ ### Added — Tariff rate bands
178
+ - `electricity_day_rate`, `electricity_night_rate`, `electricity_ev_peak_rate`, `electricity_ev_off_peak_rate` — raw tariff-defined rate bands from the Kraken `DayNightTariff` / `FourRateEvTariff` types. Null on tariffs that don't expose banding (e.g. `HalfHourlyTariff` users see nulls; Economy 7 / FourRateEv users see populated values).
179
+
180
+ ### Added — Update notification
181
+ - HA MQTT Update entity (`update.octopus_intelligent_node_update`) surfacing newer-version availability in Home Assistant's Settings → Updates panel. Requires HA ≥ 2022.4.
182
+ - Node-RED debug log emits `node.warn` once per detected new version, with install instructions.
183
+ - New payload fields: `installed_version`, `latest_version`, `update_available`, `update_check_at`, `update_check_error`. Check runs once per 24h via the unified scheduler.
184
+
185
+ ### Added — Promotion to MQTT entities (closing v1.3.0 gaps)
186
+ - 8 previously payload-only fields promoted to MQTT entities: `applicable_rates_prev_pence/_gbp/_to`, `applicable_rates_next_pence/_gbp/_from`, `electricity_export_rate_prev_gbp`, `electricity_export_rate_next_gbp`.
187
+
188
+ ### Added — Per-category error binary sensors
189
+ - 15 new binary_sensors with `device_class: problem`, one per category. `OFF` when healthy / `ON` when the corresponding `<category>_error` payload field is set. Existing string error sensors retained — no breakage for users referencing them in automations.
190
+
191
+ ### Fixed
192
+ - Example dashboard: Home Mini live demand gauge now goes down to `-10 kW` (was `min: 0`), correctly displaying solar-export demand.
193
+
194
+ ### Backwards compatibility
195
+ - All existing payload field names, MQTT topics, HA entity unique_ids, input commands, and node config fields are preserved. v1.4.0 → v1.5.0 is a zero-config upgrade.
196
+
197
+ ## [1.4.0] — 2026-05-29
198
+
199
+ Single poll loop. The V1 `setInterval(fetchData)` intelligent loop and the V2 `createScheduler(pollDueCategories)` category loop are merged into one clock-aligned scheduler with one auth and one emit per tick. No HA-side changes.
200
+
201
+ ### Fixed
202
+ - **Intermittent `KT-CT-1199` "Too many requests"** on `flexPlannedDispatches` — the standalone `flex_planned_dispatches` V2 category queried the same endpoint as the V1 intelligent poll, and the two unsynchronised loops phase-drifted into bursts that tripped Kraken's burst limit. The intelligent poll now owns `flexPlannedDispatches`; the standalone category is removed.
203
+ - **Whole payload was nuked on any single-category error**, and `intelligent_error` was never set. Every category now follows one error policy: record `<category>_error`, keep last-good data, retry next interval. No permanent disable.
204
+ - **Slow polls could overlap a tick** — added an in-flight guard around the scheduler.
205
+
206
+ ### Changed (internal architecture; no HA-side breakage)
207
+ - Every category exposes `async poll(token) → partialPayload`. Simple categories use a `simplePoll` factory; the intelligent poll is a bespoke category that owns both the devices and dispatch queries.
208
+ - Tick / poll / error-merge logic moved into `lib/poll-tick.js` and `lib/scheduler.js` for unit-test coverage.
209
+ - Manual refresh, MQTT refresh, and post-mutation validation re-polls all go through the same scheduler / intelligent-poll path.
210
+
211
+ ### Unchanged
212
+ - All payload field names, MQTT topics, `unique_id`s, HA entity IDs, input commands, and node config fields.
213
+
214
+ ## [1.3.3] — 2026-05-22
215
+
216
+ ### Fixed
217
+ - **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.
218
+ - **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.
219
+ - **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.
220
+ - **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.
221
+
222
+ ### Added
223
+ - `saving_session_window_active` (binary sensor) — true when an upcoming session window is currently happening, regardless of whether you joined.
224
+ - `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.
225
+
226
+ ### Changed (HA-side breaking)
227
+ - `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.
228
+
229
+ ## [1.3.2] — 2026-05-14
230
+
231
+ 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.
232
+
233
+ ### Fixed
234
+ - `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.
235
+ - `lib/categories/gas.js` — same treatment for `tariff.unitRate` and `tariff.standingCharge`.
236
+ - `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.
237
+
238
+ ### Tests
239
+ - Added string-input regression tests for each coerced field, asserting `typeof === 'number'`. 4 new tests, 237 total (was 233).
240
+
241
+ ## [1.3.1] — 2026-05-14
242
+
243
+ Critical hotfix for v1.3.0. Users on 1.3.0 should upgrade immediately.
244
+
245
+ ### Fixed
246
+ - **Intelligent category crash on numeric string inputs** — `flexPlannedDispatches.energyAddedKwh` is returned by the live Kraken API as a string. The intelligent category's reduce accumulator concatenated strings instead of summing, then called `.toFixed()` on the resulting string, raising `TypeError: totalEnergy.toFixed is not a function`. Whole intelligent payload section fell back to `defaultData` (null slot times, `total_energy: 0`, `next_kwh: "0"`), which surfaced in Home Assistant as "Error updating entity" for every intelligent sensor. Fixed by coercing `energyAddedKwh` via `parseFloat()` before arithmetic and formatting in `lib/categories/intelligent.js`, matching the pattern already used in `lib/categories/flex-planned-dispatches.js`. Added regression tests covering both positive and negative (export dispatch) string inputs.
247
+ - `next_kwh` now consistently formats with two decimal places (e.g. `"5.50"`, `"15.20"`) per the documented contract in README, HTML help, and `test-mocks.js`. The v1.3.0 path stripped trailing zeros via `String(parseFloat(...))` — that branch is unreachable now because it always crashed before reaching it, but the format is corrected for completeness.
248
+
249
+ ## [1.3.0] — 2026-05-12
250
+
251
+ Major additive release covering the full Octopus Energy consumer read surface. No breaking changes to v1.2.x payload fields, entity IDs, MQTT topics, input commands, or node config fields. All v1.2.x automations and dashboards continue to work unchanged.
252
+
253
+ ### Added — Electricity (import)
254
+ - `electricity_standing_charge` — daily standing charge (p/day)
255
+ - `electricity_unit_rate` — fixed unit rate (p/kWh); `null` on half-hourly tariffs
256
+ - `electricity_tariff_code`, `electricity_valid_from`, `electricity_valid_to`
257
+ - `electricity_consumption_kwh` — previous day import consumption
258
+ - `electricity_consumption_from`, `electricity_consumption_to` — period boundaries
259
+ - `applicable_rates`, `applicable_rates_count` — full 48-slot half-hourly schedule
260
+ - `applicable_rates_current_pence`, `applicable_rates_current_gbp` — live rate (use these on half-hourly tariffs)
261
+ - `applicable_rates_prev_pence/_gbp/_to`, `applicable_rates_next_pence/_gbp/_from` — adjacent slot rates and transition timestamps (payload-only; not currently exposed as MQTT entities — see README)
262
+
263
+ ### Added — Electricity (export)
264
+ - `electricity_export_standing_charge` — typically `0` for Agile Outgoing
265
+ - `electricity_export_unit_rate` — fixed; `null` on half-hourly export tariffs
266
+ - `electricity_export_tariff_code` (e.g. `AGILE-OUTGOING-19-05-13`), `electricity_export_valid_from`, `electricity_export_valid_to`
267
+ - `electricity_export_consumption_kwh`, `_from`, `_to` — previous day export from the export meter
268
+ - `electricity_export_rate`, `electricity_export_rate_count` — full 48-slot half-hourly export schedule
269
+ - `electricity_export_rate_current_pence/_gbp` — live export rate
270
+ - `electricity_export_rate_prev_pence/_to`, `electricity_export_rate_next_pence/_from` — adjacent export slot rates
271
+
272
+ ### Added — Gas
273
+ - `gas_standing_charge`, `gas_unit_rate`, `gas_tariff_code`, `gas_valid_from`, `gas_valid_to`
274
+ - `gas_consumption_kwh`, `gas_consumption_from`, `gas_consumption_to`
275
+
276
+ ### Added — Home Mini
277
+ - `mini_demand_kw` (kW, numeric) — real-time grid demand
278
+ - `mini_consumption_delta_kwh` (kWh, numeric) — half-hour period consumption
279
+ - `mini_read_at` — timestamp of most recent telemetry
280
+ - Opt-in via "Enable Home Mini" checkbox in node config
281
+
282
+ ### Added — Rewards
283
+ - `saving_session_available` (binary), `saving_session_start`, `saving_session_end`, `saving_session_joined`
284
+ - `free_electricity_active` (binary), `free_electricity_available` (binary), `free_electricity_start`, `free_electricity_end`
285
+ - `wheel_of_fortune_electricity_spins`, `wheel_of_fortune_gas_spins` — opt-in via node config checkbox
286
+ - `octoplus_enrolled` (binary sensor), `octoplus_enrollment_status` (string), `octoplus_loyalty_points_user` (binary sensor)
287
+
288
+ ### Added — Account & dispatches
289
+ - `account_balance_pounds`, `account_balance_pence`
290
+ - `completed_dispatches` (array), `completed_dispatches_count` — completed intelligent dispatch history
291
+ - `flex_planned_dispatches` (array), `flex_planned_dispatches_count` — upcoming flex dispatches (replaces deprecated `plannedDispatches`)
292
+
293
+ ### Added — Infrastructure
294
+ - **Account discovery** — automatic product detection at startup; categories auto-enable based on registered products and discover both import and export meter points by `direction`, not array position
295
+ - **Per-category poll intervals** — configurable in node editor for each data source
296
+ - **1-second clock-aligned category scheduler** — independent polling; one slow category doesn't block others
297
+
298
+ ### Changed
299
+ - **Octopus `wheelOfFortuneSpins` migrated to `wheelOfFortuneSpinsAllowed`** on `api.backend.octopus.energy` — the old field was deprecated and scheduled for removal 2026-04-20
300
+ - **Octopus `savingSessions` migrated to `api.backend.octopus.energy`** endpoint — the field was removed from the main endpoint
301
+ - **`octoplus_enrolled` and `octoplus_loyalty_points_user` now publish as `binary_sensor` instead of `sensor`** — these are boolean values and HA's sensor domain rejects raw booleans. **HA-side breaking change for users referencing the old `sensor.*` entity IDs**: update automations and dashboards to use `binary_sensor.*`. Payload field names (`msg.payload.octoplus_enrolled`, `msg.payload.octoplus_loyalty_points_user`) are unchanged.
302
+ - **`entity_category: config` removed** from read-only tariff/validity sensors (`electricity_unit_rate`, `electricity_tariff_code`, `electricity_valid_from/to`, `gas_*`, `electricity_export_*`, `saving_session_start/end`, `free_electricity_start/end`, `octoplus_enrollment_status`). These now appear in the main device entity list rather than a separate Configuration section. HA's `entity_category: config` is intended for user-configurable entities (switches, numbers, selects) — applying it to read-only sensors caused state to stick at "unavailable" on some installs.
303
+
304
+ ### Fixed
305
+ - **Import/export meter point selection** — discovery now selects meter points by the `direction` field (`IMPORT` or `EXPORT`), not array position. Earlier dev builds on accounts with both meters could surface export data as import (live "current rate" showing the export Agile rate instead of the import tariff). No stable v1.x release was affected; caught and fixed before v1.3.0 ship.
306
+ - **MQTT transport headers** — `lib/graphql.js` now sends `User-Agent: node-red-contrib-octopus-intelligent/<version>` on every request. Without it, `api.backend.octopus.energy` returns 403 at the edge — which previously surfaced as "WoF returns HTML" and silently broken saving sessions.
307
+ - **MQTT auth format** — uses raw JWT in the Authorization header (no `JWT ` prefix). Main endpoint accepts both; backend endpoint sub-resolvers require the raw form.
308
+ - **Saving sessions schema migration** — removed deprecated `octopoints` field from `SavingSessionsAccountType` query (Octopus moved loyalty points to the Octoplus query).
309
+ - **Gas tariff query fragments** — `GasTariffType` is an object type, not a union — removed inline fragments that caused "Fragment cannot be spread here" errors.
310
+
311
+ ### Unchanged (no breaking changes)
312
+ - All v1.2.x payload field names in `msg.payload`
313
+ - All v1.2.x MQTT topics, `unique_id` values, and HA entity IDs (except the Octoplus domain change noted above)
314
+ - All v1.2.x input commands: `set_limit`, `set_time`, `set_smart_charging`, `set_timezone`
315
+ - All v1.2.x node config fields: `accountNumber`, `apiKey`, `broker`, `enableMqtt`, `name`, `refreshInterval`, `timezoneOverride`
316
+ - Intelligent Octopus Go charging schedule, smart charging toggle, charging preferences
317
+
318
+ ---
319
+
320
+ ## [1.2.1] — 2026-04-29
321
+
322
+ ### Fixed
323
+ - **Deprecated API migration** — moved smart-charging verification from the deprecated `registeredKrakenflexDevice` query to the current `devices` query
324
+ - **Mutation migration** — `setVehicleChargePreferences` (deprecated) replaced with `setDevicePreferences` using the 7-day schedule input
325
+ - **Startup device fetch** — uses the current `devices` query instead of deprecated `registeredKrakenflexDevice`
326
+
327
+ ### Unchanged
328
+ - All v1.2.0 payload fields, MQTT topics, and entity IDs preserved
329
+
330
+ ---
331
+
332
+ ## [1.2.0] - 2026-04-26
333
+
334
+ ### Added
335
+ - **Smart Charging Toggle** — suspend or unsuspend Octopus intelligent charging from Node-RED or Home Assistant
336
+ - `msg.payload = { set_smart_charging: true }` — enable (unsuspend)
337
+ - `msg.payload = { set_smart_charging: false }` — disable (suspend)
338
+ - **HA MQTT Switch** — "Smart Charging" switch entity in Home Assistant (auto-discovered)
339
+ - **`smart_charging` payload field** — `true` = active, `false` = suspended, `null` = unknown (startup fetch pending or failed)
340
+ - **Device ID startup fetch** — `krakenflexDeviceId` fetched once at startup via `registeredKrakenflexDevice` query; cached permanently
341
+
342
+ ### Technical
343
+ - Mirrors `setPreferences` pattern: auth → mutation → optimistic update → exponential backoff verification (15s/30s/60s/120s)
344
+ - Verification re-fetches `registeredKrakenflexDevice.suspended` to confirm state change
345
+ - Zero new npm dependencies
346
+
347
+ ---
348
+
349
+ ## [1.1.1] - 2026-04-26
350
+
351
+ ### Security
352
+ - **Removed `axios` dependency** — replaced with Node.js built-in `https` module; eliminates 13 transitive packages and all associated supply chain risk
353
+ - **Removed test/mock files from npm package** — `__tests__/` and `test-mocks.js` no longer published; removes 139 kB of dev artefacts from end-user installs
354
+ - **Removed images from npm package** — 364 kB of images no longer bundled; README images now reference GitHub raw URLs and render correctly on npmjs.com
355
+
356
+ ### Changed
357
+ - Package size reduced from 369 kB → 27 kB (93% reduction)
358
+ - Zero production dependencies (was: `axios ^1.6.0`)
359
+
360
+ ---
361
+
362
+ ## [1.1.0] - 2026-04-24
363
+
364
+ ### Added
365
+ - **Locale Timestamps** — new `*_locale` fields in every payload, always in server auto-detected timezone
366
+ - `slot1_start_locale`, `slot1_end_locale`, `slot2_start_locale`, `slot2_end_locale`
367
+ - `slot3_start_locale`, `slot3_end_locale`, `window_start_locale`, `window_end_locale`
368
+ - `next_start_locale`
369
+ - **Timezone Metadata** — `timezone_detected` (server auto-detect) and `timezone_applied` (active TZ for display fields)
370
+ - **HA Timezone Select Entity** — `select.octopus_timezone` with 15 curated IANA timezones covering all Octopus operating countries (UK, AU, DE, ES, NZ, US)
371
+ - Selection persists across Node-RED restarts via node context storage
372
+ - State republished to HA on Node-RED startup
373
+ - **`set_timezone` Input Command** — `msg.payload = { set_timezone: "Europe/London" }`, same pattern as `set_limit`/`set_time`
374
+ - **`timezoneOverride` Node Config Field** — optional IANA timezone in node editor, leave blank for auto-detect
375
+ - **Timezone Diagnostic Sensors** — `sensor.octopus_timezone_detected` and `sensor.octopus_timezone_applied`
376
+
377
+ ### Changed
378
+ - **Display timestamp fields now output resolved timezone** instead of raw UTC
379
+ - Affected fields: `slot1_start`, `slot1_end`, `slot2_start`, `slot2_end`, `slot3_start`, `slot3_end`, `window_start`, `window_end`, `next_start`
380
+ - Resolution order: HA-persisted selection → `timezoneOverride` config → server auto-detected
381
+ - **Raw fields (`*_raw`) remain unchanged** — always exact UTC strings from the API
382
+
383
+ ### Technical
384
+ - Zero new npm dependencies — native `Intl.DateTimeFormat` API (Node 14 compatible)
385
+ - `convertToTimezone(dateStr, tz)` — handles DST correctly, falls back to original string on error
386
+ - `resolveTimezone(node)` — reads node context storage, config field, or server auto-detect
387
+
388
+ ## [1.0.5] - 2025-12-31
389
+
390
+ ### Fixed
391
+ - **README Documentation** - Removed misleading "Octopus Energy branded device cards" claim
392
+ - Changed to accurate description: "Clean Organization" and "Professional Layout"
393
+ - No actual Octopus Energy branding exists in Home Assistant device cards
394
+ - Avoids potential trademark/copyright concerns
395
+
396
+ ## [1.0.4] - 2025-12-11
397
+
398
+ ### Added
399
+ - **Manual Refresh Button (MQTT)** - "Octopus Refresh API" button in Home Assistant
400
+ - Hardcoded 30-second rate limiting to prevent API spam
401
+ - Shows warning in Node-RED when rate limited
402
+ - Publishes refresh cooldown state to MQTT
403
+ - **Refresh Available At Sensor** - Diagnostic timestamp sensor
404
+ - Shows ISO timestamp when manual refresh becomes available
405
+ - Displays as countdown in Home Assistant ("in 25 seconds")
406
+ - Automatically clears to `null` after 30 seconds
407
+ - Leverages Home Assistant's native timestamp handling
408
+ - **Next Poll Time Sensors** - Shows when next automatic poll will occur
409
+ - `sensor.octopus_next_poll_time` - Main sensor (timestamp class)
410
+ - `sensor.octopus_next_poll_time_raw` - Diagnostic raw timestamp
411
+ - Updates after each successful poll
412
+ - **API Complexity Tracking** - Monitor API usage against 50,000 hourly limit
413
+ - `sensor.octopus_api_requests_hour` - Count of requests (last 60 min)
414
+ - `sensor.octopus_api_complexity_hour` - Total complexity used
415
+ - `sensor.octopus_api_complexity_usage` - Percentage of limit used
416
+ - Estimated complexity: Regular poll (300), Mutation (250), Pre-validation (200)
417
+ - All API complexity sensors in Diagnostics section
418
+ - **Enhanced Debug Output** - `msg.debug` now includes:
419
+ - `responseHeaders` - Full HTTP response headers from API
420
+ - `extensions` - GraphQL extensions field (if present)
421
+ - `api_usage` - Comprehensive API usage metrics per request
422
+ - **Comprehensive Test Coverage** - Added 5 new tests
423
+ - Tests for MQTT refresh button rate limiting
424
+ - Tests for countdown expiry behavior
425
+ - Validates countdown doesn't go negative
426
+ - Tests timer cleanup and MQTT message structure
427
+
428
+ ### Changed
429
+ - **Rate Limiting Strategy** - Different behavior for MQTT vs Node-RED
430
+ - MQTT Button: Hardcoded 30-second cooldown (enforced)
431
+ - Node-RED Input: No rate limiting (programmers control this)
432
+ - Timestamp-based cooldown (not seconds counter)
433
+ - **State Output** - Node-RED now outputs state on every poll
434
+ - Previously only output on changes
435
+ - Now outputs full `statusPayload` every poll cycle
436
+ - Better for automations and monitoring
437
+ - **Global Setter** - Updated `NodeRed_Global_Setter.js` with new fields:
438
+ - `octopus_next_poll`
439
+ - `octopus_refresh_available_at`
440
+ - `octopus_api_requests_hour`
441
+ - `octopus_api_complexity_hour`
442
+ - `octopus_api_complexity_percent`
443
+
444
+ ### Fixed
445
+ - **Cooldown Timer Expiry** - Properly publishes `null` at 30 seconds
446
+ - Prevents countdown showing negative values in Home Assistant
447
+ - Timer cleanup prevents memory leaks
448
+ - Exactly 2 MQTT messages per refresh (start + expiry)
449
+
450
+ ### Technical Details
451
+ - **API Complexity Estimation** - Since Octopus API doesn't provide actual complexity:
452
+ - Uses estimated values based on query types
453
+ - Tracks rolling 60-minute window
454
+ - If actual complexity becomes available, will use it automatically
455
+ - **Timestamp-Based Cooldown** - Uses ISO timestamps instead of seconds
456
+ - Home Assistant handles countdown display automatically
457
+ - Zero MQTT spam during countdown
458
+ - Clean `null` state when ready
459
+
460
+ ## [1.0.3] - 2025-12-04
461
+
462
+ ### Added
463
+ - **State reconciliation loop** for charging detection (every 10 seconds)
464
+ - Automatically detects charging state based on cached slot timestamps
465
+ - No API calls - uses local data only
466
+ - Handles imminent/immediate slots when car is plugged in
467
+ - Self-healing: corrects state if timers miss edge cases
468
+ - **Flow Library scorecard compliance**
469
+ - Added `version` field to `node-red` section in package.json (>=2.0.0)
470
+ - Added `examples/` folder with 3 demonstration flows
471
+ - Satisfies Node-RED Flow Library requirements
472
+
473
+ ### Fixed
474
+ - **Home Assistant sensors going "unknown"** when adjusting controls
475
+ - Sensors now maintain last known values while editing pending preferences
476
+ - Only update when fresh data arrives from API
477
+ - Added `lastKnownState` cache and state merging in `publishCurrentState()`
478
+ - **Charging state not updating** for imminent/immediate slots
479
+ - Fixed edge case where slots starting <30s after poll were not detected
480
+ - Reconciliation loop catches these within 10 seconds
481
+ - Ensures accurate "Charging Now" sensor in Home Assistant
482
+
483
+ ### Changed
484
+ - Improved charging state management with redundant detection methods
485
+ - Enhanced MQTT state publishing to preserve sensor data during control updates
486
+
487
+ ## [1.0.2] - 2025-11-30
488
+
489
+ ### Changed
490
+ - Updated flow example description in Node-RED help panel for better clarity
491
+ - Improved explanation of default behavior: reads by default, manually refreshable, and accepts commands
492
+
493
+ ## [1.0.1] - 2025-11-30
494
+
495
+ ### Added
496
+ - **Node.js and Node-RED version requirements** in package.json engines field
497
+ - Minimum Node.js: >=14.0.0
498
+ - Minimum Node-RED: >=2.0.0
499
+ - Addresses Flow Library scorecard requirements
500
+ - **Comprehensive example flows** in Node-RED help panel
501
+ - Basic monitoring flow (inject every 5 min)
502
+ - Set preferences from flow (JSON payload with set_limit/set_time)
503
+ - Home Assistant MQTT integration example
504
+ - **Visual documentation** with screenshots
505
+ - Node-RED flow examples showing monitoring, preferences, and preset buttons
506
+ - MQTT integration flow example
507
+ - Home Assistant device page with all entities
508
+ - **Visual Examples section** in Node-RED help panel with embedded GitHub-hosted images
509
+ - **Screenshots section** in README.md showing real-world usage
510
+
511
+ ### Changed
512
+ - Updated README.md with Screenshots section after Features
513
+ - Updated .npmignore to exclude images/ folder (keeps npm package lightweight)
514
+ - Updated .gitignore to exclude local documentation files
515
+
516
+ ### Fixed
517
+ - Flow Library scorecard now shows supported Node-RED and Node.js versions
518
+ - Flow Library scorecard "Nodes have examples" requirement now satisfied
519
+
520
+ ## [1.0.0] - 2025-11-30
521
+
522
+ ### Added
523
+ - Initial public release
524
+ - **Octopus Energy GraphQL API integration**
525
+ - Authentication via API key
526
+ - Fetch planned charging dispatches (smart-charge and bump-charge slots)
527
+ - Query vehicle charging preferences (target SOC and ready time)
528
+ - Update charging preferences via GraphQL mutations
529
+ - **Home Assistant MQTT auto-discovery**
530
+ - Number entity: Target charge limit (50-100%)
531
+ - Select entity: Ready time (04:00-11:00)
532
+ - Button entity: Apply changes
533
+ - Sensor entities: Confirmed settings, next charge time, total energy, slot times
534
+ - Binary sensor: Charging now (ON/OFF)
535
+ - Organized into Controls, Sensors, and Diagnostics categories
536
+ - **Real-time charging slot detection**
537
+ - Detects currently active charging slots
538
+ - Calculates next charging start time
539
+ - Provides individual slot start/end times (up to 3 slots)
540
+ - Calculates overall charging window
541
+ - Shows charge source (smart-charge vs bump-charge)
542
+ - **Exponential backoff validation**
543
+ - Smart retry mechanism when updating preferences
544
+ - Prevents sensors from becoming "unavailable" during API updates
545
+ - Validates changes at 15s, 30s, 60s, 120s intervals
546
+ - **Comprehensive debugging**
547
+ - Full API call tracking in msg.debug
548
+ - Success/failure status for each operation
549
+ - Detailed error messages
550
+ - **Node-RED flow control**
551
+ - Accept input messages to set preferences programmatically
552
+ - Output payload with all charging data
553
+ - 5-minute default refresh interval (configurable)
554
+ - **Octopus Energy branding**
555
+ - Professional pink theme (#E8146F)
556
+ - Device branded as "Octopus Intelligent" in Home Assistant
557
+ - Suggested "Energy" area in Home Assistant
558
+ - **Unit test coverage**
559
+ - Data processing tests (10 tests)
560
+ - Timer management tests (10 tests)
561
+ - Mock API responses for consistent testing
562
+
563
+ ### Security
564
+ - API key stored securely as Node-RED credential (not exposed in flows)
565
+ - Account numbers sanitized in MQTT topics and entity IDs
566
+
567
+ ### Documentation
568
+ - Comprehensive README.md with:
569
+ - Feature list and capabilities
570
+ - Installation instructions (npm and palette manager)
571
+ - Configuration guide
572
+ - Home Assistant setup instructions
573
+ - Node-RED usage examples
574
+ - Home Assistant automation examples
575
+ - Troubleshooting section
576
+ - Support options (GitHub Star, Sponsor, PayPal donate)
577
+ - MIT License
578
+ - GitHub repository with issue tracking
579
+
580
+ ## Release Notes
581
+
582
+ ### Version Numbering
583
+ This project follows [Semantic Versioning](https://semver.org/):
584
+ - **MAJOR** version (X.0.0): Breaking changes
585
+ - **MINOR** version (1.X.0): New features (backwards compatible)
586
+ - **PATCH** version (1.0.X): Bug fixes (backwards compatible)
587
+
588
+ ### Links
589
+ - [npm Package](https://www.npmjs.com/package/node-red-contrib-octopus-intelligent)
590
+ - [GitHub Repository](https://github.com/ASomerN/node-red-contrib-octopus-intelligent)
591
+ - [Node-RED Flow Library](https://flows.nodered.org/node/node-red-contrib-octopus-intelligent)
592
+ - [Issues & Bug Reports](https://github.com/ASomerN/node-red-contrib-octopus-intelligent/issues)
593
+
594
+ ### Support
595
+ - ⭐ [Star on GitHub](https://github.com/ASomerN/node-red-contrib-octopus-intelligent)
596
+ - 💖 [Become a Sponsor](https://github.com/sponsors/ASomerN)
597
+ - ☕ [Donate via PayPal](https://www.paypal.com/donate?hosted_button_id=A2B8ZFEJBE2S6)