node-red-contrib-octopus-intelligent 1.4.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +487 -408
- package/README.md +1004 -980
- package/examples/basic-monitoring.json +1 -1
- package/examples/ha-dashboard.yaml +602 -486
- package/examples/mqtt-integration.json +1 -1
- package/examples/node-red-dashboard-flow.json +1287 -0
- package/examples/set-preferences.json +1 -1
- package/lib/api-metrics.js +31 -31
- package/lib/auth.js +20 -20
- package/lib/categories/account.js +32 -32
- package/lib/categories/applicable-rates.js +127 -91
- package/lib/categories/completed-dispatches.js +35 -35
- package/lib/categories/electricity.js +146 -133
- package/lib/categories/flex-planned-dispatches.js +36 -36
- package/lib/categories/free-electricity.js +61 -61
- package/lib/categories/gas.js +95 -95
- package/lib/categories/home-mini.js +37 -37
- package/lib/categories/intelligent.js +155 -124
- package/lib/categories/octoplus.js +32 -32
- package/lib/categories/saving-sessions.js +64 -64
- package/lib/categories/wheel-of-fortune.js +49 -49
- package/lib/commands.js +47 -0
- package/lib/discovery-retry.js +13 -0
- package/lib/discovery.js +92 -85
- package/lib/graphql-errors.js +18 -0
- package/lib/graphql.js +44 -44
- package/lib/http-get-json.js +22 -0
- package/lib/payload.js +89 -77
- package/lib/poll-tick.js +44 -44
- package/lib/preferences.js +32 -0
- package/lib/scheduler.js +47 -47
- package/lib/sensor-definitions.js +219 -0
- package/lib/timezone.js +49 -49
- package/lib/update-check.js +38 -0
- package/octopus-intelligent.html +218 -205
- package/octopus-intelligent.js +1687 -1685
- package/package.json +54 -54
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Sensor Definitions (Read-Only)
|
|
4
|
+
// category: undefined = main, 'config' = Configuration, 'diagnostic' = Diagnostics
|
|
5
|
+
//
|
|
6
|
+
// NOTE: entries here must never carry category: 'config' — that HA entity_category
|
|
7
|
+
// means "user-configurable setting", and every sensor below is a read-only value
|
|
8
|
+
// reported from the Kraken API. Writable command entities (timezone select,
|
|
9
|
+
// smart-charging switch) are defined separately in octopus-intelligent.js, not here.
|
|
10
|
+
// Getting this wrong sticks the entity at "unavailable" on some HA Core versions and
|
|
11
|
+
// outright blocks registration on newer ones. Fixed for tariff codes in v1.3.0, for
|
|
12
|
+
// Octoplus binary sensors shortly after, and for the day/night/EV rate-band sensors
|
|
13
|
+
// below in v1.6.1.
|
|
14
|
+
const sensors = [
|
|
15
|
+
// --- EV Charging (main) ---
|
|
16
|
+
{ id: 'next_charge', name: 'Next Charge Time', class: 'timestamp', icon: 'mdi:timer', val: 'next_start' },
|
|
17
|
+
{ id: 'total_energy', name: 'Total Planned Energy', unit: 'kWh', class: 'energy', val: 'total_energy' },
|
|
18
|
+
{ id: 'next_kwh', name: 'Next Slot Energy', unit: 'kWh', class: 'energy', val: 'next_kwh' },
|
|
19
|
+
{ id: 'source', name: 'Charge Source', icon: 'mdi:help-circle', val: 'next_source' },
|
|
20
|
+
{ id: 'slot1_start', name: 'Slot 1 Start', class: 'timestamp', icon: 'mdi:timer-outline', val: 'slot1_start' },
|
|
21
|
+
{ id: 'slot1_end', name: 'Slot 1 End', class: 'timestamp', icon: 'mdi:timer-outline', val: 'slot1_end' },
|
|
22
|
+
{ id: 'slot2_start', name: 'Slot 2 Start', class: 'timestamp', icon: 'mdi:timer-outline', val: 'slot2_start' },
|
|
23
|
+
{ id: 'slot2_end', name: 'Slot 2 End', class: 'timestamp', icon: 'mdi:timer-outline', val: 'slot2_end' },
|
|
24
|
+
{ id: 'slot3_start', name: 'Slot 3 Start', class: 'timestamp', icon: 'mdi:timer-outline', val: 'slot3_start' },
|
|
25
|
+
{ id: 'slot3_end', name: 'Slot 3 End', class: 'timestamp', icon: 'mdi:timer-outline', val: 'slot3_end' },
|
|
26
|
+
{ id: 'window_start', name: 'Overall Window Start', class: 'timestamp', icon: 'mdi:timer-play', val: 'window_start' },
|
|
27
|
+
{ id: 'window_end', name: 'Overall Window End', class: 'timestamp', icon: 'mdi:timer-stop', val: 'window_end' },
|
|
28
|
+
|
|
29
|
+
// --- EV Charging (diagnostic) ---
|
|
30
|
+
{ id: 'next_poll', name: 'Next Poll Time', class: 'timestamp', icon: 'mdi:clock-outline', val: 'next_poll', category: 'diagnostic' },
|
|
31
|
+
{ id: 'refresh_available_at', name: 'Refresh Available At', class: 'timestamp', icon: 'mdi:timer-sand', val: 'refresh_available_at', category: 'diagnostic' },
|
|
32
|
+
{ id: 'api_requests_hour', name: 'API Requests (Last Hour)', icon: 'mdi:api', val: 'api_requests_hour', category: 'diagnostic' },
|
|
33
|
+
{ id: 'api_complexity_hour', name: 'API Complexity (Last Hour)', icon: 'mdi:chart-line', val: 'api_complexity_hour', category: 'diagnostic' },
|
|
34
|
+
{ id: 'api_complexity_percent', name: 'API Complexity Usage', unit: '%', icon: 'mdi:percent', val: 'api_complexity_percent', category: 'diagnostic' },
|
|
35
|
+
|
|
36
|
+
// --- Raw timestamps (diagnostic) ---
|
|
37
|
+
{ id: 'next_charge_raw', name: 'Next Charge Time (Raw)', icon: 'mdi:timer', val: 'next_start_raw', category: 'diagnostic' },
|
|
38
|
+
{ id: 'next_poll_raw', name: 'Next Poll Time (Raw)', icon: 'mdi:clock-outline', val: 'next_poll_raw', category: 'diagnostic' },
|
|
39
|
+
{ id: 'slot1_start_raw', name: 'Slot 1 Start (Raw)', icon: 'mdi:timer-outline', val: 'slot1_start_raw', category: 'diagnostic' },
|
|
40
|
+
{ id: 'slot1_end_raw', name: 'Slot 1 End (Raw)', icon: 'mdi:timer-outline', val: 'slot1_end_raw', category: 'diagnostic' },
|
|
41
|
+
{ id: 'slot2_start_raw', name: 'Slot 2 Start (Raw)', icon: 'mdi:timer-outline', val: 'slot2_start_raw', category: 'diagnostic' },
|
|
42
|
+
{ id: 'slot2_end_raw', name: 'Slot 2 End (Raw)', icon: 'mdi:timer-outline', val: 'slot2_end_raw', category: 'diagnostic' },
|
|
43
|
+
{ id: 'slot3_start_raw', name: 'Slot 3 Start (Raw)', icon: 'mdi:timer-outline', val: 'slot3_start_raw', category: 'diagnostic' },
|
|
44
|
+
{ id: 'slot3_end_raw', name: 'Slot 3 End (Raw)', icon: 'mdi:timer-outline', val: 'slot3_end_raw', category: 'diagnostic' },
|
|
45
|
+
{ id: 'window_start_raw', name: 'Overall Window Start (Raw)', icon: 'mdi:timer-play', val: 'window_start_raw', category: 'diagnostic' },
|
|
46
|
+
{ id: 'window_end_raw', name: 'Overall Window End (Raw)', icon: 'mdi:timer-stop', val: 'window_end_raw', category: 'diagnostic' },
|
|
47
|
+
|
|
48
|
+
// --- Locale timestamps (diagnostic) ---
|
|
49
|
+
{ id: 'next_charge_locale', name: 'Next Charge Time (Locale)', icon: 'mdi:timer', val: 'next_start_locale', category: 'diagnostic' },
|
|
50
|
+
{ id: 'slot1_start_locale', name: 'Slot 1 Start (Locale)', icon: 'mdi:timer-outline', val: 'slot1_start_locale', category: 'diagnostic' },
|
|
51
|
+
{ id: 'slot1_end_locale', name: 'Slot 1 End (Locale)', icon: 'mdi:timer-outline', val: 'slot1_end_locale', category: 'diagnostic' },
|
|
52
|
+
{ id: 'slot2_start_locale', name: 'Slot 2 Start (Locale)', icon: 'mdi:timer-outline', val: 'slot2_start_locale', category: 'diagnostic' },
|
|
53
|
+
{ id: 'slot2_end_locale', name: 'Slot 2 End (Locale)', icon: 'mdi:timer-outline', val: 'slot2_end_locale', category: 'diagnostic' },
|
|
54
|
+
{ id: 'slot3_start_locale', name: 'Slot 3 Start (Locale)', icon: 'mdi:timer-outline', val: 'slot3_start_locale', category: 'diagnostic' },
|
|
55
|
+
{ id: 'slot3_end_locale', name: 'Slot 3 End (Locale)', icon: 'mdi:timer-outline', val: 'slot3_end_locale', category: 'diagnostic' },
|
|
56
|
+
{ id: 'window_start_locale', name: 'Overall Window Start (Locale)', icon: 'mdi:timer-play', val: 'window_start_locale', category: 'diagnostic' },
|
|
57
|
+
{ id: 'window_end_locale', name: 'Overall Window End (Locale)', icon: 'mdi:timer-stop', val: 'window_end_locale', category: 'diagnostic' },
|
|
58
|
+
{ id: 'timezone_detected', name: 'Timezone Detected', icon: 'mdi:earth', val: 'timezone_detected', category: 'diagnostic' },
|
|
59
|
+
{ id: 'timezone_applied', name: 'Timezone Applied', icon: 'mdi:earth-plus', val: 'timezone_applied', category: 'diagnostic' },
|
|
60
|
+
// --- Electricity (main) ---
|
|
61
|
+
{ id: 'electricity_standing_charge', name: 'Electricity Standing Charge', unit: 'p/day', icon: 'mdi:cash', val: 'electricity_standing_charge' },
|
|
62
|
+
{ id: 'electricity_consumption_kwh', name: 'Electricity Consumption', unit: 'kWh', class: 'energy', val: 'electricity_consumption_kwh' },
|
|
63
|
+
// --- Electricity (main) ---
|
|
64
|
+
{ id: 'electricity_unit_rate', name: 'Electricity Unit Rate', unit: 'p/kWh', icon: 'mdi:flash', val: 'electricity_unit_rate' },
|
|
65
|
+
{ id: 'electricity_day_rate', name: 'Electricity Day Rate', unit: 'p/kWh', icon: 'mdi:weather-sunny', val: 'electricity_day_rate' },
|
|
66
|
+
{ id: 'electricity_night_rate', name: 'Electricity Night Rate', unit: 'p/kWh', icon: 'mdi:weather-night', val: 'electricity_night_rate' },
|
|
67
|
+
{ id: 'electricity_ev_peak_rate', name: 'Electricity EV Peak Rate', unit: 'p/kWh', icon: 'mdi:car-electric-outline', val: 'electricity_ev_peak_rate' },
|
|
68
|
+
{ id: 'electricity_ev_off_peak_rate', name: 'Electricity EV Off-Peak Rate', unit: 'p/kWh', icon: 'mdi:car-electric', val: 'electricity_ev_off_peak_rate' },
|
|
69
|
+
{ id: 'electricity_tariff_code', name: 'Electricity Tariff Code', icon: 'mdi:tag', val: 'electricity_tariff_code' },
|
|
70
|
+
{ id: 'electricity_valid_from', name: 'Electricity Tariff Valid From', class: 'timestamp', icon: 'mdi:calendar-start', val: 'electricity_valid_from' },
|
|
71
|
+
{ id: 'electricity_valid_to', name: 'Electricity Tariff Valid To', class: 'timestamp', icon: 'mdi:calendar-end', val: 'electricity_valid_to' },
|
|
72
|
+
// --- Electricity (diagnostic) ---
|
|
73
|
+
{ id: 'electricity_consumption_from', name: 'Electricity Consumption From', class: 'timestamp', icon: 'mdi:calendar-clock', val: 'electricity_consumption_from', category: 'diagnostic' },
|
|
74
|
+
{ id: 'electricity_consumption_to', name: 'Electricity Consumption To', class: 'timestamp', icon: 'mdi:calendar-clock', val: 'electricity_consumption_to', category: 'diagnostic' },
|
|
75
|
+
{ id: 'electricity_rates_error', name: 'Electricity Rates Error', icon: 'mdi:alert-circle', val: 'electricity_rates_error', category: 'diagnostic' },
|
|
76
|
+
{ id: 'electricity_consumption_error', name: 'Electricity Consumption Error', icon: 'mdi:alert-circle', val: 'electricity_consumption_error', category: 'diagnostic' },
|
|
77
|
+
|
|
78
|
+
// --- Electricity Export (main) ---
|
|
79
|
+
{ id: 'electricity_export_consumption_kwh', name: 'Electricity Export Consumption', unit: 'kWh', class: 'energy', val: 'electricity_export_consumption_kwh' },
|
|
80
|
+
{ id: 'electricity_export_rate_current_pence', name: 'Current Electricity Export Rate', unit: 'p/kWh', icon: 'mdi:cash-clock', val: 'electricity_export_rate_current_pence' },
|
|
81
|
+
{ id: 'electricity_export_rate_current_gbp', name: 'Electricity Export Rate', unit: 'GBP/kWh', icon: 'mdi:cash-clock', stateClass: 'measurement', val: 'electricity_export_rate_current_gbp' },
|
|
82
|
+
// --- Electricity Export (main) ---
|
|
83
|
+
// Solar/export users have a second agreement with productCode containing "OUTGOING".
|
|
84
|
+
// unit_rate is null for half-hourly export tariffs (e.g. Agile Outgoing) — current
|
|
85
|
+
// half-hourly export rate comes from electricity_export_rate_current_pence.
|
|
86
|
+
{ id: 'electricity_export_unit_rate', name: 'Electricity Export Unit Rate', unit: 'p/kWh', icon: 'mdi:transmission-tower-export', val: 'electricity_export_unit_rate' },
|
|
87
|
+
{ id: 'electricity_export_standing_charge',name: 'Electricity Export Standing Charge',unit: 'p/day', icon: 'mdi:cash', val: 'electricity_export_standing_charge' },
|
|
88
|
+
{ id: 'electricity_export_tariff_code', name: 'Electricity Export Tariff Code', icon: 'mdi:tag', val: 'electricity_export_tariff_code' },
|
|
89
|
+
{ id: 'electricity_export_valid_from', name: 'Electricity Export Tariff Valid From', class: 'timestamp', icon: 'mdi:calendar-start', val: 'electricity_export_valid_from' },
|
|
90
|
+
{ id: 'electricity_export_valid_to', name: 'Electricity Export Tariff Valid To', class: 'timestamp', icon: 'mdi:calendar-end', val: 'electricity_export_valid_to' },
|
|
91
|
+
// --- Electricity Export (diagnostic) ---
|
|
92
|
+
{ id: 'electricity_export_consumption_from', name: 'Electricity Export Consumption From', class: 'timestamp', icon: 'mdi:calendar-clock', val: 'electricity_export_consumption_from', category: 'diagnostic' },
|
|
93
|
+
{ id: 'electricity_export_consumption_to', name: 'Electricity Export Consumption To', class: 'timestamp', icon: 'mdi:calendar-clock', val: 'electricity_export_consumption_to', category: 'diagnostic' },
|
|
94
|
+
{ id: 'electricity_export_rate_count', name: 'Electricity Export Rate Slots', icon: 'mdi:format-list-numbered', val: 'electricity_export_rate_count', category: 'diagnostic' },
|
|
95
|
+
{ id: 'electricity_export_rate_prev_pence', name: 'Electricity Export Rate Prev', unit: 'p/kWh', icon: 'mdi:cash-clock', val: 'electricity_export_rate_prev_pence', category: 'diagnostic' },
|
|
96
|
+
{ id: 'electricity_export_rate_prev_to', name: 'Electricity Export Rate Prev Ends', class: 'timestamp', icon: 'mdi:calendar-clock', val: 'electricity_export_rate_prev_to', category: 'diagnostic' },
|
|
97
|
+
{ id: 'electricity_export_rate_next_pence', name: 'Electricity Export Rate Next', unit: 'p/kWh', icon: 'mdi:cash-clock', val: 'electricity_export_rate_next_pence', category: 'diagnostic' },
|
|
98
|
+
{ id: 'electricity_export_rate_next_from', name: 'Electricity Export Rate Next From', class: 'timestamp', icon: 'mdi:calendar-clock', val: 'electricity_export_rate_next_from', category: 'diagnostic' },
|
|
99
|
+
{ id: 'electricity_export_rate_prev_gbp', name: 'Electricity Export Rate Prev (GBP)', unit: 'GBP/kWh', icon: 'mdi:cash-clock', val: 'electricity_export_rate_prev_gbp', stateClass: 'measurement', category: 'diagnostic' },
|
|
100
|
+
{ id: 'electricity_export_rate_next_gbp', name: 'Electricity Export Rate Next (GBP)', unit: 'GBP/kWh', icon: 'mdi:cash-clock', val: 'electricity_export_rate_next_gbp', stateClass: 'measurement', category: 'diagnostic' },
|
|
101
|
+
{ id: 'electricity_export_rate_error', name: 'Electricity Export Rate Error', icon: 'mdi:alert-circle', val: 'electricity_export_rate_error', category: 'diagnostic' },
|
|
102
|
+
|
|
103
|
+
// --- Gas (main) ---
|
|
104
|
+
{ id: 'gas_standing_charge', name: 'Gas Standing Charge', unit: 'p/day', icon: 'mdi:cash', val: 'gas_standing_charge' },
|
|
105
|
+
{ id: 'gas_consumption_kwh', name: 'Gas Consumption', unit: 'kWh', class: 'energy', val: 'gas_consumption_kwh' },
|
|
106
|
+
// --- Gas (main) ---
|
|
107
|
+
{ id: 'gas_unit_rate', name: 'Gas Unit Rate', unit: 'p/kWh', icon: 'mdi:fire', val: 'gas_unit_rate' },
|
|
108
|
+
{ id: 'gas_tariff_code', name: 'Gas Tariff Code', icon: 'mdi:tag', val: 'gas_tariff_code' },
|
|
109
|
+
{ id: 'gas_valid_from', name: 'Gas Tariff Valid From', class: 'timestamp', icon: 'mdi:calendar-start', val: 'gas_valid_from' },
|
|
110
|
+
{ id: 'gas_valid_to', name: 'Gas Tariff Valid To', class: 'timestamp', icon: 'mdi:calendar-end', val: 'gas_valid_to' },
|
|
111
|
+
// --- Gas (diagnostic) ---
|
|
112
|
+
{ id: 'gas_consumption_from', name: 'Gas Consumption From', class: 'timestamp', icon: 'mdi:calendar-clock', val: 'gas_consumption_from', category: 'diagnostic' },
|
|
113
|
+
{ id: 'gas_consumption_to', name: 'Gas Consumption To', class: 'timestamp', icon: 'mdi:calendar-clock', val: 'gas_consumption_to', category: 'diagnostic' },
|
|
114
|
+
{ id: 'gas_rates_error', name: 'Gas Rates Error', icon: 'mdi:alert-circle', val: 'gas_rates_error', category: 'diagnostic' },
|
|
115
|
+
{ id: 'gas_consumption_error', name: 'Gas Consumption Error', icon: 'mdi:alert-circle', val: 'gas_consumption_error', category: 'diagnostic' },
|
|
116
|
+
|
|
117
|
+
// --- Applicable Rates (main) ---
|
|
118
|
+
{ id: 'applicable_rates_current_pence', name: 'Current Electricity Rate', unit: 'p/kWh', icon: 'mdi:cash-clock', val: 'applicable_rates_current_pence' },
|
|
119
|
+
{ id: 'applicable_rates_current_gbp', name: 'Electricity Rate', unit: 'GBP/kWh', icon: 'mdi:cash-clock', stateClass: 'measurement', val: 'applicable_rates_current_gbp' },
|
|
120
|
+
// --- Applicable Rates (diagnostic) ---
|
|
121
|
+
{ id: 'applicable_rates_count', name: 'Applicable Rates Slots', icon: 'mdi:format-list-numbered', val: 'applicable_rates_count', category: 'diagnostic' },
|
|
122
|
+
{ id: 'applicable_rates_error', name: 'Applicable Rates Error', icon: 'mdi:alert-circle', val: 'applicable_rates_error', category: 'diagnostic' },
|
|
123
|
+
{ id: 'applicable_rates_prev_pence', name: 'Applicable Rate Prev', unit: 'p/kWh', icon: 'mdi:cash-clock', val: 'applicable_rates_prev_pence', category: 'diagnostic' },
|
|
124
|
+
{ id: 'applicable_rates_prev_gbp', name: 'Applicable Rate Prev (GBP)', unit: 'GBP/kWh', icon: 'mdi:cash-clock', val: 'applicable_rates_prev_gbp', stateClass: 'measurement', category: 'diagnostic' },
|
|
125
|
+
{ id: 'applicable_rates_prev_to', name: 'Applicable Rate Prev Ends', class: 'timestamp', icon: 'mdi:calendar-clock', val: 'applicable_rates_prev_to', category: 'diagnostic' },
|
|
126
|
+
{ id: 'applicable_rates_next_pence', name: 'Applicable Rate Next', unit: 'p/kWh', icon: 'mdi:cash-clock', val: 'applicable_rates_next_pence', category: 'diagnostic' },
|
|
127
|
+
{ id: 'applicable_rates_next_gbp', name: 'Applicable Rate Next (GBP)', unit: 'GBP/kWh', icon: 'mdi:cash-clock', val: 'applicable_rates_next_gbp', stateClass: 'measurement', category: 'diagnostic' },
|
|
128
|
+
{ id: 'applicable_rates_next_from', name: 'Applicable Rate Next From', class: 'timestamp', icon: 'mdi:calendar-clock', val: 'applicable_rates_next_from', category: 'diagnostic' },
|
|
129
|
+
// Applicable rates — 24h schedule stats (v1.5)
|
|
130
|
+
{ id: 'applicable_rates_min_pence', name: 'Applicable Rates Min', unit: 'p/kWh', icon: 'mdi:arrow-down', val: 'applicable_rates_min_pence', category: 'diagnostic' },
|
|
131
|
+
{ id: 'applicable_rates_max_pence', name: 'Applicable Rates Max', unit: 'p/kWh', icon: 'mdi:arrow-up', val: 'applicable_rates_max_pence', category: 'diagnostic' },
|
|
132
|
+
{ id: 'applicable_rates_median_pence', name: 'Applicable Rates Median', unit: 'p/kWh', icon: 'mdi:approximately-equal', val: 'applicable_rates_median_pence', category: 'diagnostic' },
|
|
133
|
+
{ id: 'applicable_rates_avg_pence', name: 'Applicable Rates Avg', unit: 'p/kWh', icon: 'mdi:chart-line', val: 'applicable_rates_avg_pence', category: 'diagnostic' },
|
|
134
|
+
{ id: 'electricity_export_rate_min_pence', name: 'Electricity Export Rate Min', unit: 'p/kWh', icon: 'mdi:arrow-down', val: 'electricity_export_rate_min_pence', category: 'diagnostic' },
|
|
135
|
+
{ id: 'electricity_export_rate_max_pence', name: 'Electricity Export Rate Max', unit: 'p/kWh', icon: 'mdi:arrow-up', val: 'electricity_export_rate_max_pence', category: 'diagnostic' },
|
|
136
|
+
{ id: 'electricity_export_rate_median_pence', name: 'Electricity Export Rate Median', unit: 'p/kWh', icon: 'mdi:approximately-equal', val: 'electricity_export_rate_median_pence', category: 'diagnostic' },
|
|
137
|
+
{ id: 'electricity_export_rate_avg_pence', name: 'Electricity Export Rate Avg', unit: 'p/kWh', icon: 'mdi:chart-line', val: 'electricity_export_rate_avg_pence', category: 'diagnostic' },
|
|
138
|
+
|
|
139
|
+
// --- Account (main) ---
|
|
140
|
+
{ id: 'account_balance_pounds', name: 'Account Balance', unit: '£', icon: 'mdi:cash-multiple', val: 'account_balance_pounds' },
|
|
141
|
+
// --- Account (diagnostic) ---
|
|
142
|
+
{ id: 'account_balance_pence', name: 'Account Balance (Pence)', unit: 'p', icon: 'mdi:cash', val: 'account_balance_pence', category: 'diagnostic' },
|
|
143
|
+
{ id: 'account_error', name: 'Account Error', icon: 'mdi:alert-circle', val: 'account_error', category: 'diagnostic' },
|
|
144
|
+
|
|
145
|
+
// --- Octoplus (main) ---
|
|
146
|
+
// octoplus_enrolled and octoplus_loyalty_points_user are booleans — published as
|
|
147
|
+
// binary_sensor entities further down. Leaving them out of this array.
|
|
148
|
+
{ id: 'octoplus_enrollment_status', name: 'Octoplus Status', icon: 'mdi:star-circle-outline', val: 'octoplus_enrollment_status' },
|
|
149
|
+
// --- Octoplus (diagnostic) ---
|
|
150
|
+
{ id: 'octoplus_error', name: 'Octoplus Error', icon: 'mdi:alert-circle', val: 'octoplus_error', category: 'diagnostic' },
|
|
151
|
+
|
|
152
|
+
// --- Wheel of Fortune (main) ---
|
|
153
|
+
{ id: 'wheel_of_fortune_electricity_spins', name: 'WoF Electricity Spins', icon: 'mdi:star-circle', val: 'wheel_of_fortune_electricity_spins' },
|
|
154
|
+
{ id: 'wheel_of_fortune_gas_spins', name: 'WoF Gas Spins', icon: 'mdi:star-circle', val: 'wheel_of_fortune_gas_spins' },
|
|
155
|
+
// --- Wheel of Fortune (diagnostic) ---
|
|
156
|
+
{ id: 'wheel_of_fortune_electricity_max', name: 'WoF Electricity Max', icon: 'mdi:star-outline', val: 'wheel_of_fortune_electricity_max', category: 'diagnostic' },
|
|
157
|
+
{ id: 'wheel_of_fortune_electricity_used', name: 'WoF Electricity Used', icon: 'mdi:star-outline', val: 'wheel_of_fortune_electricity_used', category: 'diagnostic' },
|
|
158
|
+
{ id: 'wheel_of_fortune_gas_max', name: 'WoF Gas Max', icon: 'mdi:star-outline', val: 'wheel_of_fortune_gas_max', category: 'diagnostic' },
|
|
159
|
+
{ id: 'wheel_of_fortune_gas_used', name: 'WoF Gas Used', icon: 'mdi:star-outline', val: 'wheel_of_fortune_gas_used', category: 'diagnostic' },
|
|
160
|
+
{ id: 'wheel_of_fortune_error', name: 'WoF Error', icon: 'mdi:alert-circle', val: 'wheel_of_fortune_error', category: 'diagnostic' },
|
|
161
|
+
|
|
162
|
+
// --- Home Mini (main) ---
|
|
163
|
+
{ id: 'mini_demand_kw', name: 'Home Mini Demand', unit: 'kW', class: 'power', icon: 'mdi:home-lightning-bolt', val: 'mini_demand_kw' },
|
|
164
|
+
{ id: 'mini_consumption_delta_kwh', name: 'Home Mini Period Consumption', unit: 'kWh', class: 'energy', icon: 'mdi:home-lightning-bolt', val: 'mini_consumption_delta_kwh' },
|
|
165
|
+
// --- Home Mini (diagnostic) ---
|
|
166
|
+
{ id: 'mini_read_at', name: 'Home Mini Reading Time', class: 'timestamp', icon: 'mdi:clock-outline', val: 'mini_read_at', category: 'diagnostic' },
|
|
167
|
+
{ id: 'home_mini_error', name: 'Home Mini Error', icon: 'mdi:alert-circle', val: 'home_mini_error', category: 'diagnostic' },
|
|
168
|
+
|
|
169
|
+
// --- Saving Sessions (main) ---
|
|
170
|
+
{ id: 'saving_session_points', name: 'Octopus Points', icon: 'mdi:star', val: 'saving_session_points' },
|
|
171
|
+
// --- Saving Sessions (main) ---
|
|
172
|
+
{ id: 'saving_session_start', name: 'Saving Session Start', class: 'timestamp', icon: 'mdi:calendar-clock', val: 'saving_session_start' },
|
|
173
|
+
{ id: 'saving_session_end', name: 'Saving Session End', class: 'timestamp', icon: 'mdi:calendar-clock', val: 'saving_session_end' },
|
|
174
|
+
// --- Saving Sessions (diagnostic) ---
|
|
175
|
+
{ id: 'saving_sessions_error', name: 'Saving Sessions Error', icon: 'mdi:alert-circle', val: 'saving_sessions_error', category: 'diagnostic' },
|
|
176
|
+
|
|
177
|
+
// --- Free Electricity (main) ---
|
|
178
|
+
{ id: 'free_electricity_start', name: 'Free Electricity Start', class: 'timestamp', icon: 'mdi:flash-circle', val: 'free_electricity_start' },
|
|
179
|
+
{ id: 'free_electricity_end', name: 'Free Electricity End', class: 'timestamp', icon: 'mdi:flash-circle', val: 'free_electricity_end' },
|
|
180
|
+
// --- Free Electricity (diagnostic) ---
|
|
181
|
+
{ id: 'free_electricity_error', name: 'Free Electricity Error', icon: 'mdi:alert-circle', val: 'free_electricity_error', category: 'diagnostic' },
|
|
182
|
+
|
|
183
|
+
// --- Dispatches (main) ---
|
|
184
|
+
{ id: 'completed_dispatches_count', name: 'Completed Dispatches', icon: 'mdi:history', val: 'completed_dispatches_count' },
|
|
185
|
+
{ id: 'flex_planned_dispatches_count', name: 'Flex Planned Dispatches', icon: 'mdi:lightning-bolt-circle', val: 'flex_planned_dispatches_count' },
|
|
186
|
+
// --- Dispatches (diagnostic) ---
|
|
187
|
+
{ id: 'completed_dispatches_error', name: 'Completed Dispatches Error', icon: 'mdi:alert-circle', val: 'completed_dispatches_error', category: 'diagnostic' },
|
|
188
|
+
{ id: 'flex_planned_dispatches_error', name: 'Flex Planned Dispatches Error', icon: 'mdi:alert-circle', val: 'flex_planned_dispatches_error', category: 'diagnostic' },
|
|
189
|
+
{ id: 'intelligent_error', name: 'Intelligent Error', icon: 'mdi:alert-circle', val: 'intelligent_error', category: 'diagnostic' },
|
|
190
|
+
|
|
191
|
+
// v1.5 — update check (the MQTT update entity is published in announceControls())
|
|
192
|
+
{ id: 'installed_version', name: 'Installed Version', icon: 'mdi:package-variant', val: 'installed_version', category: 'diagnostic' },
|
|
193
|
+
{ id: 'latest_version', name: 'Latest Version', icon: 'mdi:package-variant-closed-plus', val: 'latest_version', category: 'diagnostic' },
|
|
194
|
+
{ id: 'update_check_at', name: 'Update Check At', class: 'timestamp', icon: 'mdi:clock-check-outline', val: 'update_check_at', category: 'diagnostic' },
|
|
195
|
+
{ id: 'update_check_error', name: 'Update Check Error', icon: 'mdi:alert-circle', val: 'update_check_error', category: 'diagnostic' },
|
|
196
|
+
];
|
|
197
|
+
|
|
198
|
+
// v1.5 — derived binary_sensors for the unified <category>_error fields.
|
|
199
|
+
// OFF when the underlying field is null/empty (healthy), ON when populated.
|
|
200
|
+
// The string sensors stay; these are additional indicators.
|
|
201
|
+
const errorSensors = [
|
|
202
|
+
{ id: 'intelligent_error_state', name: 'Intelligent Error State', val: 'intelligent_error' },
|
|
203
|
+
{ id: 'electricity_rates_error_state', name: 'Electricity Rates Error State', val: 'electricity_rates_error' },
|
|
204
|
+
{ id: 'electricity_consumption_error_state', name: 'Electricity Consumption Error State', val: 'electricity_consumption_error' },
|
|
205
|
+
{ id: 'electricity_export_rate_error_state', name: 'Electricity Export Rate Error State', val: 'electricity_export_rate_error' },
|
|
206
|
+
{ id: 'gas_rates_error_state', name: 'Gas Rates Error State', val: 'gas_rates_error' },
|
|
207
|
+
{ id: 'gas_consumption_error_state', name: 'Gas Consumption Error State', val: 'gas_consumption_error' },
|
|
208
|
+
{ id: 'applicable_rates_error_state', name: 'Applicable Rates Error State', val: 'applicable_rates_error' },
|
|
209
|
+
{ id: 'account_error_state', name: 'Account Error State', val: 'account_error' },
|
|
210
|
+
{ id: 'octoplus_error_state', name: 'Octoplus Error State', val: 'octoplus_error' },
|
|
211
|
+
{ id: 'wheel_of_fortune_error_state', name: 'Wheel of Fortune Error State', val: 'wheel_of_fortune_error' },
|
|
212
|
+
{ id: 'home_mini_error_state', name: 'Home Mini Error State', val: 'home_mini_error' },
|
|
213
|
+
{ id: 'saving_sessions_error_state', name: 'Saving Sessions Error State', val: 'saving_sessions_error' },
|
|
214
|
+
{ id: 'free_electricity_error_state', name: 'Free Electricity Error State', val: 'free_electricity_error' },
|
|
215
|
+
{ id: 'completed_dispatches_error_state', name: 'Completed Dispatches Error State', val: 'completed_dispatches_error' },
|
|
216
|
+
{ id: 'flex_planned_dispatches_error_state', name: 'Flex Planned Dispatches Error State', val: 'flex_planned_dispatches_error' },
|
|
217
|
+
];
|
|
218
|
+
|
|
219
|
+
module.exports = { sensors, errorSensors };
|
package/lib/timezone.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function convertToTimezone(dateStr, tz) {
|
|
4
|
-
if (!dateStr || typeof dateStr !== 'string') return dateStr;
|
|
5
|
-
try {
|
|
6
|
-
const date = new Date(dateStr.replace(' ', 'T'));
|
|
7
|
-
if (isNaN(date.getTime())) return dateStr;
|
|
8
|
-
const parts = new Intl.DateTimeFormat('en-CA', {
|
|
9
|
-
timeZone: tz,
|
|
10
|
-
year: 'numeric', month: '2-digit', day: '2-digit',
|
|
11
|
-
hour: '2-digit', minute: '2-digit', second: '2-digit',
|
|
12
|
-
hour12: false, hourCycle: 'h23'
|
|
13
|
-
}).formatToParts(date);
|
|
14
|
-
const get = (type) => (parts.find(p => p.type === type) || {}).value || '00';
|
|
15
|
-
const y = get('year'), mo = get('month'), d = get('day');
|
|
16
|
-
const h = get('hour'), mi = get('minute'), s = get('second');
|
|
17
|
-
const localAsUtc = Date.UTC(
|
|
18
|
-
parseInt(y, 10), parseInt(mo, 10) - 1, parseInt(d, 10),
|
|
19
|
-
parseInt(h, 10), parseInt(mi, 10), parseInt(s, 10)
|
|
20
|
-
);
|
|
21
|
-
const offsetMins = Math.round((localAsUtc - date.getTime()) / 60000);
|
|
22
|
-
const sign = offsetMins >= 0 ? '+' : '-';
|
|
23
|
-
const absMin = Math.abs(offsetMins);
|
|
24
|
-
const offsetStr = `${sign}${String(Math.floor(absMin / 60)).padStart(2, '0')}:${String(absMin % 60).padStart(2, '0')}`;
|
|
25
|
-
return `${y}-${mo}-${d} ${h}:${mi}:${s}${offsetStr}`;
|
|
26
|
-
} catch (e) {
|
|
27
|
-
return dateStr;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function resolveTimezone(nd) {
|
|
32
|
-
try {
|
|
33
|
-
const persisted = nd.context().get('timezone');
|
|
34
|
-
if (persisted && typeof persisted === 'string' && persisted.trim().length > 0) {
|
|
35
|
-
return persisted.trim();
|
|
36
|
-
}
|
|
37
|
-
} catch (e) {}
|
|
38
|
-
const override = nd.timezoneOverride;
|
|
39
|
-
if (override && typeof override === 'string' && override.trim().length > 0) {
|
|
40
|
-
return override.trim();
|
|
41
|
-
}
|
|
42
|
-
try {
|
|
43
|
-
return Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC';
|
|
44
|
-
} catch (e) {
|
|
45
|
-
return 'UTC';
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
module.exports = { convertToTimezone, resolveTimezone };
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function convertToTimezone(dateStr, tz) {
|
|
4
|
+
if (!dateStr || typeof dateStr !== 'string') return dateStr;
|
|
5
|
+
try {
|
|
6
|
+
const date = new Date(dateStr.replace(' ', 'T'));
|
|
7
|
+
if (isNaN(date.getTime())) return dateStr;
|
|
8
|
+
const parts = new Intl.DateTimeFormat('en-CA', {
|
|
9
|
+
timeZone: tz,
|
|
10
|
+
year: 'numeric', month: '2-digit', day: '2-digit',
|
|
11
|
+
hour: '2-digit', minute: '2-digit', second: '2-digit',
|
|
12
|
+
hour12: false, hourCycle: 'h23'
|
|
13
|
+
}).formatToParts(date);
|
|
14
|
+
const get = (type) => (parts.find(p => p.type === type) || {}).value || '00';
|
|
15
|
+
const y = get('year'), mo = get('month'), d = get('day');
|
|
16
|
+
const h = get('hour'), mi = get('minute'), s = get('second');
|
|
17
|
+
const localAsUtc = Date.UTC(
|
|
18
|
+
parseInt(y, 10), parseInt(mo, 10) - 1, parseInt(d, 10),
|
|
19
|
+
parseInt(h, 10), parseInt(mi, 10), parseInt(s, 10)
|
|
20
|
+
);
|
|
21
|
+
const offsetMins = Math.round((localAsUtc - date.getTime()) / 60000);
|
|
22
|
+
const sign = offsetMins >= 0 ? '+' : '-';
|
|
23
|
+
const absMin = Math.abs(offsetMins);
|
|
24
|
+
const offsetStr = `${sign}${String(Math.floor(absMin / 60)).padStart(2, '0')}:${String(absMin % 60).padStart(2, '0')}`;
|
|
25
|
+
return `${y}-${mo}-${d} ${h}:${mi}:${s}${offsetStr}`;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
return dateStr;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function resolveTimezone(nd) {
|
|
32
|
+
try {
|
|
33
|
+
const persisted = nd.context().get('timezone');
|
|
34
|
+
if (persisted && typeof persisted === 'string' && persisted.trim().length > 0) {
|
|
35
|
+
return persisted.trim();
|
|
36
|
+
}
|
|
37
|
+
} catch (e) {}
|
|
38
|
+
const override = nd.timezoneOverride;
|
|
39
|
+
if (override && typeof override === 'string' && override.trim().length > 0) {
|
|
40
|
+
return override.trim();
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC';
|
|
44
|
+
} catch (e) {
|
|
45
|
+
return 'UTC';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module.exports = { convertToTimezone, resolveTimezone };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const NPM_LATEST_URL = 'https://registry.npmjs.org/node-red-contrib-octopus-intelligent/latest';
|
|
4
|
+
|
|
5
|
+
function compareSemver(a, b) {
|
|
6
|
+
// Strict numeric X.Y.Z with optional pre-release suffix.
|
|
7
|
+
// Pre-release (1.5.0-dev.1) is OLDER than the base release (1.5.0).
|
|
8
|
+
const parse = v => {
|
|
9
|
+
const m = String(v).match(/^(\d+)\.(\d+)\.(\d+)(-.+)?$/);
|
|
10
|
+
if (!m) return null;
|
|
11
|
+
return { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] || null };
|
|
12
|
+
};
|
|
13
|
+
const pa = parse(a), pb = parse(b);
|
|
14
|
+
if (!pa || !pb) return 0;
|
|
15
|
+
if (pa.major !== pb.major) return pa.major - pb.major;
|
|
16
|
+
if (pa.minor !== pb.minor) return pa.minor - pb.minor;
|
|
17
|
+
if (pa.patch !== pb.patch) return pa.patch - pb.patch;
|
|
18
|
+
if (pa.pre && !pb.pre) return -1;
|
|
19
|
+
if (!pa.pre && pb.pre) return 1;
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function checkUpdate(httpGetJson, installedVersion) {
|
|
24
|
+
const data = await httpGetJson(NPM_LATEST_URL);
|
|
25
|
+
const latest = data && data.version;
|
|
26
|
+
if (typeof latest !== 'string' || !/^\d+\.\d+\.\d+/.test(latest)) {
|
|
27
|
+
throw new Error('npm registry response missing version');
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
installed_version: installedVersion,
|
|
31
|
+
latest_version: latest,
|
|
32
|
+
update_available: compareSemver(latest, installedVersion) > 0,
|
|
33
|
+
update_check_at: new Date().toISOString(),
|
|
34
|
+
update_check_error: null,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = { checkUpdate, compareSemver, NPM_LATEST_URL };
|