node-switchbot 2.5.0-beta.9 → 3.0.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.
Files changed (341) hide show
  1. package/.github/workflows/beta-release.yml +25 -2
  2. package/.github/workflows/release.yml +13 -0
  3. package/BLE.md +1144 -0
  4. package/CHANGELOG.md +22 -0
  5. package/OpenAPI.md +185 -0
  6. package/README.md +20 -1189
  7. package/branding/Node_x_SwitchBot.svg +9 -0
  8. package/branding/icon.png +0 -0
  9. package/branding/switchbot.png +0 -0
  10. package/dist/advertising.d.ts +3 -3
  11. package/dist/advertising.d.ts.map +1 -1
  12. package/dist/advertising.js +26 -26
  13. package/dist/advertising.js.map +1 -1
  14. package/dist/device/woblindtilt.d.ts +19 -50
  15. package/dist/device/woblindtilt.d.ts.map +1 -1
  16. package/dist/device/woblindtilt.js +41 -100
  17. package/dist/device/woblindtilt.js.map +1 -1
  18. package/dist/device/wobulb.d.ts +41 -15
  19. package/dist/device/wobulb.d.ts.map +1 -1
  20. package/dist/device/wobulb.js +72 -128
  21. package/dist/device/wobulb.js.map +1 -1
  22. package/dist/device/woceilinglight.d.ts +47 -21
  23. package/dist/device/woceilinglight.d.ts.map +1 -1
  24. package/dist/device/woceilinglight.js +96 -171
  25. package/dist/device/woceilinglight.js.map +1 -1
  26. package/dist/device/wocontact.d.ts +11 -1
  27. package/dist/device/wocontact.d.ts.map +1 -1
  28. package/dist/device/wocontact.js +23 -22
  29. package/dist/device/wocontact.js.map +1 -1
  30. package/dist/device/wocurtain.d.ts +39 -1
  31. package/dist/device/wocurtain.d.ts.map +1 -1
  32. package/dist/device/wocurtain.js +69 -103
  33. package/dist/device/wocurtain.js.map +1 -1
  34. package/dist/device/wohand.d.ts +37 -2
  35. package/dist/device/wohand.d.ts.map +1 -1
  36. package/dist/device/wohand.js +55 -89
  37. package/dist/device/wohand.js.map +1 -1
  38. package/dist/device/wohub2.d.ts +11 -1
  39. package/dist/device/wohub2.d.ts.map +1 -1
  40. package/dist/device/wohub2.js +21 -29
  41. package/dist/device/wohub2.js.map +1 -1
  42. package/dist/device/wohumi.d.ts +37 -2
  43. package/dist/device/wohumi.d.ts.map +1 -1
  44. package/dist/device/wohumi.js +52 -83
  45. package/dist/device/wohumi.js.map +1 -1
  46. package/dist/device/woiosensorth.d.ts +12 -1
  47. package/dist/device/woiosensorth.d.ts.map +1 -1
  48. package/dist/device/woiosensorth.js +25 -29
  49. package/dist/device/woiosensorth.js.map +1 -1
  50. package/dist/device/woplugmini.d.ts +45 -12
  51. package/dist/device/woplugmini.d.ts.map +1 -1
  52. package/dist/device/woplugmini.js +71 -77
  53. package/dist/device/woplugmini.js.map +1 -1
  54. package/dist/device/wopresence.d.ts +11 -1
  55. package/dist/device/wopresence.d.ts.map +1 -1
  56. package/dist/device/wopresence.js +21 -27
  57. package/dist/device/wopresence.js.map +1 -1
  58. package/dist/device/wosensorth.d.ts +18 -2
  59. package/dist/device/wosensorth.d.ts.map +1 -1
  60. package/dist/device/wosensorth.js +34 -50
  61. package/dist/device/wosensorth.js.map +1 -1
  62. package/dist/device/wosmartlock.d.ts +63 -13
  63. package/dist/device/wosmartlock.d.ts.map +1 -1
  64. package/dist/device/wosmartlock.js +114 -195
  65. package/dist/device/wosmartlock.js.map +1 -1
  66. package/dist/device/wosmartlockpro.d.ts +16 -12
  67. package/dist/device/wosmartlockpro.d.ts.map +1 -1
  68. package/dist/device/wosmartlockpro.js +34 -29
  69. package/dist/device/wosmartlockpro.js.map +1 -1
  70. package/dist/device/wostrip.d.ts +4 -3
  71. package/dist/device/wostrip.d.ts.map +1 -1
  72. package/dist/device/wostrip.js +5 -4
  73. package/dist/device/wostrip.js.map +1 -1
  74. package/dist/device.d.ts +13 -5
  75. package/dist/device.d.ts.map +1 -1
  76. package/dist/device.js +13 -2
  77. package/dist/device.js.map +1 -1
  78. package/dist/index.d.ts +9 -1
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +9 -1
  81. package/dist/index.js.map +1 -1
  82. package/dist/parameter-checker.d.ts +10 -13
  83. package/dist/parameter-checker.d.ts.map +1 -1
  84. package/dist/parameter-checker.js +16 -1
  85. package/dist/parameter-checker.js.map +1 -1
  86. package/dist/settings.d.ts +47 -0
  87. package/dist/settings.d.ts.map +1 -1
  88. package/dist/settings.js +49 -0
  89. package/dist/settings.js.map +1 -1
  90. package/dist/{switchbot.d.ts → switchbot-ble.d.ts} +12 -9
  91. package/dist/switchbot-ble.d.ts.map +1 -0
  92. package/dist/switchbot-ble.js +426 -0
  93. package/dist/switchbot-ble.js.map +1 -0
  94. package/dist/switchbot-openapi.d.ts +131 -0
  95. package/dist/switchbot-openapi.d.ts.map +1 -0
  96. package/dist/switchbot-openapi.js +311 -0
  97. package/dist/switchbot-openapi.js.map +1 -0
  98. package/dist/test/advertising.test.d.ts +2 -0
  99. package/dist/test/advertising.test.d.ts.map +1 -0
  100. package/dist/test/advertising.test.js +99 -0
  101. package/dist/test/advertising.test.js.map +1 -0
  102. package/dist/test/device.test.d.ts +2 -0
  103. package/dist/test/device.test.d.ts.map +1 -0
  104. package/dist/test/device.test.js +38 -0
  105. package/dist/test/device.test.js.map +1 -0
  106. package/dist/test/index.test.d.ts +2 -0
  107. package/dist/test/index.test.d.ts.map +1 -0
  108. package/dist/test/index.test.js +35 -0
  109. package/dist/test/index.test.js.map +1 -0
  110. package/dist/test/parameter-checker.test.d.ts +2 -0
  111. package/dist/test/parameter-checker.test.d.ts.map +1 -0
  112. package/dist/test/parameter-checker.test.js +108 -0
  113. package/dist/test/parameter-checker.test.js.map +1 -0
  114. package/dist/test/settings.test.d.ts +2 -0
  115. package/dist/test/settings.test.d.ts.map +1 -0
  116. package/dist/test/settings.test.js +49 -0
  117. package/dist/test/settings.test.js.map +1 -0
  118. package/dist/test/switchbot-openapi.test.d.ts +2 -0
  119. package/dist/test/switchbot-openapi.test.d.ts.map +1 -0
  120. package/dist/test/switchbot-openapi.test.js +96 -0
  121. package/dist/test/switchbot-openapi.test.js.map +1 -0
  122. package/dist/test/switchbot.test.d.ts +2 -0
  123. package/dist/test/switchbot.test.d.ts.map +1 -0
  124. package/dist/test/switchbot.test.js +106 -0
  125. package/dist/test/switchbot.test.js.map +1 -0
  126. package/dist/test/woblindtilt.test.js +70 -20
  127. package/dist/test/woblindtilt.test.js.map +1 -1
  128. package/dist/test/wobulb.test.js +87 -44
  129. package/dist/test/wobulb.test.js.map +1 -1
  130. package/dist/test/woceilinglight.test.js +72 -54
  131. package/dist/test/woceilinglight.test.js.map +1 -1
  132. package/dist/test/wocontact.test.js +51 -20
  133. package/dist/test/wocontact.test.js.map +1 -1
  134. package/dist/test/wocurtain.test.js +65 -23
  135. package/dist/test/wocurtain.test.js.map +1 -1
  136. package/dist/test/wohand.test.js +34 -40
  137. package/dist/test/wohand.test.js.map +1 -1
  138. package/dist/test/wohub2.test.d.ts +2 -0
  139. package/dist/test/wohub2.test.d.ts.map +1 -0
  140. package/dist/test/wohub2.test.js +80 -0
  141. package/dist/test/wohub2.test.js.map +1 -0
  142. package/dist/test/wohumi.test.js +70 -49
  143. package/dist/test/wohumi.test.js.map +1 -1
  144. package/dist/test/woiosensorth.test.js +33 -32
  145. package/dist/test/woiosensorth.test.js.map +1 -1
  146. package/dist/test/woplugmini.test.js +80 -57
  147. package/dist/test/woplugmini.test.js.map +1 -1
  148. package/dist/test/wopresence.test.js +44 -18
  149. package/dist/test/wopresence.test.js.map +1 -1
  150. package/dist/test/wosensorth.test.js +44 -52
  151. package/dist/test/wosensorth.test.js.map +1 -1
  152. package/dist/test/wosmartlock.test.js +126 -59
  153. package/dist/test/wosmartlock.test.js.map +1 -1
  154. package/dist/test/wosmartlockpro.test.js +96 -69
  155. package/dist/test/wosmartlockpro.test.js.map +1 -1
  156. package/dist/test/wostrip.test.js +70 -83
  157. package/dist/test/wostrip.test.js.map +1 -1
  158. package/dist/types/bledevicestatus.d.ts +4 -12
  159. package/dist/types/bledevicestatus.d.ts.map +1 -1
  160. package/dist/types/devicelist.d.ts.map +1 -1
  161. package/dist/types/devicelist.js +0 -4
  162. package/dist/types/devicelist.js.map +1 -1
  163. package/dist/types/devicepush.d.ts +13 -0
  164. package/dist/types/devicepush.d.ts.map +1 -0
  165. package/dist/types/devicepush.js +2 -0
  166. package/dist/types/devicepush.js.map +1 -0
  167. package/dist/types/deviceresponse.d.ts +2 -3
  168. package/dist/types/deviceresponse.d.ts.map +1 -1
  169. package/dist/types/devicestatus.d.ts.map +1 -1
  170. package/dist/types/devicewebhookstatus.d.ts +32 -0
  171. package/dist/types/devicewebhookstatus.d.ts.map +1 -1
  172. package/dist/types/irdevicelist.d.ts.map +1 -1
  173. package/dist/types/types.d.ts +24 -1
  174. package/dist/types/types.d.ts.map +1 -1
  175. package/dist/types/types.js +14 -0
  176. package/dist/types/types.js.map +1 -1
  177. package/docs/assets/highlight.css +12 -47
  178. package/docs/assets/main.js +1 -1
  179. package/docs/assets/navigation.js +1 -1
  180. package/docs/assets/search.js +1 -1
  181. package/docs/classes/SwitchBotBLE.html +62 -0
  182. package/docs/classes/SwitchBotOpenAPI.html +47 -0
  183. package/docs/classes/SwitchbotDevice.html +32 -33
  184. package/docs/enums/LogLevel.html +10 -0
  185. package/docs/enums/SwitchBotBLEModel.html +2 -2
  186. package/docs/enums/SwitchBotBLEModelFriendlyName.html +2 -2
  187. package/docs/enums/SwitchBotBLEModelName.html +2 -2
  188. package/docs/enums/SwitchBotModel.html +2 -2
  189. package/docs/hierarchy.html +1 -0
  190. package/docs/index.html +16 -993
  191. package/docs/interfaces/Ad-1.html +5 -0
  192. package/docs/interfaces/AdvertisementData.html +3 -0
  193. package/docs/interfaces/Chars.html +4 -0
  194. package/docs/interfaces/ErrorObject.html +3 -0
  195. package/docs/interfaces/Params.html +6 -0
  196. package/docs/interfaces/Rule.html +9 -0
  197. package/docs/interfaces/ServiceData.html +2 -0
  198. package/docs/interfaces/SwitchBotBLEDevice.html +21 -0
  199. package/docs/interfaces/WebhookDetail.html +6 -0
  200. package/docs/interfaces/ad.html +5 -0
  201. package/docs/interfaces/body.html +3 -0
  202. package/docs/interfaces/bodyChange.html +4 -0
  203. package/docs/interfaces/deleteWebhookResponse.html +4 -0
  204. package/docs/interfaces/device.html +7 -0
  205. package/docs/interfaces/deviceList.html +2 -0
  206. package/docs/interfaces/deviceStatus.html +7 -0
  207. package/docs/interfaces/deviceStatusRequest.html +4 -0
  208. package/docs/interfaces/deviceWebhook.html +4 -0
  209. package/docs/interfaces/deviceWebhookContext.html +4 -0
  210. package/docs/interfaces/devices.html +4 -0
  211. package/docs/interfaces/infraredRemoteList.html +2 -0
  212. package/docs/interfaces/irdevice.html +5 -0
  213. package/docs/interfaces/pushResponse.html +4 -0
  214. package/docs/interfaces/queryWebhookResponse.html +4 -0
  215. package/docs/interfaces/setupWebhookResponse.html +4 -0
  216. package/docs/interfaces/switchbot.html +3 -0
  217. package/docs/interfaces/updateWebhookResponse.html +4 -0
  218. package/docs/interfaces/webhookRequest.html +4 -0
  219. package/docs/media/BLE.md +1144 -0
  220. package/docs/media/OpenAPI.md +185 -0
  221. package/docs/modules.html +137 -3
  222. package/docs/types/MacAddress.html +1 -0
  223. package/docs/types/batteryCirculatorFan.html +1 -0
  224. package/docs/types/batteryCirculatorFanServiceData.html +1 -0
  225. package/docs/types/batteryCirculatorFanStatus.html +1 -0
  226. package/docs/types/batteryCirculatorFanWebhookContext.html +1 -0
  227. package/docs/types/blindTilt.html +1 -0
  228. package/docs/types/blindTiltServiceData.html +1 -0
  229. package/docs/types/blindTiltStatus.html +1 -0
  230. package/docs/types/blindTiltWebhookContext.html +1 -0
  231. package/docs/types/bot.html +1 -0
  232. package/docs/types/botServiceData.html +1 -0
  233. package/docs/types/botStatus.html +1 -0
  234. package/docs/types/botWebhookContext.html +1 -0
  235. package/docs/types/ceilingLight.html +1 -0
  236. package/docs/types/ceilingLightPro.html +1 -0
  237. package/docs/types/ceilingLightProServiceData.html +1 -0
  238. package/docs/types/ceilingLightProStatus.html +1 -0
  239. package/docs/types/ceilingLightProWebhookContext.html +1 -0
  240. package/docs/types/ceilingLightServiceData.html +1 -0
  241. package/docs/types/ceilingLightStatus.html +1 -0
  242. package/docs/types/ceilingLightWebhookContext.html +1 -0
  243. package/docs/types/colorBulb.html +1 -0
  244. package/docs/types/colorBulbServiceData.html +1 -0
  245. package/docs/types/colorBulbStatus.html +1 -0
  246. package/docs/types/colorBulbWebhookContext.html +1 -0
  247. package/docs/types/contactSensor.html +1 -0
  248. package/docs/types/contactSensorServiceData.html +1 -0
  249. package/docs/types/contactSensorStatus.html +1 -0
  250. package/docs/types/contactSensorWebhookContext.html +1 -0
  251. package/docs/types/curtain.html +1 -0
  252. package/docs/types/curtain3.html +1 -0
  253. package/docs/types/curtain3ServiceData.html +1 -0
  254. package/docs/types/curtain3WebhookContext.html +1 -0
  255. package/docs/types/curtainServiceData.html +1 -0
  256. package/docs/types/curtainStatus.html +1 -0
  257. package/docs/types/curtainWebhookContext.html +1 -0
  258. package/docs/types/floorCleaningRobotS10.html +1 -0
  259. package/docs/types/floorCleaningRobotS10Status.html +1 -0
  260. package/docs/types/floorCleaningRobotS10WebhookContext.html +1 -0
  261. package/docs/types/hub2.html +1 -0
  262. package/docs/types/hub2ServiceData.html +1 -0
  263. package/docs/types/hub2Status.html +1 -0
  264. package/docs/types/hub2WebhookContext.html +1 -0
  265. package/docs/types/humidifier.html +1 -0
  266. package/docs/types/humidifierServiceData.html +1 -0
  267. package/docs/types/humidifierStatus.html +1 -0
  268. package/docs/types/humidifierWebhookContext.html +1 -0
  269. package/docs/types/indoorCam.html +1 -0
  270. package/docs/types/indoorCameraWebhookContext.html +1 -0
  271. package/docs/types/keypad.html +1 -0
  272. package/docs/types/keypadTouch.html +1 -0
  273. package/docs/types/keypadTouchWebhookContext.html +1 -0
  274. package/docs/types/keypadWebhookContext.html +1 -0
  275. package/docs/types/lock.html +1 -0
  276. package/docs/types/lockPro.html +1 -0
  277. package/docs/types/lockProServiceData.html +1 -0
  278. package/docs/types/lockProStatus.html +1 -0
  279. package/docs/types/lockProWebhookContext.html +1 -0
  280. package/docs/types/lockServiceData.html +1 -0
  281. package/docs/types/lockStatus.html +1 -0
  282. package/docs/types/lockWebhookContext.html +1 -0
  283. package/docs/types/meter.html +1 -0
  284. package/docs/types/meterPlus.html +1 -0
  285. package/docs/types/meterPlusServiceData.html +1 -0
  286. package/docs/types/meterPlusStatus.html +1 -0
  287. package/docs/types/meterPlusWebhookContext.html +1 -0
  288. package/docs/types/meterServiceData.html +1 -0
  289. package/docs/types/meterStatus.html +1 -0
  290. package/docs/types/meterWebhookContext.html +1 -0
  291. package/docs/types/motionSensor.html +1 -0
  292. package/docs/types/motionSensorServiceData.html +1 -0
  293. package/docs/types/motionSensorStatus.html +1 -0
  294. package/docs/types/motionSensorWebhookContext.html +1 -0
  295. package/docs/types/outdoorMeter.html +1 -0
  296. package/docs/types/outdoorMeterServiceData.html +1 -0
  297. package/docs/types/outdoorMeterStatus.html +1 -0
  298. package/docs/types/outdoorMeterWebhookContext.html +1 -0
  299. package/docs/types/panTiltCamWebhookContext.html +1 -0
  300. package/docs/types/pantiltCam.html +1 -0
  301. package/docs/types/pantiltCam2k.html +1 -0
  302. package/docs/types/plug.html +1 -0
  303. package/docs/types/plugMini.html +1 -0
  304. package/docs/types/plugMiniJPServiceData.html +1 -0
  305. package/docs/types/plugMiniJPWebhookContext.html +1 -0
  306. package/docs/types/plugMiniStatus.html +1 -0
  307. package/docs/types/plugMiniUSServiceData.html +1 -0
  308. package/docs/types/plugMiniUSWebhookContext.html +1 -0
  309. package/docs/types/plugStatus.html +1 -0
  310. package/docs/types/plugWebhookContext.html +1 -0
  311. package/docs/types/remote.html +1 -0
  312. package/docs/types/robotVacuumCleanerS1.html +1 -0
  313. package/docs/types/robotVacuumCleanerS1Plus.html +1 -0
  314. package/docs/types/robotVacuumCleanerS1PlusStatus.html +1 -0
  315. package/docs/types/robotVacuumCleanerS1PlusWebhookContext.html +1 -0
  316. package/docs/types/robotVacuumCleanerS1Status.html +1 -0
  317. package/docs/types/robotVacuumCleanerS1WebhookContext.html +1 -0
  318. package/docs/types/robotVacuumCleanerServiceData.html +1 -0
  319. package/docs/types/stripLight.html +1 -0
  320. package/docs/types/stripLightServiceData.html +1 -0
  321. package/docs/types/stripLightStatus.html +1 -0
  322. package/docs/types/stripLightWebhookContext.html +1 -0
  323. package/docs/types/waterLeakDetector.html +1 -0
  324. package/docs/types/waterLeakDetectorServiceData.html +1 -0
  325. package/docs/types/waterLeakDetectorStatus.html +1 -0
  326. package/docs/types/waterLeakDetectorWebhookContext.html +1 -0
  327. package/package.json +15 -13
  328. package/.github/npm-version-script.cjs +0 -81
  329. package/dist/switchbot.d.ts.map +0 -1
  330. package/dist/switchbot.js +0 -259
  331. package/dist/switchbot.js.map +0 -1
  332. package/dist/test/wohand2.test.d.ts +0 -2
  333. package/dist/test/wohand2.test.d.ts.map +0 -1
  334. package/dist/test/wohand2.test.js +0 -50
  335. package/dist/test/wohand2.test.js.map +0 -1
  336. package/dist/types/pushbody.d.ts +0 -6
  337. package/dist/types/pushbody.d.ts.map +0 -1
  338. package/dist/types/pushbody.js +0 -2
  339. package/dist/types/pushbody.js.map +0 -1
  340. package/docs/classes/SwitchBot.html +0 -16
  341. package/docs/types/SwitchBotBLEDevice.html +0 -1
package/README.md CHANGED
@@ -1,1209 +1,40 @@
1
- <span align="center">
1
+ <div align="center">
2
2
 
3
- # Node-SwitchBot
4
-
5
- <a href="https://www.npmjs.com/package/node-switchbot"><img title="npm version" src="https://badgen.net/npm/v/node-switchbot" ></a>
6
- <a href="https://www.npmjs.com/package/node-switchbot"><img title="npm downloads" src="https://badgen.net/npm/dt/node-switchbot" ></a>
7
-
8
- </span>
9
-
10
- The node-switchbot is a Node.js module which allows you to move your [Switchbot (Bot)'s](https://www.switch-bot.com/bot) arm
11
- and [Switchbot Curtain](https://www.switch-bot.com/products/switchbot-curtain), operate your [Switchbot Lock](https://www.switch-bot.com/products/switchbot-lock),
12
- also monitor the temperature/humidity from [SwitchBot Thermometer & Hygrometer (Meter)](https://www.switch-bot.com/meter)
13
- as well as the status from [SwitchBot Motion Sensor](https://www.switch-bot.com/products/motion-sensor)
14
- and [SwitchBot Contact Sensor](https://www.switch-bot.com/products/contact-sensor)
15
-
16
- This module is unofficial. It was developed by reference to [the official python code](https://github.com/OpenWonderLabs/python-host).
17
- But some functionalities of this module were developed through trial and error. So some information obtained from this module might be wrong.
18
-
19
- ---
20
-
21
- ## Table of Contents
22
-
23
- - [node-switchbot](#node-switchbot)
24
- - [Table of Contents](#table-of-contents)
25
- - [Supported OS](#supported-os)
26
- - [Dependencies](#dependencies)
27
- - [Installation](#installation)
28
- - [Quick Start](#quick-start)
29
- - [Monitoring Advertising packets](#monitoring-advertising-packets)
30
- - [Moving the arm of the Bot](#moving-the-arm-of-the-bot)
31
- - [`Switchbot` object](#switchbot-object)
32
- - [`discover()` method](#discover-method)
33
- - [`ondiscover` event handler](#ondiscover-event-handler)
34
- - [`startScan()` method](#startscan-method)
35
- - [`stopScan()` method](#stopscan-method)
36
- - [`onadvertisement` event handler](#onadvertisement-event-handler)
37
- - [`wait()` method](#wait-method)
38
- - [`SwitchbotDevice` object](#switchbotdevice-object)
39
- - [Properties](#properties)
40
- - [`getDeviceName()` method](#getdevicename-method)
41
- - [`setDeviceName()` method](#setdevicename-method)
42
- - [`connect()` method](#connect-method)
43
- - [`disconnect()` method](#disconnect-method)
44
- - [`onconnect` event handler](#onconnect-event-handler)
45
- - [`ondisconnect` event handler](#ondisconnect-event-handler)
46
- - [`WoHand` object](#wohand-object)
47
- - [`press()` method](#press-method)
48
- - [`turnOn()` method](#turnon-method)
49
- - [`turnOff()` method](#turnoff-method)
50
- - [`down()` method](#down-method)
51
- - [`up()` method](#up-method)
52
- - [`WoCurtain` object](#wocurtain-object)
53
- - [`open()` method](#open-method)
54
- - [`close()` method](#close-method)
55
- - [`pause()` method](#pause-method)
56
- - [`runToPos()` method](#runtopos-method)
57
- - [`WoPlugMini` object](#woplugmini-object)
58
- - [`turnOn()` method](#turnon-method)
59
- - [`turnOff()` method](#turnoff-method)
60
- - [`toggle()` method](#toggle-method)
61
- - [`WoSmartLock` object](#wosmartlock-object)
62
- - [`lock()` method](#lock-method)
63
- - [`unlock()` method](#unlock-method)
64
- - [`unlock_no_unlatch()` method](#unlock_no_unlatch-method)
65
- - [`info()` method](#info-method)
66
- - [Advertisement data](#advertisement-data)
67
- - [Bot (WoHand)](#bot-wohand)
68
- - [Meter (WoSensorTH)](#meter-wosensorth)
69
- - [Curtain (WoCurtain)](#curtain-wocurtain)
70
- - [Contact (WoContact)](#contact-wocontact)
71
- - [Motion (WoMotion)](#motion-womotion)
72
- - [PlugMini (WoPlugMini)](#plugmini-woplugmini)
73
- - [Release Note](#release-note)
74
- - [References](#references)
75
- - [License](#license)
76
-
77
- ## Supported OS
78
-
79
- The node-switchbot supports only Linux-based OSes, such as Raspbian, Ubuntu, and so on. This module does not support Windows and macOS for now. (If [@abandonware/noble](https://github.com/abandonware/noble) is installed properly, this module might work well on such OSes.)
80
-
81
- ## Dependencies
82
-
83
- - [Node.js](https://nodejs.org/en/) 10 +
84
- - [@abandonware/noble](https://github.com/abandonware/noble)
85
-
86
- See the document of the [@abandonware/noble](https://github.com/abandonware/noble) for details on installing the [@abandonware/noble](https://github.com/abandonware/noble).
87
-
88
- Note that the noble must be run as root on most of Linux environments. See the document of the [@abandonware/noble](https://github.com/abandonware/noble) for details.
89
-
90
- ## Installation
91
-
92
- Before installing the [@abandonware/noble](https://github.com/abandonware/noble), some linux libraries related Bluetooth as follows if the OS is Ubuntu/Debian/Raspbian.
93
-
94
- ```
95
- $ sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev
96
- ```
97
-
98
- If you use other OS, follow the instructions described in the document of the [@abandonware/noble](https://github.com/abandonware/noble).
99
-
100
- After installing the libraries above, install the [@abandonware/noble](https://github.com/abandonware/noble) and the node-switchbot (this module) as follows:
101
-
102
- ```
103
- $ cd ~
104
- $ npm install @abandonware/noble
105
- $ npm install node-switchbot
106
- ```
107
-
108
- ---
109
-
110
- ## Quick Start
111
-
112
- ### Monitoring Advertising packets
113
-
114
- Monitoring the advertising packets, you can find your devices and know the latest state of each device. The packet contains the settings of the device, the arm position of the Bot, the temperature and humidity of the Meter, and so on.
115
-
116
- ```Typescript
117
- // Load the node-switchbot and get a `Switchbot` constructor object
118
- import { SwitchBot } from 'node-switchbot';
119
- // Create a `Switchbot` object
120
- const switchbot = new SwitchBot();
121
-
122
- (async () => {
123
- // Start to monitor advertisement packets
124
- await switchbot.startScan();
125
- // Set an event handler
126
- switchbot.onadvertisement = (ad) => {
127
- console.log(JSON.stringify(ad, null, ' '));
128
- };
129
- // Wait 10 seconds
130
- await switchbot.wait(10000);
131
- // Stop to monitor
132
- switchbot.stopScan();
133
- process.exit();
134
- })();
135
- ```
136
-
137
- The [`startScan()`](#startscan-method) methods starts to monitor advertisement packets. In order to receive the packets, you have to assign a callback function to the [`onadvertisement`](#Switchbot-onadvertisement-event-handler).
138
-
139
- The [`wait()`](#Switchbot-wait-method) method is just a utility method, which wait for the specified milliseconds.
140
-
141
- The [`startScan()`](#startscan-method) and [`wait()`](#Switchbot-wait-method) methods are asynchronous, they return a `Promise` object. You can write code in promise style as well. What the code below does is as same as what the code above does:
142
-
143
- ```Typescript
144
- // Load the node-switchbot and get a `Switchbot` constructor object
145
- const Switchbot = require("node-switchbot");
146
- // Create a `Switchbot` object
147
- const switchbot = new Switchbot();
148
-
149
- // Start to monitor advertisement packets
150
- switchbot
151
- .startScan()
152
- .then(() => {
153
- // Set an event handler
154
- switchbot.onadvertisement = (ad) => {
155
- console.log(JSON.stringify(ad, null, " "));
156
- };
157
- // Wait 10 seconds
158
- return switchbot.wait(10000);
159
- })
160
- .then(() => {
161
- // Stop to monitor
162
- switchbot.stopScan();
163
- process.exit();
164
- });
165
- ```
166
-
167
- The sample codes above will output the result as follows:
168
-
169
- ```json
170
- {
171
- "id": "c12e453e2008",
172
- "address": "c1:2e:45:3e:20:08",
173
- "rssi": -61,
174
- "serviceData": {
175
- "model": "H",
176
- "modelName": "WoHand",
177
- "mode": true,
178
- "state": false,
179
- "battery": 100
180
- }
181
- }
182
- ```
183
-
184
- ```json
185
- {
186
- "id": "cb4eb903c96d",
187
- "address": "cb:4e:b9:03:c9:6d",
188
- "rssi": -70,
189
- "serviceData": {
190
- "model": "T",
191
- "modelName": "WoSensorTH",
192
- "temperature": {
193
- "c": 25.2,
194
- "f": 77.4
195
- },
196
- "fahrenheit": false,
197
- "humidity": 43,
198
- "battery": 100
199
- }
200
- }
201
- ```
202
-
203
- ```json
204
- {
205
- "id": "ec58c5d00111",
206
- "address": "ec:58:c5:d0:01:11",
207
- "rssi": -39,
208
- "serviceData": {
209
- "model": "c",
210
- "modelName": "WoCurtain",
211
- "calibration": true,
212
- "battery": 91,
213
- "position": 1,
214
- "lightLevel": 1
215
- }
216
- }
217
- ```
218
-
219
- See the section "[Advertisement data](#Advertisement-data)" for the details of the advertising packets.
220
-
221
- ### Moving the arm of the Bot
222
-
223
- This sample discovers a Bot (WoHand), then put the Bot's arm down, finally put it up in 5 seconds.
224
-
225
- ```Typescript
226
- // Load the node-switchbot and get a `Switchbot` constructor object
227
- import { SwitchBot } from 'node-switchbot';
228
- // Create a `Switchbot` object
229
- const switchbot = new SwitchBot();
230
-
231
- (async () => {
232
- // Find a Bot (WoHand)
233
- const bot_list = await switchbot.discover({ model: "H", quick: true });
234
- if (bot_list.length === 0) {
235
- throw new Error("No device was found.");
236
- }
237
- // The `WoHand` object representing the found Bot.
238
- const device = bot_list[0];
239
- // Put the Bot's arm down (stretch the arm)
240
- await device.down();
241
- // Wait for 5 seconds
242
- await switchbot.wait(5000);
243
- // Put the Bot's arm up (retract the arm)
244
- await device.up();
245
- process.exit();
246
- })();
247
- ```
248
-
249
- In order to manipulate the arm of your Bot, you have to discover your Bot using the [`discover()`](#Switchbot-discover-method) method. The object `{ model: 'H' }` passed to the method means that only Bots will be discovered. That is, Meters will be ignored.
250
-
251
- In this code, you can get a [`WoHand`](#SwitchbotDeviceWoHand-object) object representing the found Bot. Using the [`down()`](#SwitchbotDeviceWoHand-down-method) and [`up()`](#SwitchbotDeviceWoHand-up-method) methods of the object, you can move the arm. In addition to these methods, you can use the [`press()`](#SwitchbotDeviceWoHand-press-method), [`turnOn()`](#SwitchbotDeviceWoHand-turnOn-method), and [`turnOff()`](#SwitchbotDeviceWoHand-turnOff-method) methods as well.
252
-
253
- ---
254
-
255
- ## `Switchbot` object
256
-
257
- In order to use the node-switchbot, you have to load the node-switchbot module as follows:
258
-
259
- ```Typescript
260
- import { SwitchBot } from 'node-switchbot';
261
- ```
262
-
263
- You can get an `SwitchBot` constructor from the code above. Then you have to create a `SwitchBot` object from the `SwitchBot` constructor as follows:
264
-
265
- ```typescript
266
- const switchbot = new SwitchBot()
267
- switchbot.startScan()
268
- ```
269
-
270
- The `SwitchBot` constructor takes an argument optionally. It must be a hash object containing the properties as follows:
271
-
272
- | Property | Type | Required | Description |
273
- | :------- | :---- | :------- | :---------------------------------------------------------------------------------------- |
274
- | `noble` | Noble | option | a Noble object of the [`@abandonware/noble`](https://github.com/abandonware/noble) module |
275
-
276
- The node-switchbot module uses the [`@abandonware/noble`](https://github.com/abandonware/noble) module in order to interact with BLE devices. If you want to interact other BLE devices using the `@abandonware/noble` module, you can create an `Noble` object by yourself, then pass it to this module. If you don't specify a `Noble` object to the `noble` property, this module automatically create a `Noble` object internally.
277
-
278
- The sample code below shows how to pass a `Noble` object to the `Switchbot` constructor.
279
-
280
- ```Typescript
281
- // Create a Noble object
282
- const noble = require('@abandonware/noble');
283
-
284
- // Create a Switchbot object
285
- import { SwitchBot } from 'node-switchbot';
286
- const switchbot = new SwitchBot({ 'noble': noble })
287
- ```
288
-
289
- In the code snippet above, the variable `switchbot` is an `SwitchBot` object. The `SwitchBot` object has a lot of methods as described in sections below.
290
-
291
- ### `discover()` method
292
-
293
- The `discover` method finds devices. This method returns a `Promise` object. This method takes an argument which is a hash object containing parameters as follows:
294
-
295
- | Property | Type | Required | Description |
296
- | :--------- | :------ | :------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
297
- | `duration` | Integer | Optional | Duration for discovery process (msec). The default value is 5000 (msec). |
298
- | `model` | String | Optional | `"H"`, `"T"` or `"c"`. If `"H"` is specified, this method will discover only Bots. If `"T"` is specified, this method will discover only Meters. If `"c"` is specified, this method will discover only Curtains. |
299
- | `id` | String | Optional | If this value is set, this method will discover only a device whose ID is as same as this value. The ID is identical to the MAC address. This parameter is case-insensitive, and colons are ignored. |
300
- | `quick` | Boolean | Optional | If this value is `true`, this method finishes the discovery process when the first device is found, then calls the `resolve()` function without waiting the specified `duration`. The default value is `false`. |
301
-
302
- In the code snippet below, no parameter is passed to the method:
303
-
304
- ```Typescript
305
- switchbot.discover().then((device_list) => {
306
- // Do something...
307
- }).catch((error) => {
308
- console.error(error);
309
- });
310
- ```
311
-
312
- If no parameter is passed to the method as the code above, an `Array` object will be passed to the `resolve()` function in 5 seconds. The `Array` object contains [`SwitchbotDevice`](#SwitchbotDevice-object) objects representing the found devices. See the section "[`SwitchbotDevice`](#SwitchbotDevice-object) objects" for more details.
313
-
314
- If you want a quick response, you can set the `quick` property to `true`.
315
-
316
- ```Typescript
317
- switchbot.discover({
318
- duration: 5000,
319
- quick: true
320
- }).then((device_list) => {
321
- // Do something...
322
- }).catch((error) => {
323
- console.error(error);
324
- });
325
- ```
326
-
327
- As the `quick` property is set to `true`, the `resolve()` function will be called immediately after a device is found regardless the value of the `duration` property.
328
-
329
- ### `ondiscover` event handler
330
-
331
- The `ondiscover` property on the [`Switchbot`](#Switchbot-object) object is an event handler called whenever a device is newly found in the discovery process. A [`SwitchbotDevice`](#SwitchbotDevice-object) object is passed to the callback function set to the `ondiscover` property.
332
-
333
- ```Typescript
334
- switchbot.ondiscover = (device) => {
335
- console.log(device.id + ' (' + device.modelName + ')');
336
- };
337
-
338
- switchbot.discover().then(() => {
339
- console.log('The discovery process was finished.');
340
- }).catch((error) => {
341
- console.error(error);
342
- });
343
- ```
344
-
345
- The code snippet above will output the result as follows:
346
-
347
- ```
348
- cb4eb903c96d (WoSensorTH)
349
- c12e453e2008 (WoHand)
350
- The discovery process was finished.
351
- ```
352
-
353
- ### `startScan()` method
354
-
355
- The `startScan()` method starts to scan advertising packets coming from devices. This method takes an argument which is a hash object containing the parameters as follows:
356
-
357
- | Property | Type | Required | Description |
358
- | :------- | :----- | :------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
359
- | `model` | String | Optional | `"H"`, `"T"`, `"c"`, `"g"` or `"j"`. If `"H"` is specified, this method will discover only Bots. If `"T"` is specified, this method will discover only Meters. If `"c"` is specified, this method will discover only Curtains. If `"g"` or `"j"` is specified, this method will discover only (US/JP) Plug Minis. |
360
- | `id` | String | Optional | If this value is set, this method will discover only a device whose ID is as same as this value. The ID is identical to the MAC address. This value is case-insensitive, and colons are ignored. |
361
-
362
- Whenever a packet is received, the callback function set to the [`onadvertisement`](#Switchbot-onadvertisement-event-handler) property of the [`Switchbot`](#Switchbot-object) object will be called. When a packet is received, a hash object representing the packet will be passed to the callback function.
363
-
364
- ```Typescript
365
- // Set a callback function called when a packet is received
366
- switchbot.onadvertisement = (ad) => {
367
- console.log(ad);
368
- };
369
-
370
- // Start to scan advertising packets
371
- switchbot.startScan({
372
- id: 'cb:4e:b9:03:c9:6d',
373
- }).then(() => {
374
- // Wait for 30 seconds
375
- return switchbot.wait(30000);
376
- }).then(() => {
377
- // Stop to scan
378
- switchbot.stopScan();
379
- process.exit();
380
- }).catch((error) => {
381
- console.error(error);
382
- });
383
- ```
384
-
385
- The code snippet above will output the result as follows:
386
-
387
- ```
388
- {
389
- id: 'cb4eb903c96d',
390
- address: 'cb:4e:b9:03:c9:6d',
391
- rssi: -65,
392
- serviceData: {
393
- model: 'T',
394
- modelName: 'WoSensorTH',
395
- celsius: 25.8,
396
- fahrenheit: 78.4,
397
- fahrenheit_mode: false,
398
- humidity: 43,
399
- battery: 100
400
- }
401
- }
402
- ...
403
- ```
404
-
405
- The `serviceData` property depends on the model of the device. See the section "[Advertisement data](#Advertisement-data)" for the details of the data format.
406
-
407
- ### `stopScan()` method
408
-
409
- The `stopScan()` method stops to scan advertising packets coming from devices. This method returns nothing. Note that this method is _not_ asynchronous but synchronous unlike the other methods. See the section "[`startScan()` method](#startscan-method)" for details.
410
-
411
- ### `onadvertisement` event handler
412
-
413
- If a callback function is set to the `onadvertisement` property, the callback function will be called whenever an advertising packet is received from a device during the scan is active (from the moment when the [`startScan()`](#startscan-method) method is called, to the moment when the [`stopScan()`](#Switchbot-stopScan-method) method is called).
414
-
415
- See the section "[`startScan()` method](#startscan-method)" for details.
416
-
417
- ### `wait()` method
418
-
419
- The `wait()` method waits for the specified milliseconds. This method takes an integer representing the duration (millisecond). This method returns a `Promise` object.
420
-
421
- This method has nothing to do with Switchbot devices. It's just a utility method. See the section "[Quick Start](#Quick-Start)" for details of the usage of this method.
422
-
423
- ---
424
-
425
- ## `SwitchbotDevice` object
426
-
427
- The `SwitchbotDevice` object represents a Switchbot device (Bot, Meter, Curtain, Contact or Motion), which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
428
-
429
- Actually, the `SwitchbotDevice` object is a super class of the [`WoHand`](#SwitchbotDeviceWoHand-object) and `WoSensorTH` objects. The [`WoHand`](#SwitchbotDeviceWoHand-object) object represents a Bot, the `WoSensorTH` object represents a Meter.
430
-
431
- You can use the properties and methods described in this section on Bot, Meter, Curtain, Contact and Motion. See the section "[`WoHand` object](#SwitchbotDeviceWoHand-object)" for the details of the functionalities available only on Bot. For now, `WoSensorTH` object has no additional functionality.
432
-
433
- ### Properties
434
-
435
- The `SwitchbotDevice` object supports the properties as follows:
436
-
437
- | Property | Type | Description |
438
- | :---------------- | :------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------- |
439
- | `id` | String | ID of the device. (e.g., `"cb4eb903c96d"`) |
440
- | `address` | String | MAC address of the device. Basically it is as same as the value of the `id` except that this value includes `:` in the string. (e.g., `"cb:4e:b9:03:c9:6d"`) |
441
- | `model` | String | This value is `"H"` "Bot (WoHand)", `"T"` "Meter (WoSensorTH)", `"c"` "Curtain (WoCurtain)", `"d"` "Contact (WoContact)" or `"s"` "Motion (WoMotion)". |
442
- | `modelName` | String | This value is `"WoHand"`, `"WoSensorTH"`, `WoCurtain`, `WoContect` or `WoMotion`. |
443
- | `connectionState` | String | This value indicates the BLE connection state. `"connecting"`, `"connected"`, `"disconnecting"`, or `"disconnected"`. |
444
- | `onconnect` | Function | See the section "[`onconnect` event handler](#SwitchbotDevice-onconnect-event-handler)" for details. |
445
- | `ondisconnect` | Function | See the section "[`ondisconnect` event handler](#SwitchbotDevice-ondisconnect-event-handler)" for details. |
446
-
447
- ### `getDeviceName()` method
448
-
449
- The `getDeviceName()` method fetches the device name saved in the device. This method returns a `Promise` object.
450
-
451
- If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the [`connect()`](#SwitchbotDevice-connect-method) method in advance.
452
-
453
- If the device name is fetched successfully, the device name will be passed to the `resolve()`.
454
-
455
- ```Typescript
456
- switchbot
457
- .discover({ model: "H", quick: true })
458
- .then((device_list) => {
459
- return device_list[0].getDeviceName();
460
- })
461
- .then((name) => {
462
- console.log(name);
463
- process.exit();
464
- })
465
- .catch((error) => {
466
- console.error(error);
467
- process.exit();
468
- });
469
- ```
470
-
471
- The code above will output the result as follows:
472
-
473
- ```Typescript
474
- WoHand;
475
- ```
476
-
477
- ### `setDeviceName()` method
478
-
479
- The `setDeviceName()` method update the device name saved in the device with the name specified as the first argument. This method returns a `Promise` object. Nothing will be passed to the `resolve()` function.
480
-
481
- If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the [`connect()`](#SwitchbotDevice-connect-method) method in advance.
482
-
483
- The character set of the device name saved in the device is UTF-8. The byte length of the name must be less than or equal to 20 bytes. If the name consists of only ASCII characters, up to 20 characters would be allowed. But if the name consists of multibyte characters, the upper limit of characters would be fewer than half. For example, Japanese characters could be saved at most 6 characters because most of Japanese characters consume 3 byte per each character.
484
-
485
- ```Typescript
486
- switchbot
487
- .discover({ model: "H", quick: true })
488
- .then((device_list) => {
489
- return device_list[0].setDeviceName("Bot in kitchen");
490
- })
491
- .then(() => {
492
- console.log("Done.");
493
- process.exit();
494
- })
495
- .catch((error) => {
496
- console.error(error);
497
- process.exit();
498
- });
499
- ```
500
-
501
- ### `connect()` method
502
-
503
- The `connect()` method establishes a connection with the device (i.e., pairing). This method returns a `Promise` object. If the device has already been connected, this method does nothing and calls the `resolve()` function immediately.
504
-
505
- Most of the methods implemented in the `SwitchbotDevice` object automatically connect and disconnect the device. But this mechanism would be absolutely inefficient if you want to manipulate the device repeatedly in the short time.
506
-
507
- The connection established using the `connect()` method is not disconnected automatically unless the [`disconnect()`](#SwitchbotDevice-disconnect-method) method is explicitly called.
508
-
509
- The code snippet below establishes a connection with the Bot using the `connect()` method, then puts the Bot's arm down, then waits for 5 seconds, then puts the arm down, finally disconnects the device using the [`disconnect()`](#SwitchbotDevice-disconnect-method) method:
510
-
511
- ```Typescript
512
- let device = null;
513
-
514
- switchbot
515
- .discover({ model: "H", quick: true })
516
- .then((device_list) => {
517
- device = device_list[0];
518
- if (!device) {
519
- console.log("No device was found.");
520
- process.exit();
521
- }
522
- console.log(device.modelName + " (" + device.address + ") was found.");
523
- console.log("Connecting...");
524
- return device.connect();
525
- })
526
- .then(() => {
527
- console.log("Putting the arm down...");
528
- return device.down();
529
- })
530
- .then(() => {
531
- console.log("Waiting for 5 seconds...");
532
- return switchbot.wait(5000);
533
- })
534
- .then(() => {
535
- console.log("Putting the arm up...");
536
- return device.up();
537
- })
538
- .then(() => {
539
- console.log("Disconnecting...");
540
- return device.disconnect();
541
- })
542
- .then(() => {
543
- console.log("Done.");
544
- process.exit();
545
- })
546
- .catch((error) => {
547
- console.error(error);
548
- process.exit();
549
- });
550
- ```
551
-
552
- The result will be as follows:
553
-
554
- ```
555
- WoHand (c1:2e:45:3e:20:08) was found.
556
- Connecting...
557
- Putting the arm down...
558
- Waiting for 5 seconds...
559
- Putting the arm up...
560
- Disconnecting...
561
- Done.
562
- ```
563
-
564
- ### `disconnect()` method
565
-
566
- The `disconnect()` method disconnects the device. This method returns a `Promise` object. If the device has already been disconnected, this method does nothing and calls the `resolve()` function immediately.
567
-
568
- See the [previous section](#SwitchbotDevice-connect-method) for more details.
569
-
570
- ### `onconnect` event handler
571
-
572
- The `onconnect` event handler will be called when the connection with the device is established. Nothing will be passed to the handler.
573
-
574
- The code below calls the [`press()`](#SwitchbotDeviceWoHand-press-method) method, while callback functions are attached to the `onconnect` and `ondisconnect`.
575
-
576
- ```Typescript
577
- switchbot
578
- .discover({ model: "H", quick: true })
579
- .then((device_list) => {
580
- const device = device_list[0];
581
- if (!device) {
582
- console.log("No device was found.");
583
- process.exit();
584
- }
585
- console.log(device.modelName + " (" + device.address + ") was found.");
586
-
587
- // Set event handers
588
- device.onconnect = () => {
589
- console.log("Connected.");
590
- };
591
- device.ondisconnect = () => {
592
- console.log("Disconnected.");
593
- };
594
-
595
- console.log("Pressing the switch...");
596
- return device.press();
597
- })
598
- .then(() => {
599
- console.log("Done.");
600
- process.exit();
601
- })
602
- .catch((error) => {
603
- console.error(error);
604
- process.exit();
605
- });
606
- ```
607
-
608
- The code above will output the result as follows:
609
-
610
- ```
611
- WoHand (c1:2e:45:3e:20:08) was found.
612
- Pressing the switch...
613
- Connected.
614
- Disconnected.
615
- Done.
616
- ```
617
-
618
- Seeing the result, you would find the [`press()`](#SwitchbotDeviceWoHand-press-method) method automatically connects and disconnects the device.
619
-
620
- ### `ondisconnect` event handler
621
-
622
- The `ondisconnect` event handler will be called when the connection with the device is closed. Nothing will be passed to the handler. See the previous section "[`onconnect` event handler](#SwitchbotDevice-onconnect-event-handler)" for more details.
623
-
624
- ---
625
-
626
- ## `WoHand` object
627
-
628
- The `WoHand` object represents a Bot, which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
629
-
630
- Actually, the `WoHand` is an object inherited from the [`SwitchbotDevice`](#SwitchbotDevice-object). You can use not only the method described in this section but also the properties and methods implemented in the [`SwitchbotDevice`](#SwitchbotDevice-object) object.
631
-
632
- ### `press()` method
633
-
634
- The `press()` method sends a press command to the Bot. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
635
-
636
- If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the [`connect()`](#SwitchbotDevice-connect-method) method in advance.
637
-
638
- ```Typescript
639
- switchbot
640
- .discover({ model: "H", quick: true })
641
- .then((device_list) => {
642
- return device_list[0].press();
643
- })
644
- .then(() => {
645
- console.log("Done.");
646
- })
647
- .catch((error) => {
648
- console.error(error);
649
- });
650
- ```
651
-
652
- When the Bot receives this command, the Bot's arm will be put down (stretched), then put up (retracted) in a few seconds.
653
-
654
- ### `turnOn()` method
655
-
656
- The `turnOn()` method sends a turn-on command to the Bot. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
657
-
658
- If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the [`connect()`](#SwitchbotDevice-connect-method) method in advance.
659
-
660
- When the Bot receives this command, the Bot's arm will be put down (stretched) or put up (retracted) depending on the mode setting.
661
-
662
- | Mode | Inverse the on/off direction | Physical position of the arm |
663
- | :---------- | :--------------------------- | :------------------------------------ |
664
- | Press mode | N/A | Down (stretched), then Up (retracted) |
665
- | Switch mode | Disabled | Down (stretched) |
666
- | &nbsp; | Enabled | Up (retracted) |
667
-
668
- ```Typescript
669
- switchbot
670
- .discover({ model: "H", quick: true })
671
- .then((device_list) => {
672
- return device_list[0].turnOn();
673
- })
674
- .then(() => {
675
- console.log("Done.");
676
- })
677
- .catch((error) => {
678
- console.error(error);
679
- });
680
- ```
681
-
682
- ### `turnOff()` method
683
-
684
- The `turnOff()` method sends a turn-off command to the Bot. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
685
-
686
- If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the [`connect()`](#SwitchbotDevice-connect-method) method in advance.
687
-
688
- When the Bot receives this command, the Bot's arm will be put down (stretched) or put up (retracted) depending on the mode setting.
689
-
690
- | Mode | Inverse the on/off direction | Physical position of the arm |
691
- | :---------- | :--------------------------- | :------------------------------------ |
692
- | Press mode | N/A | Down (stretched), then Up (retracted) |
693
- | Switch mode | Disabled | Up (retracted) |
694
- | &nbsp; | Enabled | Down (stretched) |
695
-
696
- ```Typescript
697
- switchbot
698
- .discover({ model: "H", quick: true })
699
- .then((device_list) => {
700
- return device_list[0].turnOff();
701
- })
702
- .then(() => {
703
- console.log("Done.");
704
- })
705
- .catch((error) => {
706
- console.error(error);
707
- });
708
- ```
709
-
710
- ### `down()` method
711
-
712
- The `down()` method sends a down command to the Bot. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
713
-
714
- If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the [`connect()`](#SwitchbotDevice-connect-method) method in advance.
715
-
716
- When the Bot receives this command, the Bot's arm will be put down (stretched) regardless of the mode setting.
717
-
718
- ```Typescript
719
- switchbot
720
- .discover({ model: "H", quick: true })
721
- .then((device_list) => {
722
- return device_list[0].down();
723
- })
724
- .then(() => {
725
- console.log("Done.");
726
- })
727
- .catch((error) => {
728
- console.error(error);
729
- });
730
- ```
731
-
732
- ### `up()` method
733
-
734
- The `up()` method sends an up command to the Bot. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
735
-
736
- If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the [`connect()`](#SwitchbotDevice-connect-method) method in advance.
737
-
738
- When the Bot receives this command, the Bot's arm will be put up (retracted) regardless of the mode setting.
739
-
740
- ```Typescript
741
- switchbot
742
- .discover({ model: "H", quick: true })
743
- .then((device_list) => {
744
- return device_list[0].up();
745
- })
746
- .then(() => {
747
- console.log("Done.");
748
- })
749
- .catch((error) => {
750
- console.error(error);
751
- });
752
- ```
753
-
754
- ---
755
-
756
- ## `WoCurtain` object
757
-
758
- The `WoCurtain` object represents a Curtain, which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
759
-
760
- Actually, the `WoCurtain` is an object inherited from the [`SwitchbotDevice`](#SwitchbotDevice-object). You can use not only the method described in this section but also the properties and methods implemented in the [`SwitchbotDevice`](#SwitchbotDevice-object) object.
761
-
762
- ### `open()` method
763
-
764
- The `open()` method sends an open command to the Curtain. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
765
-
766
- If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the [`connect()`](#SwitchbotDevice-connect-method) method in advance.
767
-
768
- When the Curtain receives this command, the Curtain will open the curtain (0% position). If not calibrated, the Curtain does not move.
769
-
770
- The `open()` method receives an optional `mode` parameter. (See [`runToPos()`](#runtopos-method))
771
-
772
- ```Typescript
773
- switchbot
774
- .discover({ model: "c", quick: true })
775
- .then((device_list) => {
776
- return device_list[0].open();
777
- })
778
- .then(() => {
779
- console.log("Done.");
780
- })
781
- .catch((error) => {
782
- console.error(error);
783
- });
784
- ```
785
-
786
- ### `close()` method
787
-
788
- The `close()` method sends a close command to the Curtain. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
789
-
790
- If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the [`connect()`](#SwitchbotDevice-connect-method) method in advance.
791
-
792
- When the Curtain receives this command, the Curtain will close the curtain (100% position). If not calibrated, the Curtain does not move.
793
-
794
- The `close()` method receives an optional `mode` parameter. (See [`runToPos()`](#runtopos-method))
795
-
796
- ```Typescript
797
- switchbot
798
- .discover({ model: "c", quick: true })
799
- .then((device_list) => {
800
- return device_list[0].close();
801
- })
802
- .then(() => {
803
- console.log("Done.");
804
- })
805
- .catch((error) => {
806
- console.error(error);
807
- });
808
- ```
809
-
810
- ### `pause()` method
811
-
812
- The `pause()` method sends a pause command to the Curtain. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
813
-
814
- If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the [`connect()`](#SwitchbotDevice-connect-method) method in advance.
815
-
816
- When the Curtain receives this command, the Curtain will pause.
817
-
818
- ```Typescript
819
- switchbot
820
- .discover({ model: "c", quick: true })
821
- .then((device_list) => {
822
- return device_list[0].pause();
823
- })
824
- .then(() => {
825
- console.log("Done.");
826
- })
827
- .catch((error) => {
828
- console.error(error);
829
- });
830
- ```
831
-
832
- ### `runToPos()` method
833
-
834
- The `runToPos()` method sends a position command to the Curtain. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
835
-
836
- If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the [`connect()`](#SwitchbotDevice-connect-method) method in advance.
837
-
838
- When the Curtain receives this command, the Curtain will run to the percentage position. If not calibrated, the Curtain does not move.
839
-
840
- The `open()` method sends an open command to the Curtain. This method returns a `Promise` object. Nothing will be passed to the `resove()`.
841
-
842
- If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the [`connect()`](#SwitchbotDevice-connect-method) method in advance.
843
-
844
- When the Curtain receives this command, the Curtain will open the curtain (0% position). If not calibrated, the Curtain does not move.
845
-
846
- | Property | Type | Required | Description |
847
- | :-------- | :------ | :------- | :--------------------------------------------------------------------------------------------------------------------------------------------------- |
848
- | `percent` | Integer | Required | The percentage of target position (`0-100`). (e.g., `50`) |
849
- | `mode` | Integer | Optional | The running mode of Curtain. <br/>`0x00` - Performance mode.<br/> `0x01` - Silent mode. <br/>`0xff` - Default. Unspecified, from Curtain's settings. |
3
+ ![node-switchbot](https://raw.githubusercontent.com/OpenWonderLabs/node-switchbot/latest/branding/Node_x_SwitchBot.svg?sanitize=true)
850
4
 
851
- ```Typescript
852
- switchbot
853
- .discover({ model: "c", quick: true })
854
- .then((device_list) => {
855
- return device_list[0].runToPos(50);
856
- })
857
- .then(() => {
858
- console.log("Done.");
859
- })
860
- .catch((error) => {
861
- console.error(error);
862
- });
863
- ```
864
-
865
- ---
866
-
867
- ## `WoPlugMini` object
868
-
869
- The `WoPlugMini ` object represents a PlugMini, which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
870
-
871
- Actually, the `WoPlugMini ` is an object inherited from the [`SwitchbotDevice`](#SwitchbotDevice-object). You can use not only the method described in this section but also the properties and methods implemented in the [`SwitchbotDevice`](#SwitchbotDevice-object) object.
872
-
873
- ### `turnOn()` method
874
-
875
- The `turnOn()` method sends a turn-on command to the PlugMini. This method returns a `Promise` object. A `boolean` value indicating whether the PlugMini is on (`true`), is passed to the `resolve()` method of the Promise.
876
-
877
- If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the [`connect()`](#SwitchbotDevice-connect-method) method in advance.
878
-
879
- ### `turnOff()` method
880
-
881
- The `turnOff()` method sends a turn-off command to the PlugMini. This method returns a `Promise` object. A `boolean` value indicating whether the PlugMini is off (`false`), is passed to the `resolve()` method of the Promise.
5
+ # Node-SwitchBot
882
6
 
883
- If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the [`connect()`](#SwitchbotDevice-connect-method) method in advance.
7
+ [![npm version](https://badgen.net/npm/v/node-switchbot)](https://www.npmjs.com/package/node-switchbot)
8
+ [![npm downloads](https://badgen.net/npm/dt/node-switchbot)](https://www.npmjs.com/package/node-switchbot)
884
9
 
885
- ### `toggle()` method
10
+ </div>
886
11
 
887
- The `toggle()` method sends a toggle command to the PlugMini, toggling between the on and off state. This method returns a `Promise` object. A `boolean` value indicating whether the PlugMini is on (`true`) or off (`false`), is passed to the `resolve()` method of the Promise.
12
+ The `node-switchbot` is a Node.js module that allows you to interact with various SwitchBot devices. You can control your [SwitchBot (Bot)'s](https://www.switch-bot.com/bot) arm, operate your [SwitchBot Curtain](https://www.switch-bot.com/products/switchbot-curtain), and manage your [SwitchBot Lock](https://www.switch-bot.com/products/switchbot-lock). Additionally, you can monitor temperature and humidity using the [SwitchBot Thermometer & Hygrometer (Meter)](https://www.switch-bot.com/meter), and check the status of the [SwitchBot Motion Sensor](https://www.switch-bot.com/products/motion-sensor) and [SwitchBot Contact Sensor](https://www.switch-bot.com/products/contact-sensor).
888
13
 
889
- If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the [`connect()`](#SwitchbotDevice-connect-method) method in advance.
14
+ This module now supports both Bluetooth Low Energy (BLE) and the SwitchBot OpenAPI, providing more flexibility and options for interacting with your devices.
890
15
 
891
- ---
16
+ Please note that most of this module was developed by referencing the official [BLE API](https://github.com/OpenWonderLabs/SwitchBotAPI-BLE) and [OpenAPI](https://github.com/OpenWonderLabs/SwitchBotAPI) documentation. However, some functionalities were developed through trial and error, so there might be inaccuracies in the information obtained from this module.
892
17
 
893
18
  ---
894
19
 
895
- ## `WoSmartLock` object
896
-
897
- The `WoSmartLock ` object represents a SmartLock, which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
898
-
899
- Actually, the `WoSmartLock ` is an object inherited from the [`SwitchbotDevice`](#SwitchbotDevice-object). You can use not only the method described in this section but also the properties and methods implemented in the [`SwitchbotDevice`](#SwitchbotDevice-object) object.
900
-
901
- ### `setKey()` method
902
-
903
- The `setKey()` method initialises the key information required for encrypted communication with the SmartLock
904
-
905
- This must be set before any control commands are sent to the device. To obtain the key information you will need to use an external tool - see [`pySwitchbot`](https://github.com/Danielhiversen/pySwitchbot/tree/master?tab=readme-ov-file#obtaining-locks-encryption-key) project for an example script.
906
-
907
- | Property | Type | Description |
908
- | :-------------- | :----- | :----------------------------------------------------------------------------------------------- |
909
- | `keyId` | String | unique2 character ID for the key. (e.g., `"ff"`) returned from the SwitchBot api for your device |
910
- | `encryptionKey` | String | the unique encryption key returned from the SwitchBot api for your device |
911
-
912
- ### `lock()` method
913
-
914
- The `lock()` method sends a lock command to the SmartLock. This method returns a `Promise` object. A `boolean` value indicating whether the SmartLock is locked (`true`), is passed to the `resolve()` method of the Promise.
915
-
916
- If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the [`connect()`](#SwitchbotDevice-connect-method) method in advance.
917
-
918
- ### `unlock()` method
919
-
920
- The `unlock()` method sends an unlock command to the SmartLock. This method returns a `Promise` object. A `boolean` value indicating whether the SmartLock is locked (`false`), is passed to the `resolve()` method of the Promise.
921
-
922
- If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the [`connect()`](#SwitchbotDevice-connect-method) method in advance.
923
-
924
- ### `unlockNoUnlatch()` method
925
-
926
- The `unlockNoUnlatch()` method sends a partial unlock command to the SmartLock, unlocking without the full unlatch.
927
-
928
- If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the [`connect()`](#SwitchbotDevice-connect-method) method in advance.
929
-
930
- ### `info()` method
931
-
932
- The `info()` method retreieves state information from the SmartLock, This method returns a `Promise` object. An `object` value indicating with the state infor, is passed to the `resolve()` method of the Promise.
933
-
934
- If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the [`connect()`](#SwitchbotDevice-connect-method) method in advance.
935
-
936
- ## Advertisement data
937
-
938
- After the [`startScan()`](#startscan-method) method is invoked, the [`onadvertisement`](#Switchbot-onadvertisement-event-handler) event handler will be called whenever an advertising packet comes from the switchbot devices. An object containing the properties as follows will be passed to the event handler:
939
-
940
- | Property | Type | Description |
941
- | :------------ | :------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------- |
942
- | `id` | String | ID of the device. (e.g., `"cb4eb903c96d"`) |
943
- | `address` | String | MAC address of the device. Basically it is as same as the value of the `id` except that this value includes `:` in the string. (e.g., `"cb:4e:b9:03:c9:6d"`) |
944
- | `rssi` | Integer | RSSI. (e.g., `-62`) |
945
- | `serviceData` | Object | An object including the device-specific data. |
946
-
947
- The structures of the `serviceData` are described in the following sections.
948
-
949
- ### Bot (WoHand)
950
-
951
- Example of the advertisement data:
952
-
953
- ```json
954
- {
955
- "id": "c12e453e2008",
956
- "address": "c1:2e:45:3e:20:08",
957
- "rssi": -61,
958
- "serviceData": {
959
- "model": "H",
960
- "modelName": "WoHand",
961
- "mode": true,
962
- "state": false,
963
- "battery": 100
964
- }
965
- }
966
- ```
967
-
968
- Structure of the `serviceData`:
969
-
970
- | Property | Type | Description |
971
- | :---------- | :------ | :------------------------------------------------------------------------------------------------------------------------------------------- |
972
- | `model` | String | This value is always `"H"`, which means "Bot (WoHand)". |
973
- | `modelName` | String | This value is always `"WoHand"`, which means "Bot". |
974
- | `mode` | Boolean | This indicates the mode setting. When the mode is "Switch mode", this value is `true`. When the mode is "Press mode", this value is `false`. |
975
- | `state` | Boolean | This value indicates whether the switch status is ON or OFF. |
976
- | `battery` | Integer | (**experimental**) This value indicates the battery level (`%`). |
977
-
978
- The `mode` can be changed only using the official smartphone app. The node-switchbot does not support changing the mode because the BLE protocol is non-public.
979
-
980
- If the `mode` is `false`, which means the "Press mode" is selected, the `state` is always `false`. If the `mode` is `true`, which means the "Switch mode" is selected, the `state` represents the logical state (ON or OFF). Note that it does _not_ mean the physical arm position. The physical arm position depends on the setting "Inverse the on/off direction" on the official smartphone app.
981
-
982
- | "Inverse the on/off direction" | Value of the `state` | Logical state | Physical arm position |
983
- | :----------------------------- | :------------------- | :------------ | :-------------------- |
984
- | disabled | `true` | OFF | Up (retracted) |
985
- | &nbsp; | `false` | ON | Down (stretched) |
986
- | enabled | `true` | OFF | Down (stretched) |
987
- | &nbsp; | `false` | ON | Up (retracted) |
988
-
989
- The `battery` is _experimental_ for now. I'm not sure whether the value is correct or not. Never trust this value for now.
990
-
991
- ### Meter (WoSensorTH)
992
-
993
- Example of the advertisement data:
994
-
995
- ```json
996
- {
997
- "id": "cb4eb903c96d",
998
- "address": "cb:4e:b9:03:c9:6d",
999
- "rssi": -70,
1000
- "serviceData": {
1001
- "model": "T",
1002
- "modelName": "WoSensorTH",
1003
- "temperature": {
1004
- "c": 25.2,
1005
- "f": 77.4
1006
- },
1007
- "fahrenheit": false,
1008
- "humidity": 43,
1009
- "battery": 100
1010
- }
1011
- }
1012
- ```
1013
-
1014
- Structure of the `data`:
1015
-
1016
- | Property | Type | Description |
1017
- | :--------------- | :------ | :----------------------------------------------------------------------------------------------------------- |
1018
- | `model` | String | This value is always `"T"`, which means "Meter (WoSensorTH)". |
1019
- | `modelName` | String | This value is always `"WoSensorTH"`, which means "Meter". |
1020
- | `temperature` | Object |
1021
- | &nbsp;&nbsp; `c` | Float | Temperature (degree Celsius/°C) |
1022
- | &nbsp;&nbsp; `f` | Float | Temperature (degree Fahrenheit/℉) |
1023
- | `fahrenheit` | Boolean | The flag whether the Meter shows Fahrenheit (`true`) or Celsius (`false`) for the temperature on the display |
1024
- | `humidity` | Integer | Humidity (`%`) |
1025
- | `battery` | Integer | (**experimental**) This value indicates the battery level (`%`). |
1026
-
1027
- The `fahrenheit` indicates the setting on the device. Note that it does _not_ indicate the setting on the official smartphone app. The setting of the temperature unit on the device and the setting on the app are independent.
1028
-
1029
- The `battery` is _experimental_ for now. I'm not sure whether the value is correct or not. Never trust this value for now.
1030
-
1031
- ### Curtain (WoCurtain)
20
+ ## [Installation](https://npmjs.org/node-switchbot)
1032
21
 
1033
- Example of the advertisement data:
22
+ To install the `node-switchbot` module within your project, use the following command:
1034
23
 
1035
- ```json
1036
- {
1037
- "id": "ec58c5d00111",
1038
- "address": "ec:58:c5:d0:01:11",
1039
- "rssi": -39,
1040
- "serviceData": {
1041
- "model": "c",
1042
- "modelName": "WoCurtain",
1043
- "calibration": true,
1044
- "battery": 91,
1045
- "position": 1,
1046
- "lightLevel": 1
1047
- }
1048
- }
24
+ ```sh
25
+ $ npm install --save node-switchbot
1049
26
  ```
1050
27
 
1051
- Structure of the `serviceData`:
1052
-
1053
- | Property | Type | Description |
1054
- | :------------ | :------ | :--------------------------------------------------------------------------------- |
1055
- | `model` | String | This value is `"c"`, which means "Curtain (WoCurtain)". |
1056
- | | | or `"{"`, which means "Curtain 3 (WoCurtain)". |
1057
- | `modelName` | String | This value is always `"WoCurtain"`, which means "Curtain". |
1058
- | `calibration` | Boolean | This value indicates the calibration status (`true` or `false`). |
1059
- | `battery` | Integer | This value indicates the battery level (`1-100`, `%`). |
1060
- | `position` | Integer | This value indicates the percentage of current position (`0-100`, 0 is open, `%`). |
1061
- | `lightLevel` | Integer | This value indicates the light level of the light source currently set (`1-10`). |
1062
-
1063
- ### Contact (WoContact)
1064
-
1065
- Example of the advertisement data:
1066
-
1067
- ```json
1068
- {
1069
- "id": "f0cda125e3ec",
1070
- "address": "f0:cd:a1:25:e3:ec",
1071
- "rssi": -56,
1072
- "serviceData": {
1073
- "model": "d",
1074
- "modelName": "WoContact",
1075
- "movement": false,
1076
- "battery": 95,
1077
- "doorState": "close",
1078
- "lightLevel": "bright"
1079
- }
1080
- }
1081
- ```
28
+ ## [BLE (Bluetooth Low Energy)](BLE.md)
1082
29
 
1083
- Structure of the `serviceData`:
1084
-
1085
- | Property | Type | Description |
1086
- | :----------- | :------ | :--------------------------------------------------------------------------- |
1087
- | `model` | String | This value is always `"c"`, which means "Contact (WoContact)". |
1088
- | `modelName` | String | This value is always `"WoContact"`, which means "Contact". |
1089
- | `movement` | Boolean | This value indicates the motion status (`true` or `false`). |
1090
- | `battery` | Integer | This value indicates the battery level (`1-100`, `%`). |
1091
- | `doorState` | String | This value indicates the door Status (`close`, `open`, `timeout no closed`). |
1092
- | `lightLevel` | String | This value indicates the light level (`dark`, `bright`). |
1093
-
1094
- ### Motion (WoMotion)
1095
-
1096
- Example of the advertisement data:
1097
-
1098
- ```json
1099
- {
1100
- "id": "e7216fa344a9",
1101
- "address": "e7:21:6f:a3:44:a9",
1102
- "rssi": -53,
1103
- "serviceData": {
1104
- "model": "s",
1105
- "modelName": "WoMotion",
1106
- "movement": false,
1107
- "battery": 96,
1108
- "lightLevel": "bright"
1109
- }
1110
- }
1111
- ```
1112
-
1113
- Structure of the `serviceData`:
1114
-
1115
- | Property | Type | Description |
1116
- | :----------- | :------ | :----------------------------------------------------------- |
1117
- | `model` | String | This value is always `"s"`, which means "Motion (WoMotion)". |
1118
- | `modelName` | String | This value is always `"WoMotion"`, which means "Motion". |
1119
- | `movement` | Boolean | This value indicates the motion status (`true` or `false`). |
1120
- | `battery` | Integer | This value indicates the battery level (`1-100`, `%`). |
1121
- | `lightLevel` | String | This value indicates the light level (`dark`, `bright`). |
1122
-
1123
- ### PlugMini (WoPlugMini)
1124
-
1125
- Example of the advertisement data:
1126
-
1127
- ```json
1128
- {
1129
- "id": "cd2409ea3e9441f87d4580e0380a62bf",
1130
- "address": "60:55:f9:35:f6:a6",
1131
- "rssi": -50,
1132
- "serviceData": {
1133
- "model": "j",
1134
- "modelName": "WoPlugMini",
1135
- "state": "off",
1136
- "delay": false,
1137
- "timer": false,
1138
- "syncUtcTime": true,
1139
- "wifiRssi": 48,
1140
- "overload": false,
1141
- "currentPower": 0
1142
- }
1143
- }
1144
- ```
1145
-
1146
- Structure of the `serviceData`:
1147
-
1148
- | Property | Type | Description |
1149
- | :------------- | :------ | :--------------------------------------------------------------------------------- |
1150
- | `model` | String | This value is always `"j"` or `"g"`, which means "PlugMini" (JP or US). |
1151
- | `modelName` | String | This value is always `"WoPlugMini"`, which means "PlugMini". |
1152
- | `state ` | Boolean | This value indicates whether the plug mini is turned on (`true`) or not (`false`). |
1153
- | `delay` | Boolean | Indicates whether a delay is present. |
1154
- | `timer` | Boolean | Indicates whether a timer is present. |
1155
- | `syncUtcTime` | boolean | Indicates whether the UTC time has been synchronized. |
1156
- | `overload` | boolean | Indicates whether the Plug Mini is overloaded, more than 15A current overload. |
1157
- | `currentPower` | Float | Current power consumption in Watts. |
1158
-
1159
- ---
1160
-
1161
- ### SmartLock (WoSmartLock)
1162
-
1163
- Example of the advertisement data:
1164
-
1165
- ```json
1166
- {
1167
- "id": "d30864110b8c",
1168
- "address": "d3:08:64:11:0b:8c",
1169
- "rssi": -52,
1170
- "serviceData": {
1171
- "model": "o",
1172
- "modelName": "WoSmartLock",
1173
- "battery": 100,
1174
- "calibration": true,
1175
- "status": "LOCKED",
1176
- "update_from_secondary_lock": false,
1177
- "door_open": false,
1178
- "double_lock_mode": false,
1179
- "unclosed_alarm": false,
1180
- "unlocked_alarm": false,
1181
- "auto_lock_paused": false
1182
- }
1183
- }
1184
- ```
30
+ To see a breakdown of how to use the BLE functionality of this project, visit the [BLE (Bluetooth Low Energy)](BLE.md) documentation.
1185
31
 
1186
- Structure of the `serviceData`:
32
+ ## [OpenAPI](OpenAPI.md)
1187
33
 
1188
- | Property | Type | Description |
1189
- | :--------------------------- | :------ | :---------------------------------------------------------------------------------- |
1190
- | `model` | String | This value is `"o"`, which means "Lock (WoSmartLock)". |
1191
- | `modelName` | String | This value is always `"WoSmartLock"`, which means "Lock". |
1192
- | `battery` | Integer | This value indicates the battery level (`1-100`, `%`). |
1193
- | `calibration` | Boolean | This value indicates the calibration status (`true` or `false`). |
1194
- | `status` | String | This value indicates the current locked state. Possible values: |
1195
- | | | `"LOCKED"`, `"UNLOCKED"`, `"LOCKING"`, `"UNLOCKING"` |
1196
- | | | `"LOCKING_STOP"`, `"UNLOCKING_STOP"` (stuck when locking or unlocking respectively) |
1197
- | | | `"NOT_FULLY_LOCKED"` (eu model only), `"UNKNOWN"` (fallback: must be some error) |
1198
- | `update_from_secondary_lock` | Boolean | ?? |
1199
- | `door_open` | Boolean | door open status - whether the door is not detecting the sensor magnet |
1200
- | `double_lock_mode` | Boolean | dual lock mode enabled status - two locks working simultaneously |
1201
- | `unclosed_alarm` | Boolean | enabled status for door ajar alarm function |
1202
- | `unlocked_alarm` | Boolean | whether the alarm function is enabled for door left unlocked |
1203
- | `auto_lock_paused` | Boolean | auto lock mode paused |
1204
- | `night_latch` | Boolean | night latch mode enabled (eu firmware only) |
34
+ To see a breakdown of how to use the OpenAPI functionality of this project, visit the [OpenAPI](OpenAPI.md) documentation.
1205
35
 
1206
36
  ## References
1207
37
 
1208
- - [Switchbot official global site](https://www.switch-bot.com/)
1209
- - [GitHub - OpenWonderLabs/SwitchBotAPI-BLE](https://github.com/OpenWonderLabs/SwitchBotAPI-BLE)
38
+ - [SwitchBot (Official website)](https://www.switch-bot.com/)
39
+ - [Facebook @SwitchBotRobot](https://www.facebook.com/SwitchBotRobot/)
40
+ - [Twitter @SwitchBot](https://twitter.com/switchbot)