Wiki source code of openHAB with Bluetooth

Last modified by Normann P. Nielsen on 2025/12/12 15:15

Show last authors
1 = Topics =
2
3 {{toc/}}
4
5
6 {{error}}During another problem/trouble shooting I ran:
7
8
9 {{code}}
10 sudo systemctl stop openhab2
11 sudo openhab-cli clean-cache
12 sudo systemctl start openhab2
13 {{/code}}
14
15 That seems to remove the BT Bindings... but a reinstall fixed it (and no Things was lost){{/error}}
16
17
18
19
20 As my [[openHAB>>https://www.openhab.org/]] installation is on a Laptop with Ubuntu 18-04 (Server, no UI) i knew that [[Bluetooth>>https://en.wikipedia.org/wiki/Bluetooth]] (BT) was somewhat avaliable.
21
22 The main purpose of playing with BT is "whos home" and "when has a devices been seen last time" - do look at [[this link>>https://github.com/sputnikdev/eclipse-smarthome-bluetooth-binding]], as we will use this excellent binding.
23
24 An interesting part to notice there is:
25 {{success}}The easiest and most effective way to detect presence is to use so called [["Bluetooth beacon">>https://github.com/sputnikdev/eclipse-smarthome-bluetooth-binding/blob/master/tags.md]] devices.
26
27 Normally, most of Bluetooth devices broadcast messages, however there are some devices that try to hide themselves from receivers providing privacy for their owners. Many of modern mobile phones (iPhone and Android) every so often (roughly every 10 minutes) randomly generate a new Bluetooth address and abandon old one making it impossible to track them by its address.{{/success}}
28
29
30 The latter part being a problem I think. Do read these links: [[Bluetooth Technology Protecting Your Privacy>>https://blog.bluetooth.com/bluetooth-technology-protecting-your-privacy]] and  [[MAC address randomization joins Apples heap of iOS 8.....>>https://appleinsider.com/articles/14/06/09/mac-address-randomization-joins-apples-heap-of-ios-8-privacy-improvements]]
31 {{success}}Theres a excellent community thread at [[https://community.openhab.org/t/3rd-party-bluetooth-binding-beta-testers-needed]] for this Binding{{/success}}
32
33
34 =
35 Add BT Support in Ubuntu =
36
37 First discovery was that the Ubuntu OS had no BT installed, so we need to do this:
38
39
40 {{code}}
41 sudo apt-get install bluez
42 sudo systemctl status bluetooth
43 ? bluetooth.service - Bluetooth service
44 Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
45 Active: active (running) since Wed 2019-01-23 18:27:43 UTC; 2 days ago
46 Docs: man:bluetoothd(8)
47 Main PID: 14880 (bluetoothd)
48 Status: "Running"
49 Tasks: 1 (limit: 3930)
50 CGroup: /system.slice/bluetooth.service
51 ??14880 /usr/lib/bluetooth/bluetoothd
52
53 Jan 23 18:27:43 robin systemd[1]: Starting Bluetooth service...
54 Jan 23 18:27:43 robin bluetoothd[14880]: Bluetooth daemon 5.48
55 Jan 23 18:27:43 robin bluetoothd[14880]: Starting SDP server
56 Jan 23 18:27:43 robin systemd[1]: Started Bluetooth service.
57 Jan 23 18:27:43 robin bluetoothd[14880]: Bluetooth management interface 1.14 initialized
58 {{/code}}
59
60
61
62 Ok, so BT was up and running, and to make sure openHAB could use it:
63
64
65 {{code}}
66 sudo usermod -a -G bluetooth openhab
67 sudo systemctl daemon-reload
68 sudo systemctl restart bluetooth
69 {{/code}}
70
71
72
73 = Test discovery and functionality =
74
75 A little testing of discovery etc:
76
77
78 {{code}}
79 sudo bluetoothctl
80 [NEW] Controller F0:03:8C:61:7E:2E Bluetooth robin [default]
81 [NEW] Device 08:6D:41:E7:FF:7B 08-6D-41-E7-FF-7B
82 [NEW] Device 53:EA:0B:88:DC:13 53-EA-0B-88-DC-13
83 Agent registered
84 [CHG] Device 08:6D:41:E7:FF:7B RSSI: -79
85 [bluetooth]# list
86 Controller F0:03:8C:61:7E:2E Bluetooth robin [default]
87 [bluetooth]#
88 [bluetooth]# show
89 Controller F0:03:8C:61:7E:2E (public)
90 Name: robin
91 Alias: Bluetooth robin
92 Class: 0x0000010c
93 Powered: yes
94 Discoverable: no
95 Pairable: yes
96 UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
97 UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb)
98 UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb)
99 UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
100 UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
101 Modalias: usb:v1D6Bp0246d0530
102 Discovering: yes
103 [bluetooth]#
104 {{/code}}
105
106
107
108 Scan for devices:
109
110
111 {{code}}
112 [bluetooth]# scan on
113 Discovery started
114 [CHG] Device 08:6D:41:E7:FF:7B RSSI: -79
115 [CHG] Device 08:6D:41:E7:FF:7B RSSI: -78
116 [CHG] Device 53:EA:0B:88:DC:13 RSSI: -75
117 [CHG] Device 53:EA:0B:88:DC:13 ManufacturerData Key: 0x004c
118 [CHG] Device 53:EA:0B:88:DC:13 ManufacturerData Value:
119 0c 0e 08 f4 f0 09 f7 7f b0 f5 01 69 dd 37 b6 eb ...........i.7..
120 [CHG] Device 53:EA:0B:88:DC:13 RSSI: -75
121 [CHG] Device 53:EA:0B:88:DC:13 ManufacturerData Key: 0x004c
122 [CHG] Device 53:EA:0B:88:DC:13 ManufacturerData Value:
123 0c 0e 08 f5 f0 21 56 5b 46 b4 8c 0a 54 79 16 02 .....!V[F...Ty..
124 [CHG] Device 08:6D:41:E7:FF:7B RSSI: -78
125 [CHG] Device 53:EA:0B:88:DC:13 RSSI: -76
126 [CHG] Device 08:6D:41:E7:FF:7B RSSI: -81
127 [bluetooth]#
128 [CHG] Device 53:EA:0B:88:DC:13 RSSI: -78
129 {{/code}}
130
131
132
133 = Installing Addons in openHAB =
134
135 OK - so we are ready for openHAB - the short story is to follow [[https://github.com/sputnikdev/eclipse-smarthome-bluetooth-binding]] - (remember to press "Save" in the Configuration → System → Market dialog :) ) You need to use a 3rd party BT binding that s not pr. default available in openHAB.
136
137 Follow the [[installation>>https://github.com/sputnikdev/eclipse-smarthome-bluetooth-binding/blob/master/installation.md]], and You should be running - this should be quite clear in the inbox, it should be populated with discovered devices..:
138
139 [[image:Screenshot 2019-01-26 at 12.03.19.png||width="593"||height="250"]]
140
141
142
143 = Managing BT Devices =
144
145 This is actually where it gets tricky and I am partly **stucked,** as I am having a hard time pairing a lot (Yes, You have a lot of BT devices in Your home and the tip in the top Tip Box may play a part here ) and their [[MAC adresses>>https://en.wikipedia.org/wiki/MAC_address]] to real physical devices.
146
147 BT Devices has a [[MAC address>>https://en.wikipedia.org/wiki/MAC_address]] like a Network Interface, and there are several ways to discover devices and addresses:
148
149
150
151
152 {{code}}
153 batman:~ bnp$ system_profiler SPBluetoothDataType
154 Bluetooth:
155
156 Apple Bluetooth Software Version: 6.0.9f2
157 Hardware, Features, and Settings:
158 Name: batman
159 Address: 08-6D-41-E7-FF-7B
160 Bluetooth Low Energy Supported: Yes
161 Handoff Supported: Yes
162 Instant Hot Spot Supported: Yes
163 Manufacturer: Broadcom
164 Transport: USB
165 Chipset: 20702B0
166 Firmware Version: v149 c9314
167 Bluetooth Power: On
168 Discoverable: Off
169 Connectable: Yes
170 Auto Seek Pointing: On
171 Remote wake: On
172 Vendor ID: 0x05AC
173 Product ID: 0x8289
174 HCI Version: 4.0 (0x6)
175 HCI Revision: 0x2462
176 LMP Version: 4.0 (0x6)
177 LMP Subversion: 0x4195
178 Device Type (Major): Computer
179 Device Type (Complete): Mac Desktop
180 Composite Class Of Device: 0x380104
181 Device Class (Major): 0x01
182 Device Class (Minor): 0x01
183 Service Class: 0x1C0
184 Auto Seek Keyboard: On
185 Devices (Paired, Configured, etc.):
186 Normann P. Nielsen’s Mouse #2:
187 Address: B8-44-D9-F1-15-59
188 Major Type: Peripheral
189 Minor Type: Mouse
190 Services: Magic Mouse 2
191 Paired: Yes
192 Configured: Yes
193 Connected: Yes
194 Manufacturer: Broadcom (0x5, 0x240C)
195 Battery Level: 67%
196 Firmware Version: 0x0064
197 Vendor ID: 0x004C
198 Product ID: 0x0269
199 Class of Device: 0x05 0x20 0x0580
200 AFH: On
201 AFH Map: F9FFFF7FFFFFDBFFFF7F
202 RSSI: -45
203 Role: Master
204 Connection Mode: Sniff Mode
205 Interval: 11.25 ms
206 Host Connectable: Yes
207 EDR Supported: Yes
208 eSCO Supported: No
209 SSP Supported: Yes
210 Soveværelse:
211 Address: D0-03-4B-E5-A3-73
212 Major Type: Miscellaneous
213 Minor Type: Unknown
214 Services:
215 Paired: No
216 Configured: Yes
217 Connected: No
218 Class of Device: 0x00 0x00 0x0000
219 Apple TV:
220 Address: C8-D0-83-C5-BB-4C
221 Major Type: Miscellaneous
222 Minor Type: Unknown
223 Services:
224 Paired: No
225 Configured: Yes
226 Connected: No
227 Class of Device: 0x00 0x00 0x0000
228 Anette W. Nielsens iPhone:
229 Address: 4C-7C-5F-7D-8A-4A
230 Major Type: Miscellaneous
231 Minor Type: Unknown
232 Services:
233 Paired: No
234 Configured: Yes
235 Connected: No
236 Class of Device: 0x00 0x00 0x0000
237 jarvis (2):
238 Address: 78-4F-43-A0-21-3A
239 Major Type: Miscellaneous
240 Minor Type: Unknown
241 Services:
242 Paired: No
243 Configured: Yes
244 Connected: No
245 Class of Device: 0x00 0x00 0x0000
246 Normann P. Nielsen’s iPad:
247 Address: 54-AE-27-10-02-87
248 Major Type: Miscellaneous
249 Minor Type: Unknown
250 Services:
251 Paired: No
252 Configured: Yes
253 Connected: No
254 Class of Device: 0x00 0x00 0x0000
255 Normann P.'s iPhone:
256 Address: 90-B0-ED-99-75-28
257 Major Type: Miscellaneous
258 Minor Type: Unknown
259 Services:
260 Paired: No
261 Configured: Yes
262 Connected: No
263 Class of Device: 0x00 0x00 0x0000
264 iPhone:
265 Address: 80-EA-96-16-60-B7
266 Major Type: Miscellaneous
267 Minor Type: Unknown
268 Services:
269 Paired: No
270 Configured: Yes
271 Connected: No
272 Class of Device: 0x00 0x00 0x0000
273 Normann P.'s iPhone:
274 Address: 34-AB-37-EF-C3-CE
275 Major Type: Miscellaneous
276 Minor Type: Unknown
277 Services:
278 Paired: No
279 Configured: Yes
280 Connected: No
281 Class of Device: 0x00 0x00 0x0000
282 Services:
283 Bluetooth File Transfer:
284 Folder other devices can browse: ~/Public
285 When receiving items: Accept all without warning
286 State: Disabled
287 Bluetooth File Exchange:
288 Folder for accepted items: ~/Downloads
289 When other items are accepted: Save to location
290 When receiving items: Accept all without warning
291 State: Disabled
292 Bluetooth Internet Sharing:
293 State: Disabled
294 Incoming Serial Ports:
295 Bluetooth-Incoming-Port:
296 RFCOMM Channel: 3
297 Requires Authentication: No
298
299 batman:~ bnp$
300 {{/code}}
301
302
303 {{code}}
304 sudo bluetoothctl
305 [NEW] Controller F0:03:8C:61:7E:2E Bluetooth robin [default]
306 [NEW] Device 08:6D:41:E7:FF:7B 08-6D-41-E7-FF-7B
307 [NEW] Device 53:EA:0B:88:DC:13 53-EA-0B-88-DC-13
308 Agent registered
309 [CHG] Device 08:6D:41:E7:FF:7B RSSI: -79
310 [bluetooth]# list
311 Controller F0:03:8C:61:7E:2E Bluetooth robin [default]
312 [bluetooth]#
313 [bluetooth]# show
314 Controller F0:03:8C:61:7E:2E (public)
315 Name: robin
316 Alias: Bluetooth robin
317 Class: 0x0000010c
318 Powered: yes
319 Discoverable: no
320 Pairable: yes
321 UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
322 UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb)
323 UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb)
324 UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
325 UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
326 Modalias: usb:v1D6Bp0246d0530
327 Discovering: yes
328 [bluetooth]#
329 {{/code}}
330
331 [[image:unnamed-1.jpg||width="1000"]]
332
333 [[image:unnamed.jpg||width="1000"]]
334
335 [[image:unnamed-2.jpg||width="1000"]]
336 {{info}}What I do notice, it the the name of the devices is rarely present, and that the [[MAC address>>https://en.wikipedia.org/wiki/MAC_address]] rarely matches the MAC addresses found in openHAB. That is currently an ongoing investigation. Any good clues here? Feel free to mail me at [[bnp@mos-eisley.dk>>mailto:bnp@mos-eisley.dk]] or drop a comment
337
338 There are several lookup tools like [[https://macaddresschanger.com/bluetooth-mac-lookup]] that should help, but I find the reliability of them low... often my MACs are not resolved to a Vendor{{/info}}
339
340
341
342
343 = A Thing in openHAB =
344
345 A few samples of discovered BT [[Things>>https://www.openhab.org/docs/configuration/things.html]] in [[openHAB>>https://www.openhab.org/]], its worth noticing that the capabilities can differ quite a lot - refer to[[ Bluetooth on Wikipedia>>https://en.wikipedia.org/wiki/Bluetooth]]; currently the specs range from version 1 to 5:
346
347 [[image:Screenshot 2019-01-26 at 12.18.05.png||width="1000"]]
348
349 [[image:Screenshot 2019-01-26 at 12.16.19.png||width="1000"]]
350
351 [[image:Screenshot 2019-01-26 at 12.17.44.png||width="1000"]]