homebridge-withings-environment-data 1.3.1 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,39 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## Unreleased
8
8
 
9
+ ## [1.3.3] - 2026-08-04
10
+
11
+ ### Fixed
12
+ - Stale data now correctly shows a fault on the sensors' `StatusFault`
13
+ characteristic too, not just "No Response" in the Home app. A
14
+ successful poll always cleared the fault, even when the reading itself
15
+ was stale, so anything reading `StatusFault` directly instead of
16
+ calling the characteristic's get handler (e.g. Homebridge's own
17
+ accessory list) kept showing the sensors as fine
18
+
19
+ ## [1.3.2] - 2026-08-04
20
+
21
+ ### Added
22
+ - "Retain" checkbox in the MQTT fieldset (default off) to control whether
23
+ published MQTT messages set the retain flag
24
+
25
+ ### Changed
26
+ - "Publish to MQTT" checkbox moved into the collapsed "MQTT" fieldset,
27
+ as its first item
28
+ - MQTT publishing now pauses once the newest reading is past the Stale
29
+ Data Warning Threshold, resuming once a fresher reading comes in —
30
+ previously it kept republishing the same stale reading on every poll
31
+
32
+ ### Fixed
33
+ - MQTT messages are no longer published with the retain flag set by
34
+ default (previously always retained)
35
+ - "Publish to MQTT" and "Retain" checkboxes now actually default to
36
+ unchecked in Config UI (an explicit `"default": false` wasn't being
37
+ applied by the schema form and rendered checked instead)
38
+ - When Retain is off, the plugin now clears any stale retained message
39
+ left on the broker from before (publishing with `retain:false` doesn't
40
+ remove an existing retained message on its own)
41
+
9
42
  ## [1.3.1] - 2026-08-03
10
43
 
11
44
  ### Fixed
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Withings Environment Data v1.3.1
1
+ # Withings Environment Data v1.3.3
2
2
 
3
3
  **This Homebridge plugin has been 100% vibe coded with Claude.**
4
4
 
@@ -55,9 +55,11 @@ turned on or off in Configuration:
55
55
  plugin still polls Withings (and still publishes to MQTT, if enabled),
56
56
  but doesn't create or update any HomeKit accessory.
57
57
  - **Publish to MQTT** (default off): when on, every successful poll
58
- publishes a retained message to topic `withingsenv/ws-50` on the
59
- configured broker, shaped like
60
- `{"temperature": 25.2, "co2_levels": 674}`.
58
+ publishes a message to topic `withingsenv/ws-50` on the configured
59
+ broker, shaped like `{"temperature": 25.2, "co2_levels": 674}`. Messages
60
+ aren't retained unless the Retain option is enabled. Publishing pauses
61
+ once the data is stale (see Stale Data Warning Threshold below) and
62
+ resumes once a fresh reading comes in.
61
63
 
62
64
  ### Configuration
63
65
 
@@ -85,9 +87,10 @@ Fields:
85
87
  Anything above the Inferior boundary is reported as Poor.
86
88
  - **Expose sensors as HomeKit Accessories**: see [Usage](#usage) above.
87
89
  Default on.
88
- - **Publish to MQTT / Host / Port / Username / Password**: see
90
+ - **Publish to MQTT / Host / Port / Username / Password / Retain**: see
89
91
  [Usage](#usage) above. Publishing is off by default; Port defaults to
90
92
  1883. Username/Password are optional, for brokers that require auth.
93
+ Retain is off by default.
91
94
  - **Stale Data Warning Threshold (hours)**: if the newest reading from the
92
95
  scale itself (not the plugin's poll) is older than this many hours — e.g.
93
96
  nobody's stood on the scale in a while — a warning is logged on every
@@ -82,7 +82,6 @@
82
82
  "publishToMqtt": {
83
83
  "title": "Publish to MQTT",
84
84
  "type": "boolean",
85
- "default": false,
86
85
  "description": "Publish sensor data to configured MQTT broker. Topic name: \"withingsenv/ws-50\""
87
86
  },
88
87
  "mqttHost": {
@@ -107,6 +106,11 @@
107
106
  "type": "password"
108
107
  }
109
108
  },
109
+ "mqttRetain": {
110
+ "title": "Retain",
111
+ "type": "boolean",
112
+ "description": "Publish messages with the MQTT retain flag set, so new subscribers immediately get the last known reading."
113
+ },
110
114
  "noResponseAfterMissedPolls": {
111
115
  "title": "No Response After Missed Polls",
112
116
  "type": "integer",
@@ -143,17 +147,18 @@
143
147
  ]
144
148
  },
145
149
  "exposeAsHomekitAccessories",
146
- "publishToMqtt",
147
150
  {
148
151
  "type": "fieldset",
149
152
  "title": "MQTT",
150
153
  "expandable": true,
151
154
  "expanded": false,
152
155
  "items": [
156
+ "publishToMqtt",
153
157
  "mqttHost",
154
158
  "mqttPort",
155
159
  "mqttUsername",
156
- "mqttPassword"
160
+ "mqttPassword",
161
+ "mqttRetain"
157
162
  ]
158
163
  },
159
164
  {
package/index.js CHANGED
@@ -239,13 +239,21 @@ class WithingsEnvironmentDataPlatform {
239
239
  password: this.config.mqttPassword || undefined,
240
240
  });
241
241
  this.mqttClient.on('error', (err) => this.log.warn(`MQTT connection error: ${err.message}`));
242
+ if (this.config.mqttRetain !== true) {
243
+ // A publish with retain:false does NOT clear a previously-retained message —
244
+ // the broker keeps serving the last retained one until something explicitly
245
+ // clears it. Do that once per connect so turning Retain off actually stops
246
+ // new subscribers from seeing stale data.
247
+ this.mqttClient.on('connect', () => this.mqttClient.publish(MQTT_TOPIC, '', { retain: true }));
248
+ }
242
249
  this.api.on('shutdown', () => this.mqttClient.end());
243
250
  }
244
251
 
245
252
  publishMqttReading() {
246
253
  if (!this.mqttClient) return;
254
+ if (this.isDataStale()) return;
247
255
  const payload = JSON.stringify({ temperature: this.lastReading.temperature, co2_levels: this.lastReading.co2 });
248
- this.mqttClient.publish(MQTT_TOPIC, payload, { retain: true });
256
+ this.mqttClient.publish(MQTT_TOPIC, payload, { retain: this.config.mqttRetain === true });
249
257
  }
250
258
 
251
259
  setupServices(accessory) {
@@ -346,6 +354,16 @@ class WithingsEnvironmentDataPlatform {
346
354
  // quiet (no one's stood on it) while polls keep succeeding fine, so this
347
355
  // is checked every cycle against whatever the newest reading actually is.
348
356
  await this.checkStaleData();
357
+
358
+ // A successful poll above already cleared the fault via setFault(false),
359
+ // even though the reading it just fetched can itself be stale. Re-assert
360
+ // the fault in that case so anything reading StatusFault directly (e.g.
361
+ // Homebridge's own accessory list, which shows cached values rather than
362
+ // invoking the onGet handlers the way the Home app does) reflects
363
+ // staleness too, not just throwIfStale()'s "No Response" to HomeKit.
364
+ if (this.isDataStale()) {
365
+ this.setFault(true);
366
+ }
349
367
  }
350
368
 
351
369
  async sendNtfyNotification(message, title = 'Homebridge: Getting Withings Environment Data Failed!') {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "homebridge-withings-environment-data",
3
3
  "displayName": "Withings Environment Data",
4
- "version": "1.3.1",
4
+ "version": "1.3.3",
5
5
  "description": "Homebridge plugin exposing ambient CO2/air-quality and room temperature readings from a Withings WS-50 scale as HomeKit sensors",
6
6
  "main": "index.js",
7
7
  "files": [