bt-sensors-plugin-sk 1.1.0-beta.2.2.1.5 → 1.1.0-beta.2.2.2
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/README.md +7 -1
- package/package.json +3 -2
- package/sensor_classes/BTHome/AbstractBTHomeSensor.js +199 -0
- package/sensor_classes/BTHome/BTHomeServiceData.js +2289 -0
- package/sensor_classes/LancolVoltageMeter.js +39 -0
- package/sensor_classes/ShellySBHT003C.js +109 -0
- package/sensor_classes/VictronBatteryMonitor.js +3 -3
package/README.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Bluetooth Sensors for [Signal K](http://www.signalk.org)
|
|
2
2
|
|
|
3
|
+
## BETA 2.2.2
|
|
4
|
+
### What's New
|
|
5
|
+
Support for Lancol Battery Meters, Kilovault HLX+ smart batteries courtesy of [sdlee1963](https://github.com/sdlee1963) and baseline support for BTHome devices as well as support for the ShellySBHT003C enviromental sensor courtesy of [Sebastian Haas](https://github.com/sebastianhaas)
|
|
6
|
+
|
|
7
|
+
Fixed incorrect reporting of Victron Battery Monitor -> aux temperature values.
|
|
8
|
+
|
|
3
9
|
## BETA 2.2.1
|
|
4
10
|
|
|
5
11
|
### What's New
|
|
@@ -24,7 +30,7 @@ On the plugin config page, You will need to select the device from the Device dr
|
|
|
24
30
|
|
|
25
31
|
BT Sensors Plugin for Signalk is a lightweight BLE (Bluetooth Low Energy) framework for listening and connecting to Bluetooth sensors on your boat and sending deltas to Signalk paths with the values the sensors reports. <br>
|
|
26
32
|
|
|
27
|
-
The Plugin currently supports every documented Victron device (AC Charger, Battery Monitor, DC-DC Converter, DC Energy Meter, GX Device, Inverter, Inverter RS, Lynx Smart BMS, Orion XS, Smart Battery Protect, Smart Lithium and VE Bus), Xiaomi devices, [ATC devices](https://github.com/atc1441/ATC_MiThermometer), RuuviTags and Inkbird thermometers.
|
|
33
|
+
The Plugin currently supports every documented Victron device (AC Charger, Battery Monitor, DC-DC Converter, DC Energy Meter, GX Device, Inverter, Inverter RS, Lynx Smart BMS, Orion XS, Smart Battery Protect, Smart Lithium and VE Bus), [Lancol Battery Meters ](https://www.lancol.com/product/12v-bluetooth-4-0-battery-tester-micro-10-c/), [Kilovault HLX+ smart batteries ](https://sunwatts.com/content/manual/KiloVault_HLX_PLUS_Datasheet_06252021%20%281%29.pdf?srsltid=AfmBOooY-cGnC_Qm6V1T9Vg5oZzBCJurS0AOGoWqWeyy-dwz2vA-l1Jb), Xiaomi devices, [ATC devices](https://github.com/atc1441/ATC_MiThermometer), RuuviTags, Renogy BMS, Ultrasonic Wind Meters, SwitchBotTH and Meterplus, Aranet 2/4 environmental sensors, Govee 50/51xx sensors, and Inkbird thermometers.
|
|
28
34
|
|
|
29
35
|
A typical use case is a Bluetooth thermometer like the Xiaomi LYWSD03MMC, an inexpensive Bluetooth thermometer that runs on a 3V watch battery that can report the current temperature and humidity in your refrigerator or cabin or wherever you want to stick it (no judgement.) <br>
|
|
30
36
|
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bt-sensors-plugin-sk",
|
|
3
|
-
"version": "1.1.0-beta.2.2.
|
|
3
|
+
"version": "1.1.0-beta.2.2.2",
|
|
4
4
|
"description": "Bluetooth Sensors for Signalk -- support for Victron devices, RuuviTag, Xiaomi, ATC and Inkbird, Ultrasonic wind meters, Mopeka tank readers, Renogy Battery and Solar Controllers, Aranet4 environment sensors, SwitchBot temp and humidity sensors, KilovaultHLXPlus smart batteries, and Govee GVH51xx temp sensors",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"dbus-next": "^0.10.2",
|
|
8
8
|
"node-ble": "^1.12.0",
|
|
9
|
-
"int24":"^0.0.1"
|
|
9
|
+
"int24":"^0.0.1",
|
|
10
|
+
"kaitai-struct": "^0.10.0"
|
|
10
11
|
},
|
|
11
12
|
"scripts": {
|
|
12
13
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
const BTSensor = require("../../BTSensor");
|
|
2
|
+
const BTHomeServiceData = require("./BTHomeServiceData");
|
|
3
|
+
const KaitaiStream = require("kaitai-struct/KaitaiStream");
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Base class for sensors publishing BTHome data.
|
|
7
|
+
*
|
|
8
|
+
* BTHome is an open standard for broadcasting sensor data and button presses over Bluetooth LE.
|
|
9
|
+
*
|
|
10
|
+
* @abstract
|
|
11
|
+
* @see https://bthome.io/
|
|
12
|
+
*/
|
|
13
|
+
class AbstractBTHomeSensor extends BTSensor {
|
|
14
|
+
/**
|
|
15
|
+
* Offset from Celsius to Kelvin, used to convert between these units.
|
|
16
|
+
* 273.15 degrees Kelvin correspond to 0 degrees Celsius.
|
|
17
|
+
*/
|
|
18
|
+
static KELVIN_OFFSET = 273.15;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* BTHome Service identifier
|
|
22
|
+
*
|
|
23
|
+
* @type {string} The Service UUID
|
|
24
|
+
* @see https://bthome.io/images/License_Statement_-_BTHOME.pdf
|
|
25
|
+
*/
|
|
26
|
+
static BTHOME_SERVICE_ID = "0000fcd2-0000-1000-8000-00805f9b34fb";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Returns measurement data for the given object ID from the given BTHomeData.
|
|
30
|
+
*
|
|
31
|
+
* @param btHomeData {BTHomeServiceData.BthomeServiceData}
|
|
32
|
+
* @param objectId {number}
|
|
33
|
+
* @return {any|null} Returns the measurement data for the given object ID, or `null`, if the BTHomeData does not
|
|
34
|
+
* contain the measurement.
|
|
35
|
+
*/
|
|
36
|
+
static getSensorDataByObjectId(btHomeData, objectId) {
|
|
37
|
+
return btHomeData.measurement.find((m) => m.objectId === objectId)?.data;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Returns whether the specified device's advertisement contains BTHome service data or not.
|
|
42
|
+
*
|
|
43
|
+
* This method should be included in the {@link BTSensor#identify} method of inheriting sensor classes.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* static async identify(device) {
|
|
47
|
+
* if (await this.hasBtHomeServiceData(device)) {
|
|
48
|
+
* // Additional checks to distinguish from other BTHome devices
|
|
49
|
+
* return YourSensorClass;
|
|
50
|
+
* }
|
|
51
|
+
* return null;
|
|
52
|
+
* }
|
|
53
|
+
* @see BTSensor#identify
|
|
54
|
+
* @param device The Bluetooth device to check for BTHome data.
|
|
55
|
+
* @returns {Promise<boolean>} Returns `true`, if the device exposes BTHome service data, or `false`,
|
|
56
|
+
* if not.
|
|
57
|
+
*/
|
|
58
|
+
static async hasBtHomeServiceData(device) {
|
|
59
|
+
const serviceData = await AbstractBTHomeSensor.getDeviceProp(
|
|
60
|
+
device,
|
|
61
|
+
"ServiceData",
|
|
62
|
+
);
|
|
63
|
+
if (serviceData) {
|
|
64
|
+
if (AbstractBTHomeSensor.BTHOME_SERVICE_ID in serviceData) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Returns whether the specified device has a given name.
|
|
73
|
+
*
|
|
74
|
+
* This method can be included in the {@link BTSensor#identify} method of inheriting sensor classes.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* static async identify(device) {
|
|
78
|
+
* if (await this.hasName(device)) {
|
|
79
|
+
* // Additional checks, if required
|
|
80
|
+
* return YourSensorClass;
|
|
81
|
+
* }
|
|
82
|
+
* return null;
|
|
83
|
+
* }
|
|
84
|
+
* @see BTSensor#identify
|
|
85
|
+
* @param device The Bluetooth device to check the name.
|
|
86
|
+
* @param name {string} The name to be checked for.
|
|
87
|
+
* @returns {Promise<boolean>} Returns `true`, if the device exposes BTHome service data, or `false`,
|
|
88
|
+
* if not.
|
|
89
|
+
*/
|
|
90
|
+
static async hasName(device, name) {
|
|
91
|
+
const deviceName = await AbstractBTHomeSensor.getDeviceProp(device, "Name");
|
|
92
|
+
if (deviceName) {
|
|
93
|
+
if (deviceName === name) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Extracts battery level from the given BTHome data.
|
|
102
|
+
*
|
|
103
|
+
* @param btHomeData {BTHomeServiceData.BthomeServiceData} The BTHome data provided by the device.
|
|
104
|
+
* @returns {number|null} The device's battery level as ratio (0‒1).
|
|
105
|
+
*/
|
|
106
|
+
static parseBatteryLevel(btHomeData) {
|
|
107
|
+
const batteryLevel = AbstractBTHomeSensor.getSensorDataByObjectId(
|
|
108
|
+
btHomeData,
|
|
109
|
+
BTHomeServiceData.BthomeObjectId.SENSOR_BATTERY,
|
|
110
|
+
)?.battery;
|
|
111
|
+
if (batteryLevel) {
|
|
112
|
+
return Number.parseFloat((batteryLevel / 100.0).toFixed(2));
|
|
113
|
+
}
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Extracts temperature from the given BTHome data and converts it to Kelvin for Signal-K.
|
|
119
|
+
*
|
|
120
|
+
* @param btHomeData {BTHomeServiceData.BthomeServiceData} The BTHome data provided by the device.
|
|
121
|
+
* @returns {number|null} The temperature in Kelvin.
|
|
122
|
+
*/
|
|
123
|
+
static parseTemperature(btHomeData) {
|
|
124
|
+
const tempCelsius = AbstractBTHomeSensor.getSensorDataByObjectId(
|
|
125
|
+
btHomeData,
|
|
126
|
+
BTHomeServiceData.BthomeObjectId.SENSOR_TEMPERATURE_0_1,
|
|
127
|
+
)?.temperature;
|
|
128
|
+
if (tempCelsius) {
|
|
129
|
+
return Number.parseFloat(
|
|
130
|
+
(AbstractBTHomeSensor.KELVIN_OFFSET + tempCelsius).toFixed(2),
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Extracts humidity from the given BTHome data.
|
|
138
|
+
*
|
|
139
|
+
* @param btHomeData {BTHomeServiceData.BthomeServiceData} The BTHome data provided by the device.
|
|
140
|
+
* @returns {number|null} The relative humidity as ratio (0‒1).
|
|
141
|
+
*/
|
|
142
|
+
static parseHumidity(btHomeData) {
|
|
143
|
+
const humidity = AbstractBTHomeSensor.getSensorDataByObjectId(
|
|
144
|
+
btHomeData,
|
|
145
|
+
BTHomeServiceData.BthomeObjectId.SENSOR_HUMIDITY,
|
|
146
|
+
)?.humidity;
|
|
147
|
+
if (humidity) {
|
|
148
|
+
return Number.parseFloat((humidity / 100.0).toFixed(2));
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Extracts button press event from the given BTHome data.
|
|
155
|
+
*
|
|
156
|
+
* @param btHomeData {BTHomeServiceData.BthomeServiceData} The BTHome data provided by the device.
|
|
157
|
+
* @returns {BTHomeServiceData.ButtonEventType|null} The device's button press state.
|
|
158
|
+
*/
|
|
159
|
+
static parseButton(btHomeData) {
|
|
160
|
+
const buttonEvent = AbstractBTHomeSensor.getSensorDataByObjectId(
|
|
161
|
+
btHomeData,
|
|
162
|
+
BTHomeServiceData.BthomeObjectId.EVENT_BUTTON,
|
|
163
|
+
)?.event;
|
|
164
|
+
if (buttonEvent) {
|
|
165
|
+
return buttonEvent;
|
|
166
|
+
}
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
propertiesChanged(props) {
|
|
171
|
+
super.propertiesChanged(props);
|
|
172
|
+
|
|
173
|
+
// Make sure the advertisement contains service data, which is not the case for, e.g., RSSI events
|
|
174
|
+
if (!Object.hasOwn(props, "ServiceData")) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Retrieve BTHome data
|
|
179
|
+
const buffer = this.getServiceData(AbstractBTHomeSensor.BTHOME_SERVICE_ID);
|
|
180
|
+
if (!buffer) {
|
|
181
|
+
this.debug(
|
|
182
|
+
`ServiceData does not contain BTHome service, which is unexpected for ${this.getDisplayName()}`,
|
|
183
|
+
);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
try {
|
|
188
|
+
// Parse ServiceData according to the BTHome v2 format (https://bthome.io/format/) and emit sensor data
|
|
189
|
+
const btHomeData = new BTHomeServiceData(new KaitaiStream(buffer));
|
|
190
|
+
this.emitValuesFrom(btHomeData);
|
|
191
|
+
} catch (e) {
|
|
192
|
+
throw new Error(
|
|
193
|
+
`Unable to parse BTHome data for ${this.getDisplayName()}`,
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
module.exports = AbstractBTHomeSensor;
|