bt-sensors-plugin-sk 1.3.0 → 1.3.2-1

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.
@@ -18,6 +18,14 @@ const ProtectionStatus = {
18
18
  0x4000: "Short Circuit Protection"
19
19
  }
20
20
 
21
+ const BatteryState = {
22
+ 0: "Discharging/Idle",
23
+ 1: "Charging",
24
+ 2: "Discharging",
25
+ 4: "Charge Disabled"
26
+
27
+ }
28
+
21
29
  class ShenzhenLiONBMS extends BTSensor{
22
30
  static Domain = BTSensor.SensorDomains.electrical
23
31
  static ImageFile = "LiTimeLiFePo4Battery.avif"
@@ -63,11 +71,12 @@ class ShenzhenLiONBMS extends BTSensor{
63
71
  "numberOfCells",
64
72
  {
65
73
  title:"Number of cells",
66
- type: "integer",
74
+ type: "number",
67
75
  isRequired: true,
68
76
  default: 4,
69
77
  minimum: 1,
70
- maximum: 16
78
+ maximum: 16,
79
+ multipleOf:1
71
80
  }
72
81
  )
73
82
 
@@ -91,6 +100,9 @@ class ShenzhenLiONBMS extends BTSensor{
91
100
  this.addMetadatum(`cell${cellNum+1}Voltage`,'V', `cell #${cellNum+1} voltage`,
92
101
  (buff)=>{return buff.readInt16LE(16+(cellNum*2)) /1000})
93
102
  .default=`electrical.batteries.{batteryID}.cells.${cellNum+1}.voltage`
103
+
104
+ this.addMetadatum(`cell${cellNum+1}Balancing`,'', `cell #${cellNum+1} balance state (true=balancing)`)
105
+ .default=`electrical.batteries.{batteryID}.cells.${cellNum+1}.balancing`
94
106
  }
95
107
 
96
108
  this.addDefaultPath('current','electrical.batteries.current')
@@ -119,19 +131,15 @@ class ShenzhenLiONBMS extends BTSensor{
119
131
  .default="electrical.batteries.{batteryID}.balanceMemoryActive"
120
132
 
121
133
  this.addMetadatum('protectionState','', 'protection state',
122
- (buff)=>{return buff.slice(76,80).reverse().join("")})
134
+ (buff)=>{return ProtectionStatus[buff.readUInt16LE(76)]??"Normal"})
123
135
  .default="electrical.batteries.{batteryID}.protectionState"
124
136
 
125
137
  this.addMetadatum('failureState','', 'failure state',
126
138
  (buff)=>{return buff.slice(80,84).reverse().join("").slice(-3)})
127
139
  .default="electrical.batteries.{batteryID}.failureState"
128
-
129
- this.addMetadatum('balanceState','', '1 = cell at offset is balancing',
130
- (buff)=>{return buff.slice(84,88).reverse().join("")})
131
- .default="electrical.batteries.{batteryID}.balanceState"
132
140
 
133
141
  this.addMetadatum('batteryState','', 'charge disabled = "0004", charging = "0001" (when charging active app will show estimated time untill fully charged), discharging/idle: "0000", unkown = "0002"',
134
- (buff)=>{return buff.slice(88,90).reverse().join("")})
142
+ (buff)=>{return (BatteryState[buff.readUInt16LE(88)])??"Unknown"})
135
143
  .default="electrical.batteries.{batteryID}.batteryState"
136
144
 
137
145
  this.addMetadatum('dischargeCount','', 'discharge count',
@@ -148,6 +156,16 @@ class ShenzhenLiONBMS extends BTSensor{
148
156
  this.getJSONSchema().properties.params.required=["batteryID", "numberOfCells" ]
149
157
  }
150
158
 
159
+ emitValuesFrom(buffer){
160
+ super.emitValuesFrom(buffer)
161
+ const balanceState= buffer.slice(84,88).reverse().join("")
162
+
163
+ for(let cellNum=0; cellNum < this?.numberOfCells??4; cellNum++) {
164
+ this.emit(`cell${cellNum+1}Balancing`, balanceState[cellNum]==='1')
165
+ }
166
+
167
+ }
168
+
151
169
  async initGATTConnection(isReconnecting){
152
170
 
153
171
  await super.initGATTConnection(isReconnecting)