bt-sensors-plugin-sk 1.1.0-beta.2.1.4 → 1.1.0-beta.2.1.4.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/index.js CHANGED
@@ -414,7 +414,7 @@ module.exports = function (app) {
414
414
  if (plugin.schema.properties.peripherals.items.dependencies)
415
415
  plugin.schema.properties.peripherals.items.dependencies.mac_address.oneOf=[]
416
416
  } else {
417
- app.debug('Plugin build 2024.10.08 started');
417
+ app.debug('Plugin build Beta 2.4.1.2 started');
418
418
 
419
419
  }
420
420
  starts++
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bt-sensors-plugin-sk",
3
- "version": "1.1.0-beta.2.1.4",
4
- "description": "Bluetooth Sensors for Signalk -- support for Victron devices, RuuviTag, Xiaomi, ATC and Inkbird, Ultrasonic, Mopeka tank reader ",
3
+ "version": "1.1.0-beta.2.1.4.2",
4
+ "description": "Bluetooth Sensors for Signalk -- support for Victron devices, RuuviTag, Xiaomi, ATC and Inkbird, Ultrasonic, Mopeka tank reader and preliminary support for Govee GVH51xx temp sensors",
5
5
  "main": "index.js",
6
6
  "dependencies": {
7
7
  "dbus-next": "^0.10.2",
@@ -0,0 +1,66 @@
1
+ const BTSensor = require("../BTSensor");
2
+ function decodeTempHumid(tempHumidBytes) {
3
+ // Convert the bytes to a 24-bit integer
4
+ const baseNum = (tempHumidBytes[0] << 16) + (tempHumidBytes[1] << 8) + tempHumidBytes[2];
5
+
6
+ // Check if the temperature is negative
7
+ const isNegative = (baseNum & 0x800000) !== 0;
8
+
9
+ // Extract the temperature and humidity values
10
+ const tempAsInt = baseNum & 0x7FFFFF;
11
+ const tempAsFloat = (tempAsInt / 1000) / 10.0;
12
+ const humid = (tempAsInt % 1000) / 10.0;
13
+
14
+ // Apply the negative sign if necessary
15
+ if (isNegative) {
16
+ return {t:-tempAsFloat, h: humid};
17
+ } else {
18
+ return {t: tempAsFloat, h: humid};
19
+ }
20
+ }
21
+ class GoveeTH extends BTSensor{
22
+
23
+ static async identify(device){
24
+ const regex = /^GVH5[0-9]{3}_[a-f,A-F,0-9]{4}$/
25
+ const name = await this.getDeviceProp(device,"Name")
26
+ const uuids = await this.getDeviceProp(device,'UUIDs')
27
+
28
+ if (name && name.match(regex) &&
29
+ uuids && uuids.length > 0 &&
30
+ uuids[0] == '0000ec88-0000-1000-8000-00805f9b34fb')
31
+ return this
32
+ else
33
+ return null
34
+
35
+ }
36
+
37
+ async init(){
38
+ await super.init()
39
+ }
40
+ initMetadata(){
41
+ this.addMetadatum('temp','K', 'temperature')
42
+ this.addMetadatum('battery','ratio', 'battery strength')
43
+ this.addMetadatum('humidity','ratio', 'humidity')
44
+ }
45
+
46
+ emitValuesFrom(buffer){
47
+ const th = decodeTempHumid(buffer.subarray(2,5))
48
+ this.emit("temp", parseFloat((273.15+th.t).toFixed(2))) ;
49
+ this.emit("humidity", th.h/100 )
50
+ this.emit('battery', buffer[5]/100)
51
+ }
52
+
53
+ getManufacturer(){
54
+ return "Govee"
55
+ }
56
+ async propertiesChanged(props){
57
+ super.propertiesChanged(props)
58
+ if (props.ManufacturerData) {
59
+ const buffer = this.getManufacturerData(0x0001)
60
+ if (buffer) {
61
+ this.emitValuesFrom(buffer)
62
+ }
63
+ }
64
+ }
65
+ }
66
+ module.exports=GoveeTH
@@ -267,7 +267,7 @@ class MopekaTankSensor extends BTSensor{
267
267
 
268
268
  _tankLevel( rawLevel ){
269
269
  const coefs= this.getMedium().coefficients
270
- return rawLevel * (coefs[0] + (coefs[1] * this.temp) + (coefs[2] * (this.temp^2)))
270
+ return rawLevel * (coefs[0] + (coefs[1] * (this.temp-273.15)) + (coefs[2] * ((this.temp-273.15)^2)))
271
271
  }
272
272
 
273
273
  initMetadata(){
@@ -275,6 +275,9 @@ class MopekaTankSensor extends BTSensor{
275
275
  md.isParam=true
276
276
  md.enum=Object.keys(Media)
277
277
 
278
+ md = this.addMetadatum("tankHeight","mm","height of tank (in mm)")
279
+ md.isParam=true
280
+
278
281
  this.addMetadatum("battVolt","V","sensor battery in volts",
279
282
  ((buffer)=>{
280
283
  this.battVolt = (buffer.readUInt8(1)/32)
@@ -291,7 +294,7 @@ class MopekaTankSensor extends BTSensor{
291
294
  }).bind(this)
292
295
  )
293
296
  this.addMetadatum("tankLevel","m","tank level",
294
- (buffer)=>{ return this._tankLevel(((buffer.readUInt16LE(3))&0x3FFF)*10)/1000}
297
+ (buffer)=>{ return this._tankLevel(((buffer.readUInt16LE(3))&0x3FFF))}
295
298
  )
296
299
  this.addMetadatum("readingQuality","","quality of read",
297
300
  (buffer)=>{ return buffer.readUInt8(4)>>6}
@@ -24,7 +24,7 @@ class VictronSolarCharger extends VictronSensor{
24
24
  this.addMetadatum('solarPower','W', 'solar power',
25
25
  (buff)=>{return this.NaNif(buff.readUInt16LE(8),0xFFFF)})
26
26
  this.addMetadatum('externalDeviceLoad','A', 'external device load',
27
- (buff)=>{return this.NaNif(buff.readUInt16BE(10)>>7,0x1FF)})
27
+ (buff)=>{return this.NaNif(buff.readUInt16LE(10)&0x1FF,0x1FF)/10})
28
28
  }
29
29
  }
30
30
  module.exports=VictronSolarCharger