Skip to content

Commit 587d9f3

Browse files
committed
Requests latest readings based on send_interval, next_checkin, and wifi_connect_time
Fixes: - Correctly logs detached probe - Names probe based on probe-type - Add config delay if `wifi_connect_time` is not long enough for sensor to update.
1 parent 0de440f commit 587d9f3

6 files changed

Lines changed: 122 additions & 270 deletions

File tree

README.md

Lines changed: 21 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -2,207 +2,38 @@
22

33
<img src="https://github.com/homebridge/branding/raw/latest/logos/homebridge-wordmark-logo-vertical.png" width="150">
44

5+
6+
<p align="center">
7+
<a href="https://www.npmjs.com/package/homebridge-tempstick"><img title="npm version" src="https://badgen.net/npm/v/homebridge-tempstick?label=stable"></a>
8+
<a href="https://www.npmjs.com/package/homebridge-tempstick"><img title="npm downloads" src="https://badgen.net/npm/dt/homebridge-tempstick"></a>
9+
<a href="https://github.com/gorhack/tempstick/actions/workflows/build.yml"><img title="Node Build" src="https://github.com/gorhack/tempstick/actions/workflows/build.yml/badge.svg"></a>
510
</p>
611

712
# Ideal Sciences Temp Stick Homebridge Plugin
813

9-
This is an unnofficial plugin to use your [Temp Stick](https://tempstick.com/) sensor with Homebridge.
14+
### This is an unofficial plugin to use your [Temp Stick](https://tempstick.com/) sensor with [Homebridge](https://homebridge.io/).
1015

1116
You will need your API key, provided in your [account](https://mytempstick.com/account#developers) settings. This plugin relies on the API provided by Temp
1217
Stick and is dependent on its uptime to retrieve your latest sensors and readings.
1318

19+
Once loaded, this plugin will display all Temp Stick sensors' ambient temperature and humidity. If you are using a
20+
thermocouple probe, it will also display the probe's temperature. This plugin updates the sensor data at roughly the
21+
same interval set within your account's `Sensor Settings` (once every 15 minutes to 24 hours). Temp Stick, nor this
22+
plugin, will display live Temp Stick readings as the sensor is only active during its `next_checkin`.
23+
24+
If you change any settings or names in your Temp Stick account you may have to reload the plugin to see those changes
25+
reflected and receive timely results.
26+
1427
### Development Roadmap:
1528
- [x] Discover all sensors and probes
1629
- [x] Ambient temperature, ambient humidity, and probe temperature
1730
- [x] Handle API errors gracefully
18-
- [ ] Use offsets (`probe_temp_offset`, `humidity_offset`, `temp_offset`) for calibrated sensors
19-
- [ ] Request latest readings based on `send_interval` and `next_checkin`
31+
- [x] Use offsets (`probe_temp_offset`, `humidity_offset`, `temp_offset`) for calibrated sensors
32+
- `last_tcTemp`, `last_humidity`, and `last_temp` include any user-set offset
33+
- [x] Request latest readings based on `send_interval` and `next_checkin`
2034
- [ ] Homebridge [verified](https://github.com/homebridge/verified)
21-
- [ ] Request updated documentation in [API](https://tempstickapi.com/docs/) for undocumented parameters
35+
- [x] Request updated documentation in [API](https://tempstickapi.com/docs/) for undocumented parameters
2236
(`last_tcTemp` and `groups` for example)
23-
24-
<span align="center">
25-
26-
# Homebridge Platform Plugin Template
27-
28-
</span>
29-
30-
This is a template Homebridge dynamic platform plugin and can be used as a base to help you get started developing your own plugin.
31-
32-
This template should be used in conjunction with the [developer documentation](https://developers.homebridge.io/). A full list of all supported service types, and their characteristics is available on this site.
33-
34-
### Clone As Template
35-
36-
Click the link below to create a new GitHub Repository using this template, or click the *Use This Template* button above.
37-
38-
<span align="center">
39-
40-
### [Create New Repository From Template](https://github.com/homebridge/homebridge-plugin-template/generate)
41-
42-
</span>
43-
44-
### Setup Development Environment
45-
46-
To develop Homebridge plugins you must have Node.js 18 or later installed, and a modern code editor such as [VS Code](https://code.visualstudio.com/). This plugin template uses [TypeScript](https://www.typescriptlang.org/) to make development easier and comes with pre-configured settings for [VS Code](https://code.visualstudio.com/) and ESLint. If you are using VS Code install these extensions:
47-
48-
- [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
49-
50-
### Install Development Dependencies
51-
52-
Using a terminal, navigate to the project folder and run this command to install the development dependencies:
53-
54-
```shell
55-
npm install
56-
```
57-
58-
### Update package.json
59-
60-
Open the [`package.json`](./package.json) and change the following attributes:
61-
62-
- `name` - this should be prefixed with `homebridge-` or `@username/homebridge-`, is case-sensitive, and contains no spaces nor special characters apart from a dash `-`
63-
- `displayName` - this is the "nice" name displayed in the Homebridge UI
64-
- `repository.url` - Link to your GitHub repo
65-
- `bugs.url` - Link to your GitHub repo issues page
66-
67-
When you are ready to publish the plugin you should set `private` to false, or remove the attribute entirely.
68-
69-
### Update Plugin Defaults
70-
71-
Open the [`src/settings.ts`](./src/settings.ts) file and change the default values:
72-
73-
- `PLATFORM_NAME` - Set this to be the name of your platform. This is the name of the platform that users will use to register the plugin in the Homebridge `config.json`.
74-
- `PLUGIN_NAME` - Set this to be the same name you set in the [`package.json`](./package.json) file.
75-
76-
Open the [`config.schema.json`](./config.schema.json) file and change the following attribute:
77-
78-
- `pluginAlias` - set this to match the `PLATFORM_NAME` you defined in the previous step.
79-
80-
### Build Plugin
81-
82-
TypeScript needs to be compiled into JavaScript before it can run. The following command will compile the contents of your [`src`](./src) directory and put the resulting code into the `dist` folder.
83-
84-
```shell
85-
npm run build
86-
```
87-
88-
### Link To Homebridge
89-
90-
Run this command so your global installation of Homebridge can discover the plugin in your development environment:
91-
92-
```shell
93-
npm link
94-
```
95-
96-
You can now start Homebridge, use the `-D` flag, so you can see debug log messages in your plugin:
97-
98-
```shell
99-
homebridge -D
100-
```
101-
102-
### Watch For Changes and Build Automatically
103-
104-
If you want to have your code compile automatically as you make changes, and restart Homebridge automatically between changes, you first need to add your plugin as a platform in `~/.homebridge/config.json`:
105-
```
106-
{
107-
...
108-
"platforms": [
109-
{
110-
"name": "Config",
111-
"port": 8581,
112-
"platform": "config"
113-
},
114-
{
115-
"name": "<PLUGIN_NAME>",
116-
//... any other options, as listed in config.schema.json ...
117-
"platform": "<PLATFORM_NAME>"
118-
}
119-
]
120-
}
121-
```
122-
123-
and then you can run:
124-
125-
```shell
126-
npm run watch
127-
```
128-
129-
This will launch an instance of Homebridge in debug mode which will restart every time you make a change to the source code. It will load the config stored in the default location under `~/.homebridge`. You may need to stop other running instances of Homebridge while using this command to prevent conflicts. You can adjust the Homebridge startup command in the [`nodemon.json`](./nodemon.json) file.
130-
131-
### Customise Plugin
132-
133-
You can now start customising the plugin template to suit your requirements.
134-
135-
- [`src/platform.ts`](./src/platform.ts) - this is where your device setup and discovery should go.
136-
- [`src/platformAccessory.ts`](./src/platformAccessory.ts) - this is where your accessory control logic should go, you can rename or create multiple instances of this file for each accessory type you need to implement as part of your platform plugin. You can refer to the [developer documentation](https://developers.homebridge.io/) to see what characteristics you need to implement for each service type.
137-
- [`config.schema.json`](./config.schema.json) - update the config schema to match the config you expect from the user. See the [Plugin Config Schema Documentation](https://developers.homebridge.io/#/config-schema).
138-
139-
### Versioning Your Plugin
140-
141-
Given a version number `MAJOR`.`MINOR`.`PATCH`, such as `1.4.3`, increment the:
142-
143-
1. **MAJOR** version when you make breaking changes to your plugin,
144-
2. **MINOR** version when you add functionality in a backwards compatible manner, and
145-
3. **PATCH** version when you make backwards compatible bug fixes.
146-
147-
You can use the `npm version` command to help you with this:
148-
149-
```shell
150-
# major update / breaking changes
151-
npm version major
152-
153-
# minor update / new features
154-
npm version update
155-
156-
# patch / bugfixes
157-
npm version patch
158-
```
159-
160-
### Publish Package
161-
162-
When you are ready to publish your plugin to [npm](https://www.npmjs.com/), make sure you have removed the `private` attribute from the [`package.json`](./package.json) file then run:
163-
164-
```shell
165-
npm publish
166-
```
167-
168-
If you are publishing a scoped plugin, i.e. `@username/homebridge-xxx` you will need to add `--access=public` to command the first time you publish.
169-
170-
#### Publishing Beta Versions
171-
172-
You can publish *beta* versions of your plugin for other users to test before you release it to everyone.
173-
174-
```shell
175-
# create a new pre-release version (eg. 2.1.0-beta.1)
176-
npm version prepatch --preid beta
177-
178-
# publish to @beta
179-
npm publish --tag=beta
180-
```
181-
182-
Users can then install the *beta* version by appending `@beta` to the install command, for example:
183-
184-
```shell
185-
sudo npm install -g homebridge-example-plugin@beta
186-
```
187-
188-
### Best Practices
189-
Consider creating your plugin with the [Homebridge Verified](https://github.com/homebridge/verified) criteria in mind. This will help you to create a plugin that is easy to use and works well with Homebridge.
190-
You can then submit your plugin to the Homebridge Verified list for review.
191-
The most up-to-date criteria can be found [here](https://github.com/homebridge/verified#requirements).
192-
For reference, the current criteria are:
193-
194-
- The plugin must successfully install.
195-
- The plugin must implement the [Homebridge Plugin Settings GUI](https://github.com/oznu/homebridge-config-ui-x/wiki/Developers:-Plugin-Settings-GUI).
196-
- The plugin must not start unless it is configured.
197-
- The plugin must not execute post-install scripts that modify the users' system in any way.
198-
- The plugin must not contain any analytics or calls that enable you to track the user.
199-
- The plugin must not throw unhandled exceptions, the plugin must catch and log its own errors.
200-
- The plugin must be published to npm and the source code available on GitHub.
201-
- A GitHub release - with patch notes - should be created for every new version of your plugin.
202-
- The plugin must run on all [supported LTS versions of Node.js](https://github.com/homebridge/homebridge/wiki/How-To-Update-Node.js), at the time of writing this is Node.js v16 and v18.
203-
- The plugin must not require the user to run Homebridge in a TTY or with non-standard startup parameters, even for initial configuration.
204-
- If the plugin needs to write files to disk (cache, keys, etc.), it must store them inside the Homebridge storage directory.
205-
206-
### Useful Links
207-
Note these links are here for help but are not supported/verified by the Homebridge team
208-
- [Custom Characteristics](https://github.com/homebridge/homebridge-plugin-template/issues/20)
37+
- Response: "...you don't need to worry about these values as they don't have a direct impact
38+
on the data readings"
39+
- [ ] User config `groups` of sensors instead of retrieving all sensors

config.schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
"required": true,
1818
"pattern": "^[A-Za-z0-9]*$",
1919
"description": "Found at https://mytempstick.com/account#developers"
20+
},
21+
"delay": {
22+
"title": "Delay (in seconds)",
23+
"type": "number",
24+
"required": false,
25+
"placeholder": "5",
26+
"pattern": "^[0-9]*$",
27+
"description": "Add an additional delay if your Homekit readings are behind your Temp Stick readings."
2028
}
2129
}
2230
}

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"name": "homebridge-tempstick",
44
"version": "1.0.3",
55
"description": "Unofficial Ideal Sciences TempStick homebridge plugin.",
6+
"homepage": "https://github.com/gorhack/tempstick",
67
"license": "Apache-2.0",
78
"type": "module",
89
"repository": {
@@ -19,12 +20,15 @@
1920
"main": "dist/index.js",
2021
"scripts": {
2122
"lint": "eslint src/**/*.ts --max-warnings=0",
22-
"watch": "npm run build && sudo hb-service unlink && sudo hb-service link && nodemon",
23+
"watch": "npm run build && sudo hb-service unlink || true && sudo hb-service link && nodemon",
2324
"build": "rimraf ./dist && tsc",
2425
"prepublishOnly": "npm run lint && npm run build"
2526
},
2627
"keywords": [
27-
"homebridge-plugin"
28+
"homebridge-plugin",
29+
"temp stick",
30+
"tempstick",
31+
"ideal sciences"
2832
],
2933
"devDependencies": {
3034
"@types/node": "^20.14.10",

src/platform.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ export class TempStickHomebridgePlatform implements DynamicPlatformPlugin {
6363
* must not be registered again to prevent "duplicate UUID" errors.
6464
*/
6565
discoverDevices() {
66+
if (!this.config.apiKey) {
67+
this.log.error('Must have an API key configured in the plugin configuration.');
68+
return;
69+
}
6670
this.log.debug('Discovering devices with apikey ' + this.config.apiKey);
6771
(async () => {
6872
try {
@@ -111,12 +115,12 @@ export class TempStickHomebridgePlatform implements DynamicPlatformPlugin {
111115
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
112116
}
113117

114-
// TODO use calibrated settings: probe_temp_offset, humidity_offset, temp_offset
115118
this.log.info(`Initialized accessory ${sensor.sensor_name}. ` +
116119
`It is ${parseInt(sensor.offline) ? 'offline' : 'online'}. ` +
117120
`The latest ambient temp was ${sensor.last_temp}°C, ` +
118121
`ambient humidity of ${sensor.last_humidity}%, ` +
119-
`${sensor.last_tcTemp ? `probe temp of ${sensor.last_tcTemp}°C ` : ''}` +
122+
`${sensor.last_tcTemp && sensor.last_tcTemp !== 'n' && sensor.TC_TYPE ?
123+
`${sensor.TC_TYPE}-probe temp of ${sensor.last_tcTemp}°C, ` : ''}` +
120124
`and battery level at ${sensor.battery_pct}%`);
121125
});
122126

0 commit comments

Comments
 (0)