Skip to content

Commit

Permalink
Add support for the Indoor/Outdoor Thermo-Hygrometer (WoIOSensorTH). (#…
Browse files Browse the repository at this point in the history
…200)

Co-authored-by: Donavan Becker <beckersmarthome@icloud.com>
  • Loading branch information
moritzmhmk and donavanbecker committed Sep 2, 2023
1 parent b0b050f commit a42d26b
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions lib/switchbot-advertising.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class SwitchbotAdvertising {
sd = this._parseServiceDataForWoSensorTHPlus(buf, onlog);// WoMeterPlus
} else if (model === "r") {
sd = this._parseServiceDataForWoStrip(buf, onlog);// WoStrip
} else if (model === "w") {
sd = this._parseServiceDataForWoIOSensorTH(buf, manufacturerData, onlog); // Indoor/Outdoor Thermo-Hygrometer
} else {
if (onlog && typeof onlog === "function") {
onlog(
Expand Down Expand Up @@ -662,6 +664,49 @@ class SwitchbotAdvertising {

return data;
}

_parseServiceDataForWoIOSensorTH(serviceDataBuf, manufacturerDataBuf, onlog) {
if (serviceDataBuf.length !== 3) {
if (onlog && typeof onlog === "function") {
onlog(
`[_parseServiceDataForWoIOSensorTH] Service Data Buffer length ${serviceDataBuf.length} !== 3!`
);
}
return null;
}
if (manufacturerDataBuf.length !== 14) {
if (onlog && typeof onlog === "function") {
onlog(
`[_parseServiceDataForWoIOSensorTH] Manufacturer Data Buffer length ${manufacturerDataBuf.length} !== 14!`
);
}
return null;
}
const mdByte10 = manufacturerDataBuf.readUInt8(10);
const mdByte11 = manufacturerDataBuf.readUInt8(11);
const mdByte12 = manufacturerDataBuf.readUInt8(12);

const sdByte2 = serviceDataBuf.readUInt8(2);

const temp_sign = mdByte11 & 0b10000000 ? 1 : -1;
const temp_c = temp_sign * ((mdByte11 & 0b01111111) + (mdByte10 & 0b00001111) / 10);
const temp_f = Math.round(((temp_c * 9 / 5) + 32) * 10) / 10;

const data = {
model: "w",
modelName: "WoIOSensorTH",
temperature: {
c: temp_c,
f: temp_f,
},
fahrenheit: mdByte12 & 0b10000000 ? true : false, // needs to be confirmed!
humidity: mdByte12 & 0b01111111,
battery: sdByte2 & 0b01111111,
};

console.log(data);
return data;
}
}

module.exports = new SwitchbotAdvertising();

0 comments on commit a42d26b

Please sign in to comment.