shelly-script-examples
shelly-script-examples copied to clipboard
ble-pasv-mqtt-gw.js not correctly reporting negative temperatures for xiaomi devices
Negative temperatures are not reported correctly. -8.8c (might not be exact as the temperature fluctuates a bit) is reported as 6544.8c
To Reproduce Simply place the xiaomi sensor in an environment with negative temperatures (in celcius) and check the mqqt output
Expected behavior Expected to see negative temperatures reported in MQTT. Both mqqt reports (the one with only temperature and the one with temperature & humidity) are incorrect.
As long as it's still cold enough here I can easily test any fixes.
Fixed it (I think), changed
else if(fmt[pos] === 'H') {
res[keyArr[pos]] = le ? this.getUInt16LE() : this.getUInt16BE();
}
to
else if(fmt[pos] === 'H') {
res[keyArr[pos]] = le ? this.getInt16LE() : this.getInt16BE();
}
getUInt16LE implies Unsigned integer so no negative values are possible. Changing to getInt16BE will allow for negative values so if the data looks ok it should be a valid solution