homebridge-nuheat2 1.2.28 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,21 @@ All notable changes to this project should be documented in this file
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [1.3.0] - 2026-10-15
8
+
9
+ ### Added
10
+
11
+ - Opt-in `enableThermostatModeControl` setting that adds `Off` and `Auto` target states to each thermostat and routes those requests through Nuheat's v2 mode API (`PUT /api/v2/Mode/Manual`, `Mode/Hold`, `Mode/Auto`). Defaults to `false`, so existing installations keep advertising heat only
12
+
13
+ ### Changed
14
+
15
+ - Derive the HomeKit target state from Nuheat's `operatingMode`/`scheduleMode` fields, replacing a switch that returned `Heat` in every branch
16
+
17
+ ### Fixed
18
+
19
+ - Stop pushing the empty `204 No Content` response from setpoint writes into HomeKit, which briefly flashed `0.2 C` / `10 C` readings and a wrong target state after every change; write paths now re-read the thermostat and non-object payloads are ignored
20
+ - Stop sending a stale cached setpoint with heat-mode requests, which could silently clobber a concurrent setpoint write from the Home app; heat requests now omit the optional temperature field
21
+
7
22
  ## [1.2.28] - 2026-09-14
8
23
 
9
24
  ### Fixed
package/README.md CHANGED
@@ -64,6 +64,7 @@ The equivalent JSON looks like this:
64
64
  "groups": [{ "groupName": "Main Floor", "disabled": false }],
65
65
  "exposeScheduleSwitches": false,
66
66
  "enableNotifications": true,
67
+ "enableThermostatModeControl": false,
67
68
  "holdLength": 1440,
68
69
  "refresh": 60
69
70
  }
@@ -86,6 +87,7 @@ The equivalent JSON looks like this:
86
87
  - `holdLength`: Hold duration in minutes, default `1440`. Values are clamped from `0` to `1440`
87
88
  - `refresh`: Poll interval in seconds, default `60`. Values lower than `30` are raised to `30` to reduce API traffic
88
89
  - `enableNotifications`: Enables Nuheat SignalR notifications for faster updates. Defaults to `true`; set to `false` only while troubleshooting
90
+ - `enableThermostatModeControl`: Adds `Off` and `Auto` target states to each thermostat so HomeKit can request standby or resume the schedule. Defaults to `false`. Experimental; see [Thermostat Mode Control](#thermostat-mode-control)
89
91
  - `debug`: Enables verbose Nuheat API, notification, and accessory logging. Defaults to `false`
90
92
 
91
93
  ### Hold Length Behavior
@@ -102,6 +104,22 @@ What the thermostats do while a group is in away mode is decided by Nuheat's ser
102
104
 
103
105
  If you need a specific temperature held while you are away, set that temperature on the thermostat itself. The plugin will hold it for `holdLength` minutes, or permanently when `holdLength` is `1440`.
104
106
 
107
+ ### Thermostat Mode Control
108
+
109
+ By default each thermostat advertises only `Heat` as a target state, because Nuheat's v1 thermostat update API has no operating-mode field and therefore cannot request standby.
110
+
111
+ Setting `enableThermostatModeControl` to `true` adds `Off` and `Auto` to the target states and routes those requests through Nuheat's v2 mode API:
112
+
113
+ | HomeKit target | Nuheat v2 request |
114
+ | --- | --- |
115
+ | `Off` | `PUT /api/v2/Mode/Manual` at the minimum target temperature (10 °C / 50 °F) |
116
+ | `Heat` | `PUT /api/v2/Mode/Hold` at the current target temperature, or `Mode/Manual` when `holdLength` is `1440` |
117
+ | `Auto` | `PUT /api/v2/Mode/Auto`, resuming the schedule |
118
+
119
+ Reads still come from the v1 API, which is the only version that reports `groupId` (needed for away mode) and `operatingMode`/`scheduleMode`. The plugin derives the HomeKit target state from those fields: an auto schedule combined with a manual operating mode is reported as `Off` (Nuheat's Standby), a hold is reported as `Heat`, and a normal scheduled run is reported as `Auto`.
120
+
121
+ This option is **experimental**. Nuheat has no explicit "off" concept, so `Off` is implemented as a permanent manual setpoint at the minimum temperature. The mapping above is inferred from Nuheat's API rather than verified against hardware, and it is unknown whether a v2 mode write is immediately reflected in a v1 read. Leave it disabled unless you want HomeKit to drive thermostat mode.
122
+
105
123
  ### Device Discovery
106
124
 
107
125
  If `devices` is omitted or empty, the plugin will automatically expose every thermostat on the authenticated account.
@@ -95,6 +95,12 @@
95
95
  "default": false,
96
96
  "description": "Create one switch per thermostat. The switch is on when the thermostat follows its Nuheat schedule and can be turned on to resume the schedule."
97
97
  },
98
+ "enableThermostatModeControl": {
99
+ "title": "Enable Thermostat Mode Control (Off/Auto)",
100
+ "type": "boolean",
101
+ "default": false,
102
+ "description": "Adds Off and Auto target states to each thermostat using Nuheat's v2 mode API, so HomeKit can request standby or resume the schedule. Experimental: leave disabled unless you want HomeKit to drive thermostat mode."
103
+ },
98
104
  "holdLength": {
99
105
  "title": "Hold Length (minutes)",
100
106
  "type": "integer",
@@ -152,6 +158,7 @@
152
158
  "holdLength",
153
159
  "refresh",
154
160
  "enableNotifications",
161
+ "enableThermostatModeControl",
155
162
  "debug"
156
163
  ]
157
164
  }
@@ -146,6 +146,19 @@
146
146
  </span>
147
147
  </label>
148
148
 
149
+ <label class="checkbox">
150
+ <input id="enable-thermostat-mode-control" type="checkbox" />
151
+ <span>
152
+ Enable thermostat mode control (Off / Auto)
153
+ <small>
154
+ Adds Off and Auto target states to each thermostat using Nuheat's v2
155
+ mode API, so HomeKit can request standby or resume the schedule.
156
+ Experimental; leave off unless you want HomeKit to drive thermostat
157
+ mode.
158
+ </small>
159
+ </span>
160
+ </label>
161
+
149
162
  <label class="checkbox">
150
163
  <input id="debug" type="checkbox" />
151
164
  <span>
@@ -12,6 +12,9 @@ const elements = {
12
12
  holdLength: document.getElementById("hold-length"),
13
13
  refresh: document.getElementById("refresh"),
14
14
  enableNotifications: document.getElementById("enable-notifications"),
15
+ enableThermostatModeControl: document.getElementById(
16
+ "enable-thermostat-mode-control",
17
+ ),
15
18
  debug: document.getElementById("debug"),
16
19
  saveAccount: document.getElementById("save-account"),
17
20
  addDevice: document.getElementById("add-device"),
@@ -102,6 +105,7 @@ function createDefaultConfig() {
102
105
  autoPopulateAwayModeSwitches: false,
103
106
  exposeScheduleSwitches: false,
104
107
  enableNotifications: true,
108
+ enableThermostatModeControl: false,
105
109
  holdLength: 1440,
106
110
  refresh: 60,
107
111
  debug: false,
@@ -126,6 +130,9 @@ function renderConfig(config) {
126
130
  elements.holdLength.value = String(normalizeHoldLength(config.holdLength));
127
131
  elements.refresh.value = String(normalizeRefresh(config.refresh));
128
132
  elements.enableNotifications.checked = config.enableNotifications !== false;
133
+ elements.enableThermostatModeControl.checked = Boolean(
134
+ config.enableThermostatModeControl,
135
+ );
129
136
  elements.debug.checked = Boolean(config.debug);
130
137
 
131
138
  updateStatuses();
@@ -313,6 +320,9 @@ async function saveBehavior() {
313
320
  holdLength,
314
321
  refresh,
315
322
  enableNotifications: Boolean(elements.enableNotifications.checked),
323
+ enableThermostatModeControl: Boolean(
324
+ elements.enableThermostatModeControl.checked,
325
+ ),
316
326
  debug: Boolean(elements.debug.checked),
317
327
  });
318
328
  showToast("success", "Behavior settings saved.");
@@ -438,6 +448,10 @@ function renderDiagnostics() {
438
448
  "Notifications",
439
449
  config.enableNotifications === false ? "disabled" : "enabled",
440
450
  ],
451
+ [
452
+ "Mode Control",
453
+ config.enableThermostatModeControl ? "Off / Auto enabled" : "heat only",
454
+ ],
441
455
  ["Debug Logs", config.debug ? "enabled" : "disabled"],
442
456
  ]);
443
457
  }
@@ -475,6 +489,9 @@ function getDraftConfig() {
475
489
  holdLength: normalizeHoldLength(elements.holdLength.value),
476
490
  refresh: normalizeRefresh(elements.refresh.value),
477
491
  enableNotifications: Boolean(elements.enableNotifications.checked),
492
+ enableThermostatModeControl: Boolean(
493
+ elements.enableThermostatModeControl.checked,
494
+ ),
478
495
  debug: Boolean(elements.debug.checked),
479
496
  };
480
497
  }
@@ -568,6 +585,7 @@ function bindEvents() {
568
585
  elements.holdLength,
569
586
  elements.refresh,
570
587
  elements.enableNotifications,
588
+ elements.enableThermostatModeControl,
571
589
  elements.debug,
572
590
  ].forEach((element) => {
573
591
  element.addEventListener("input", () => {
package/index.js CHANGED
@@ -192,7 +192,7 @@ class NuHeatPlatform {
192
192
  entry = { uuid };
193
193
  this.accessories.push(entry);
194
194
  }
195
- entry.accessory = new NuHeatThermostat(this.log, deviceData, this.config.holdLength || 1440, getPlatformAccessory(deviceAccessory), this.NuHeatAPI, Homebridge, this.account?.temperatureScale);
195
+ entry.accessory = new NuHeatThermostat(this.log, deviceData, this.config.holdLength || 1440, getPlatformAccessory(deviceAccessory), this.NuHeatAPI, Homebridge, this.account?.temperatureScale, this.config.enableThermostatModeControl === true);
196
196
  entry.existsInConfig = true;
197
197
  this.log.info("Loaded thermostat " +
198
198
  deviceData.serialNumber +
package/lib/NuHeatAPI.js CHANGED
@@ -163,6 +163,42 @@ class NuHeatAPI {
163
163
  scheduleMode: NuHeatModels_1.SCHEDULE_MODE.AUTO,
164
164
  });
165
165
  }
166
+ /**
167
+ * The v1 thermostat update model has no operating mode, so it cannot request
168
+ * standby. The v2 mode endpoints can, and they share the same account,
169
+ * identity provider, and `openapi` scope as v1.
170
+ */
171
+ async setThermostatMode(serialNumber, mode, options = {}) {
172
+ let callURL;
173
+ const callBody = { serialNumber };
174
+ if (mode === NuHeatModels_1.HEATING_MODE.AUTO) {
175
+ callURL = (0, settings_1.buildNuHeatApiUrl)("/api/v2/Mode/Auto");
176
+ }
177
+ else if (mode === NuHeatModels_1.HEATING_MODE.HOLD) {
178
+ callURL = (0, settings_1.buildNuHeatApiUrl)("/api/v2/Mode/Hold");
179
+ if (options.holdLength && options.holdLength > 0) {
180
+ callBody.holdUntil = new Date(Date.now() + options.holdLength * 60 * 1000).toISOString();
181
+ }
182
+ }
183
+ else {
184
+ // NuHeat has no off; standby is a permanent manual setpoint.
185
+ callURL = (0, settings_1.buildNuHeatApiUrl)("/api/v2/Mode/Manual");
186
+ }
187
+ if (options.setPointTemp !== undefined) {
188
+ callBody.temperature = Number(options.setPointTemp);
189
+ callBody.temperatureType = NuHeatModels_1.TEMPERATURE_TYPE.ABSOLUTE;
190
+ }
191
+ this.log.debug("NuHeatAPI: Setting thermostat " +
192
+ serialNumber +
193
+ " to " +
194
+ mode +
195
+ " mode.");
196
+ const callOptions = {
197
+ body: JSON.stringify(callBody),
198
+ method: "PUT",
199
+ };
200
+ return await this.makeAPICall(callURL, callOptions);
201
+ }
166
202
  async updateThermostat(thermostatUpdate) {
167
203
  const callURL = (0, settings_1.buildNuHeatApiUrl)("/api/v1/Thermostat");
168
204
  const callOptions = {
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OPERATING_MODE = exports.SCHEDULE_MODE = void 0;
3
+ exports.TEMPERATURE_TYPE = exports.HEATING_MODE = exports.OPERATING_MODE = exports.SCHEDULE_MODE = void 0;
4
+ exports.isThermostatOnline = isThermostatOnline;
5
+ exports.deriveHeatingMode = deriveHeatingMode;
4
6
  exports.normalizeAccount = normalizeAccount;
5
7
  exports.normalizeGroup = normalizeGroup;
6
8
  exports.normalizeSchedule = normalizeSchedule;
@@ -15,9 +17,56 @@ exports.OPERATING_MODE = {
15
17
  AUTO: 1,
16
18
  MANUAL: 2,
17
19
  };
20
+ exports.HEATING_MODE = {
21
+ OFF: "off",
22
+ MANUAL: "manual",
23
+ HOLD: "hold",
24
+ AUTO: "auto",
25
+ };
26
+ /** v2 `eTemperatureType`: 0 = absolute setpoint, 1 = relative to current. */
27
+ exports.TEMPERATURE_TYPE = {
28
+ ABSOLUTE: 0,
29
+ RELATIVE: 1,
30
+ };
18
31
  function coalesce(...values) {
19
32
  return values.find((value) => value !== undefined && value !== null);
20
33
  }
34
+ function isThermostatOnline(thermostat) {
35
+ const onlineValue = coalesce(thermostat.Online, thermostat.online, thermostat.isOnline);
36
+ if (typeof onlineValue === "boolean") {
37
+ return onlineValue;
38
+ }
39
+ if (typeof onlineValue === "string") {
40
+ return onlineValue.replace(/'/g, "").trim().toLowerCase() === "true";
41
+ }
42
+ return true;
43
+ }
44
+ /**
45
+ * NuHeat has no "off". Standby is reported as operating mode MANUAL paired
46
+ * with schedule mode AUTO; a real manual setpoint change always sends a hold
47
+ * schedule mode.
48
+ */
49
+ function deriveHeatingMode(thermostat) {
50
+ if (!isThermostatOnline(thermostat)) {
51
+ return exports.HEATING_MODE.OFF;
52
+ }
53
+ const scheduleMode = Number(thermostat.scheduleMode);
54
+ if (scheduleMode === exports.SCHEDULE_MODE.HOLD) {
55
+ return exports.HEATING_MODE.HOLD;
56
+ }
57
+ if (scheduleMode === exports.SCHEDULE_MODE.PERMANENT_HOLD) {
58
+ return exports.HEATING_MODE.MANUAL;
59
+ }
60
+ if (scheduleMode === exports.SCHEDULE_MODE.AUTO) {
61
+ return Number(thermostat.operatingMode) === exports.OPERATING_MODE.MANUAL
62
+ ? exports.HEATING_MODE.OFF
63
+ : exports.HEATING_MODE.AUTO;
64
+ }
65
+ // Unknown schedule mode: report whatever the hardware tells us.
66
+ return Number(thermostat.operatingMode) === exports.OPERATING_MODE.MANUAL
67
+ ? exports.HEATING_MODE.MANUAL
68
+ : exports.HEATING_MODE.AUTO;
69
+ }
21
70
  function normalizeAccount(account = {}) {
22
71
  return {
23
72
  firstName: coalesce(account.firstName, account.FirstName),
@@ -11,7 +11,8 @@ class NuHeatThermostat {
11
11
  accessory;
12
12
  NuHeatAPI;
13
13
  temperatureScale;
14
- constructor(log, deviceData, holdLength, accessory, NuHeatAPI, homebridge, temperatureScale) {
14
+ enableThermostatModeControl;
15
+ constructor(log, deviceData, holdLength, accessory, NuHeatAPI, homebridge, temperatureScale, enableThermostatModeControl = false) {
15
16
  Characteristic = homebridge.hap.Characteristic;
16
17
  ThermostatService = homebridge.hap.Service.Thermostat;
17
18
  this.log = log;
@@ -20,6 +21,7 @@ class NuHeatThermostat {
20
21
  this.accessory = accessory;
21
22
  this.NuHeatAPI = NuHeatAPI;
22
23
  this.temperatureScale = temperatureScale;
24
+ this.enableThermostatModeControl = enableThermostatModeControl;
23
25
  this.accessory
24
26
  .getService(homebridge.hap.Service.AccessoryInformation)
25
27
  .setCharacteristic(Characteristic.Manufacturer, "NuHeat")
@@ -31,10 +33,17 @@ class NuHeatThermostat {
31
33
  setupListeners() {
32
34
  const thermostatService = this.accessory.getService(ThermostatService);
33
35
  this.log.info("holdLength: " + this.holdLength, this.deviceData.name);
36
+ const targetHeatingCoolingStates = this.enableThermostatModeControl
37
+ ? [
38
+ Characteristic.TargetHeatingCoolingState.OFF,
39
+ Characteristic.TargetHeatingCoolingState.HEAT,
40
+ Characteristic.TargetHeatingCoolingState.AUTO,
41
+ ]
42
+ : [Characteristic.TargetHeatingCoolingState.HEAT];
34
43
  thermostatService
35
44
  .getCharacteristic(Characteristic.TargetHeatingCoolingState)
36
45
  .setProps({
37
- validValues: [Characteristic.TargetHeatingCoolingState.HEAT],
46
+ validValues: targetHeatingCoolingStates,
38
47
  })
39
48
  .on("set", this.setTargetHeatingCooling.bind(this));
40
49
  thermostatService.getCharacteristic(Characteristic.CurrentTemperature).setProps({
@@ -50,6 +59,10 @@ class NuHeatThermostat {
50
59
  this.updateTemperatureDisplayUnits();
51
60
  }
52
61
  async setTargetHeatingCooling(value, callback) {
62
+ if (this.enableThermostatModeControl) {
63
+ await this.setThermostatModeFromHomeKit(value, callback);
64
+ return;
65
+ }
53
66
  if (value !== Characteristic.TargetHeatingCoolingState.OFF) {
54
67
  callback(null);
55
68
  void this.updateAccessory();
@@ -62,7 +75,57 @@ class NuHeatThermostat {
62
75
  callback(new Error("Error: setTargetHeatingCooling"));
63
76
  return;
64
77
  }
65
- this.updateValues(response);
78
+ // The v1 write returns 204 with no content, so re-read the authoritative
79
+ // state instead of pushing the empty response into HomeKit.
80
+ await this.updateAccessory();
81
+ callback(null);
82
+ }
83
+ /**
84
+ * The v1 update model cannot request standby or an indefinite auto schedule,
85
+ * so mode changes go through the v2 mode endpoints. Those writes return no
86
+ * content, so the authoritative state is re-read through v1 afterwards.
87
+ */
88
+ async setThermostatModeFromHomeKit(value, callback) {
89
+ const { OFF, HEAT, AUTO } = Characteristic.TargetHeatingCoolingState;
90
+ let mode;
91
+ const options = {};
92
+ if (value === OFF) {
93
+ mode = NuHeatModels_1.HEATING_MODE.OFF;
94
+ options.setPointTemp = this.toNuHeatTemperature(MIN_TARGET_TEMPERATURE_C);
95
+ this.log.info("Setting the thermostat to standby (minimum target temperature).", this.deviceData.name);
96
+ }
97
+ else if (value === AUTO) {
98
+ mode = NuHeatModels_1.HEATING_MODE.AUTO;
99
+ this.log.info("Resuming the NuHeat schedule.", this.deviceData.name);
100
+ }
101
+ else if (value === HEAT) {
102
+ // Deliberately omit the setpoint: the v2 mode body's temperature field
103
+ // is optional, and HomeKit sends mode and temperature as separate
104
+ // concurrent writes. Sending a stale setpoint here can clobber the
105
+ // setpoint write that lands right after this one.
106
+ if (this.holdLength >= 1440) {
107
+ mode = NuHeatModels_1.HEATING_MODE.MANUAL;
108
+ }
109
+ else {
110
+ mode = NuHeatModels_1.HEATING_MODE.HOLD;
111
+ if (this.holdLength > 0) {
112
+ options.holdLength = this.holdLength;
113
+ }
114
+ }
115
+ this.log.info("Holding the thermostat target temperature.", this.deviceData.name);
116
+ }
117
+ else {
118
+ this.log.error("Unsupported target heating state " + value, this.deviceData.name);
119
+ callback(new Error("Error: setTargetHeatingCooling"));
120
+ return;
121
+ }
122
+ const response = await this.NuHeatAPI.setThermostatMode(this.deviceData.serialNumber ?? "", mode, options);
123
+ if (!response) {
124
+ this.log.error("Error setting thermostat mode", this.deviceData.name);
125
+ callback(new Error("Error: setTargetHeatingCooling"));
126
+ return;
127
+ }
128
+ await this.updateAccessory();
66
129
  callback(null);
67
130
  }
68
131
  async setTargetTemperature(value, callback) {
@@ -79,7 +142,9 @@ class NuHeatThermostat {
79
142
  callback(new Error("Error: setTargetTemperature"));
80
143
  }
81
144
  else {
82
- this.updateValues(response);
145
+ // The v1 write returns 204 with no content, so re-read the authoritative
146
+ // state instead of pushing the empty response into HomeKit.
147
+ await this.updateAccessory();
83
148
  callback(null);
84
149
  }
85
150
  }
@@ -93,6 +158,13 @@ class NuHeatThermostat {
93
158
  }
94
159
  }
95
160
  updateValues(newValues) {
161
+ // Write calls that return 204 No Content resolve to a literal `true`.
162
+ // That is not thermostat data; pushing it would flash garbage temperatures
163
+ // and blank the cached device data until the next poll.
164
+ if (!newValues || typeof newValues !== "object") {
165
+ this.log.debug("Ignoring a thermostat update without payload data", this.deviceData.name);
166
+ return;
167
+ }
96
168
  if (this.isOnline(newValues)) {
97
169
  this.updateTemperatureDisplayUnits();
98
170
  let currentTemperature = Number(this.toHBTemperature(newValues.currentTemperature ?? 0));
@@ -142,13 +214,22 @@ class NuHeatThermostat {
142
214
  return ((((temperature - 33) / 56 + 33 - 32) * 5) / 9).toFixed(1);
143
215
  }
144
216
  toHomeBridgeHeatingCoolingState(newValues) {
145
- if (!this.isOnline(newValues)) {
146
- return Characteristic.TargetHeatingCoolingState.OFF;
217
+ if (!this.enableThermostatModeControl) {
218
+ if (!this.isOnline(newValues)) {
219
+ return Characteristic.TargetHeatingCoolingState.OFF;
220
+ }
221
+ // The v1 read model cannot distinguish standby from a scheduled run, and
222
+ // the characteristic only advertises heat, so heat is the only safe
223
+ // report.
224
+ return Characteristic.TargetHeatingCoolingState.HEAT;
147
225
  }
148
- switch (newValues.operatingMode) {
149
- case NuHeatModels_1.OPERATING_MODE.AUTO:
150
- case NuHeatModels_1.OPERATING_MODE.MANUAL:
151
- return Characteristic.TargetHeatingCoolingState.HEAT;
226
+ switch ((0, NuHeatModels_1.deriveHeatingMode)(newValues)) {
227
+ case NuHeatModels_1.HEATING_MODE.OFF:
228
+ return Characteristic.TargetHeatingCoolingState.OFF;
229
+ case NuHeatModels_1.HEATING_MODE.AUTO:
230
+ return Characteristic.TargetHeatingCoolingState.AUTO;
231
+ case NuHeatModels_1.HEATING_MODE.MANUAL:
232
+ case NuHeatModels_1.HEATING_MODE.HOLD:
152
233
  default:
153
234
  return Characteristic.TargetHeatingCoolingState.HEAT;
154
235
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homebridge-nuheat2",
3
- "version": "1.2.28",
3
+ "version": "1.3.0",
4
4
  "description": "Homebridge Platform for NuHeat Signature Thermostats",
5
5
  "main": "index.js",
6
6
  "scripts": {