kenhuang / docker-homebridge

Homebridge Docker. HomeKit support for the impatient using Docker on x86_64 or Raspberry Pi (armhf).
https://hub.docker.com/r/kenhuang/docker-homebridge/
3 stars 1 forks source link

Support Clipsal Control Link and Wiser Room #1

Open asomervell opened 6 years ago

asomervell commented 6 years ago

Clipsal has released their very low cost "Iconic" range of light switches that will replace the old school ones you see in every house.

They have "mechs" that are programmable by BLE and work together in a room.

https://www.clipsal.com/iconic#new-technology

We must be able to intercept or control them by BLE with the homebridge for epic dimmer and power and lighting control in AU, NZ!

https://www.youtube.com/watch?v=TMt_zeA56LI

http://www.clipsal.com/Trade/Products/ProductDetail?CatNo=41EPBM

asomervell commented 6 years ago

And Google Assistant https://developers.google.com/assistant/sdk/overview

BLE info https://www.jaredwolff.com/blog/get-started-with-bluetooth-low-energy/

kenhuang commented 6 years ago

Just need another plugin: https://github.com/anthonywebb/homebridge-cbus

asomervell commented 6 years ago

Mmmm cbus != BLE with new stuff though. Maybe they do talk.

NZ Site and brand https://www.pdl.co.nz/Trade/Ranges/Products/Switch-Socket-Ranges/Iconic

Maybe the Saturn brand is the one to go with that does do cbus https://www.pdl.co.nz/Trade/Ranges/Products/Switch-Socket-Ranges/Saturn-Zen http://updates.clipsal.com/ClipsalOnline/Files/Brochures/A0000291.pdf

On further investigation, cbus requires you to wire everything back to controllers (rewire the house). But I can see exactly how if that was done in the first place you'd be stoked with that integration!

sj26 commented 5 years ago

I’m planning to install Clipsal Iconic BLE switches into my new apartment. I’m already using homebridge quite a bit, so I’ll probably write a homebridge plug-in. I’m writing this partly to advertise my interest and intent, but also to know if someone beats me to it. :-)

sj26 commented 5 years ago

It looks like there’s already a plug-in for wiser, but nothing to directly control the ble switches yet:

https://github.com/paulw11/homebridge-wiser

CalumOchkas commented 5 years ago

Hey @sj26 - did you have any luck with this? About to buy a whole heap of switches in the next few days, wondering if I should invest in the BLE options

sj26 commented 5 years ago

I haven't managed to grab any BLE switches myself yet, sorry. :-(

sj26 commented 5 years ago

It sounds like installing the Iconic stuff is a good, future-proof plan, though. The mechanisms can be swapped out for BLE options later. And there are rumours that Clipsal may end up offering direct HomeKit and other integrations themselves.

CalumOchkas commented 5 years ago

Don't be sorry! Let us know if you have any luck once you get your hands on one. I'll grab just one for now so I can start playing, and I'll do the same!

RobDeVoer commented 4 years ago

Trying to decide to get PDL/Schneider iconic range for my new home or not. Unless there are any updates since Aug 2019 I think I may just opt to place SONOFF MINIS behind my switches and either control those through my own code or a Home Assistant setup. All advice/critique is welcome. Only 1-2 weeks away from getting the gib on the walls... ;)

CalumOchkas commented 4 years ago

Hey mate! I'm using the PDL BLE dimmers now. They're OK, do as they say but I've struggled to figure out the correct codes to send commands via a Bluetooth transmitter. Also, I've struggled to find an LED bulb that dims nicely. They all flicker, some worse than others, and completely randomly. I don't have this problem with incandescent bulbs. When I spoke to electricians they just say that's to expect with the push button dimmers vs LED bulbs. YMMV

On Fri, 13 Mar 2020, 20:44 Rob de Voer, notifications@github.com wrote:

Trying to decide to get PDL/Schneider iconic range for my new home or not. Unless there are any updates since Aug 2019 I think I may just opt to place SONOFF MINIS behind my switches and either control those through my own code or a Home Assistant setup. All advice/critique is welcome. Only 1-2 weeks away from getting the gib on the walls... ;)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kenhuang/docker-homebridge/issues/1#issuecomment-598592417, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHJ6XOSJI4YXE2ZFSGIQIZTRHHP2JANCNFSM4ENL5OGA .

RobDeVoer commented 4 years ago

At the moment I am only concerned about remote on/off as we have two lighting sets in each room. Mood lighting (pendants, tiny LED lights, and LED strips) or full light (LED lights in a grid from the ceiling). Dimming may happen in the future although our current system hardly ever asks for dimming as mood lighting is nice and low already. Sounds from your experience I may be better off with the cheap Sonoff mini option.

Am surprised about your experiences with LED dimming since I have done that without any issues before with regular dimmable LED lights.

Big thanks for sharing your experiences!

joshua-j-morley commented 4 years ago

How has everyone gone with this? I'll be moving in to a house in 2 and a bit weeks with clipsal iconic and the BLE switches Definitely keen to see if anybody progressed in adapting iconic series for wifi use before i sink some time into it

phindmarsh commented 4 years ago

I picked up some of the dimmers (under the PDL brand in New Zealand, but they are the Clipsal equivalent and work with the Wiser Room app) and have been poking at the BLE side of things for a few weeks.

I’ve managed to work out the GATT profile allows you to remotely turn it off/on, set the level, and toggle the current state. This works with a generic BLE app off the App Store, but I haven’t yet got it working with with a Raspberry Pi. The services and characteristics have descriptors so it’s pretty easy to find the correct characteristics, but writing the value from python is where I’m stuck.

BFB4AEB6-0895-4667-A338-5B0C2A98CDA5 9D2F089D-D262-47AB-A971-A05D1804AD78

The basic problem seems to be that the underlying Bluetooth library on the Pi disconnects automatically after a few seconds of connecting, sometimes more like 30s, and attempting to write to the characteristics with similar values used in the generic BLE app does nothing.

I’ve also tried sniffing the BLE traffic with the iOS sysdiagnose logging and pulling the actual data that the Wiser app uses, but that’s also been difficult because I’m not really familiar with that level of reverse engineering.

My plan was to first work out how to control them using the CLI on a Pi, then port those commands to python, then wrap that into a home assistant integration. So far I’m still stuck on the “control them with the CLI” part...

I don’t have another device with a Bluetooth stack other than a Pi and a MacBook, and many of the python BLE libs don’t support macOS so my next thing was to try something in Nodejs or something to rule out a bug somewhere in python land. I’m pretty sure the issue is lower down than that, but I’m not that familiar with bluez or the lower level Bluetooth stuff yet.

sj26 commented 4 years ago

Ooh, nice one @phindmarsh, that's what I was hoping to do. Any chance you could share the gatt profile descriptions in copy pasteable form?

sj26 commented 4 years ago

Oh I've found the equivalent devices and profiles via the same GATTBrowser app.

Any chance you could share which services/properties you've been poking, and how?

phindmarsh commented 4 years ago

It’s the section at the bottom that has the control parameters I’ve found so far:

CEA2AF7D-59F7-4857-B407-19E5FC8C8DDB

720A9081 is the on/off, you can write 0x00 for off and 0x01 for on.

720A9082 is set level, which takes a value from 0x0000 for lowest and something like 0x1027 for the highest. Note the value has the bytes flipped, so 0x1010 is like half the level. So something like this:

Low = 0000 = 0x0000 Mid = 1000 = 0x0010 High = 2710 = 0x1027

720A9083 is the toggle, so you can toggle it on/off relative to the current state, and also read the state of the physical button (depressed, undepressed). I haven’t done much with this one though.

The other ones you can read the firmware version, name, etc, but I also haven’t played with those much.

Also make sure you upgrade the firmware via the wiser app first, otherwise it tells you the encryption is insufficient.

The other thing I did was decompile the Android app and tried to read the code but it’s a kotlin app so the decompiled source is not that readable (to me at least!).

The only interesting thing is the Android app seems to use services with a slightly different uuid, one that starts with 720A8081 instead of 720A9081 for example. I haven’t yet poked around the edges of this yet though. I wonder if the app is using services that aren’t advertised like the other ones are.

phindmarsh commented 4 years ago

Here’s a screen recording for turning the dimmer on/off

https://share.icloud.com/photos/0GsHxG03jcrFJ6aIeza2o51Rg

sj26 commented 4 years ago

So I can also control my device by reading and writing those properties, which is great!

But I can't do it from any device other than my iPhone.

My iPhone has the Wiser app installed, and has been paired to the switches. I think that's the missing piece — pairing. I need to read some more to figure it out. Maybe I'll try decompiling the android app like you did.

phindmarsh commented 4 years ago

Ha yeah that’s basically where I am.

I wondered if pairing has something to do with it, but I haven’t yet had the time to unpack that hypothesis yet.

Reading some attributes like firmware seems to work, and not others. Let me know how you get on!

sj26 commented 4 years ago

The linux bluetooth tooling is pretty good. I have a usb bluetooth adapter attached to my machine running homebridge. After doing a scan to find the dimmer devices:

sudo hcitool lescan | grep CH
D0:CF:5E:85:48:3D CH-DIMMER_483D

I can see the characteristics for one of my wiser dimmers:

sudo gatttool -b D0:CF:5E:85:48:3D --characteristics
handle = 0x0002, char properties = 0x02, char value handle = 0x0003, uuid = 00002a00-0000-1000-8000-00805f9b34fb
handle = 0x0004, char properties = 0x02, char value handle = 0x0005, uuid = 00002a01-0000-1000-8000-00805f9b34fb
handle = 0x0007, char properties = 0x02, char value handle = 0x0008, uuid = 00002a24-0000-1000-8000-00805f9b34fb
handle = 0x0009, char properties = 0x02, char value handle = 0x000a, uuid = 00002a26-0000-1000-8000-00805f9b34fb
handle = 0x000b, char properties = 0x02, char value handle = 0x000c, uuid = 00002a29-0000-1000-8000-00805f9b34fb
handle = 0x000e, char properties = 0x08, char value handle = 0x000f, uuid = 720a7081-9c7d-11e5-a7e3-0002a5d5c51b
handle = 0x0011, char properties = 0x12, char value handle = 0x0012, uuid = 720a7082-9c7d-11e5-a7e3-0002a5d5c51b
handle = 0x0015, char properties = 0x12, char value handle = 0x0016, uuid = 720a7083-9c7d-11e5-a7e3-0002a5d5c51b
handle = 0x0019, char properties = 0x02, char value handle = 0x001a, uuid = 720a7084-9c7d-11e5-a7e3-0002a5d5c51b
handle = 0x001c, char properties = 0x08, char value handle = 0x001d, uuid = 720a7085-9c7d-11e5-a7e3-0002a5d5c51b
handle = 0x001f, char properties = 0x12, char value handle = 0x0020, uuid = 720a7086-9c7d-11e5-a7e3-0002a5d5c51b
handle = 0x0024, char properties = 0x18, char value handle = 0x0025, uuid = f7bf3564-fb6d-4e53-88a4-5e37e0326063
handle = 0x0027, char properties = 0x04, char value handle = 0x0028, uuid = 984227f3-34fc-4045-a5d0-2c581f81a153
handle = 0x002a, char properties = 0x1a, char value handle = 0x002b, uuid = 720a9081-9c7d-11e5-a7e3-0002a5d5c51b
handle = 0x002e, char properties = 0x1a, char value handle = 0x002f, uuid = 720a9082-9c7d-11e5-a7e3-0002a5d5c51b
handle = 0x0032, char properties = 0x1a, char value handle = 0x0033, uuid = 720a9083-9c7d-11e5-a7e3-0002a5d5c51b
handle = 0x0036, char properties = 0x1a, char value handle = 0x0037, uuid = 720a9084-9c7d-11e5-a7e3-0002a5d5c51b

I believe this is the on/off characteristic:

sj26@prowl:~$ sudo gatttool -b D0:CF:5E:85:48:3D --char-read --handle 0x002a
Characteristic value/descriptor: 1a 2b 00 1b c5 d5 a5 02 00 e3 a7 e5 11 7d 9c 81 90 0a 72

Reading via gatttool doesn't show a change after toggling power state, though, so I'm wondering if this value means "unauthorized" or something

sj26 commented 4 years ago

apktool and ClassyShark are letting me poke around in the android app. There's an interesting "communicationlib" which has lots of BLE implementation. Skimming, I'm confident that the device is paired or bonded to the phone before interaction. It seems to use standard android bond creation gear:

https://developer.android.com/reference/android/bluetooth/BluetoothDevice#createBond()

sj26 commented 4 years ago

Useful reference on bonding/pairing in BLE: https://www.kynetics.com/docs/2018/BLE_Pairing_and_bonding/

phindmarsh commented 4 years ago

Yeh I’ve got about as far as reading the characteristics and the handles using a combination of lescan, gattctl, gatttool, and all the different python BLE libraries.

The trick I couldn’t get was being able to write to the chosen characteristic, or find the simple 0x00 or 0x01 values I expected on the on/off characteristic.

Perhaps you are right about the unauthorised response, didn’t think about that. I had tried to MITM or sniff the app traffic to see if there was some kind of handshake or key exchange happening, but then I figured that if I could do it with the generic GATT app it probably wasn’t using proprietary communication.

If you connect with gatttool does it automatically disconnect after a few seconds? I often got segfaults when using the gatttool CLI.

phindmarsh commented 4 years ago

I also noticed if you unpair/remove one of the dimmers from the Bluetooth settings on the iPhone the GATTBrowser app asks if you want to pair again before you can write data, which would lend more evidence to the fact you have to pair or bond with it first

sj26 commented 4 years ago

My reading of the android code makes me think it's not doing anything special (authentication etc) beyond doing simple bonding (pairing) of the ble device once the switch is in "pairing" mode (three presses, flashing). But when I try pairing (which I confirmed tries to create a ble bond in the bluez code) it doesn't work, and I get this output:

Oct 04 16:31:56 prowl bluetoothd[20162]: mgmt: > 0c 00 00 00 08 00 d7 4b 3e 5e cf d0 01 00        .......K>^....
Oct 04 16:31:56 prowl bluetoothd[20162]: mgmt: [0x0000] event 0x000c
Oct 04 16:31:56 prowl bluetoothd[20162]: src/adapter.c:dev_disconnected() Device D0:CF:5E:3E:4B:D7 disconnected, reason 0
Oct 04 16:31:56 prowl bluetoothd[20162]: src/adapter.c:adapter_remove_connection()
Oct 04 16:31:56 prowl bluetoothd[20162]: plugins/policy.c:disconnect_cb() reason 0
Oct 04 16:31:56 prowl bluetoothd[20162]: src/adapter.c:bonding_attempt_complete() hci0 bdaddr D0:CF:5E:3E:4B:D7 type 1 status 0xe
Oct 04 16:31:56 prowl bluetoothd[20162]: src/device.c:device_bonding_complete() bonding (nil) status 0x0e
Oct 04 16:31:56 prowl bluetoothd[20162]: src/device.c:device_bonding_failed() status 14
Oct 04 16:31:56 prowl bluetoothd[20162]: src/adapter.c:resume_discovery()

I think my little adapter is Bluetooth 4.0, maybe it needs 4.2. Will keep digging

phindmarsh commented 4 years ago

I was thinking about this earlier, and wondered what protection it had (if any) from a random device trying to control it without doing the triple tap thing first.

Presumably without some kind of bonding process it would be a Bad Idea and allow anyone to control your lights.

So based on what you’ve seen it would look like you need to bond with it through the triple tap process before it’ll allow you to control it?

sj26 commented 4 years ago

Yeah, I'm pretty sure the triple tap puts it into some sort of "expect bonding" mode.

But I can't figure out how to successfully bond. I don't understanding bonding well enough, I think.

I figured out my UDM has a bluetooth radio in it, and is the ideal controller for me. I also noticed that it's got more modern bluetooth - 4.2:

# hciconfig -a
hci0:   Type: Primary  Bus: UART
    BD Address: 74:83:C2:D7:AA:C1  ACL MTU: 310:10  SCO MTU: 64:8
    UP RUNNING 
    RX bytes:5206497 acl:0 sco:0 events:138185 errors:0
    TX bytes:1020141 acl:0 sco:0 commands:2003 errors:0
    Features: 0xff 0xff 0x8f 0xfe 0xdb 0xff 0x5b 0x87
    Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
    Link policy: RSWITCH HOLD SNIFF PARK 
    Link mode: SLAVE ACCEPT 
    Name: 'BlueZ 5.48'
    Class: 0x000000
    Service Classes: Unspecified
    Device Class: Miscellaneous, 
    HCI Version: 4.2 (0x8)  Revision: 0x2918
    LMP Version: 4.2 (0x8)  Subversion: 0x2918
    Manufacturer: Cambridge Silicon Radio (10)

I can scan the device and whatnot from this controller, but still pairing fails (during triple tap mode):

[bluetooth]# pair D0:CF:5E:3E:4B:D7
Attempting to pair with D0:CF:5E:3E:4B:D7
[CHG] Device D0:CF:5E:3E:4B:D7 Connected: yes
Failed to pair: org.bluez.Error.AuthenticationFailed
[CHG] Device D0:CF:5E:3E:4B:D7 Connected: no
[CHG] Controller 74:83:C2:D7:AA:C1 Powered: no
[CHG] Controller 74:83:C2:D7:AA:C1 Discovering: no
[CHG] Controller 74:83:C2:D7:AA:C1 Powered: yes

with the following daemon output:

bluetoothd[6945]: src/agent.c:agent_ref() 0x4d3de0: ref=1
bluetoothd[6945]: src/agent.c:register_agent() agent :1.9
bluetoothd[6945]: src/agent.c:agent_disconnect() Agent :1.9 disconnected
bluetoothd[6945]: src/agent.c:agent_destroy() agent :1.9
bluetoothd[6945]: src/agent.c:agent_unref() 0x4d3de0: ref=0
bluetoothd[6945]: src/agent.c:agent_ref() 0x4db3b0: ref=1
bluetoothd[6945]: src/agent.c:register_agent() agent :1.10
bluetoothd[6945]: src/agent.c:agent_disconnect() Agent :1.10 disconnected
bluetoothd[6945]: src/agent.c:agent_destroy() agent :1.10
bluetoothd[6945]: src/agent.c:agent_unref() 0x4db3b0: ref=0
bluetoothd[6945]: src/agent.c:agent_ref() 0x4d3de0: ref=1
bluetoothd[6945]: src/agent.c:register_agent() agent :1.11
bluetoothd[6945]: src/agent.c:agent_ref() 0x4d3de0: ref=2
bluetoothd[6945]: src/device.c:bonding_request_new() Requesting bonding for D0:CF:5E:3E:4B:D7
bluetoothd[6945]: src/agent.c:agent_ref() 0x4d3de0: ref=3
bluetoothd[6945]: src/agent.c:agent_unref() 0x4d3de0: ref=2
bluetoothd[6945]: src/adapter.c:suspend_discovery() 
bluetoothd[6945]: src/adapter.c:adapter_bonding_attempt() hci0 bdaddr D0:CF:5E:3E:4B:D7 type 1 io_cap 0x04
bluetoothd[6945]: src/adapter.c:connected_callback() hci0 device D0:CF:5E:3E:4B:D7 connected eir_len 0
bluetoothd[6945]: src/adapter.c:pair_device_complete() Not Powered (0x0f)
bluetoothd[6945]: src/adapter.c:bonding_attempt_complete() hci0 bdaddr D0:CF:5E:3E:4B:D7 type 1 status 0xf
bluetoothd[6945]: src/device.c:device_bonding_complete() bonding 0x4eb0c0 status 0x0f
bluetoothd[6945]: src/device.c:device_bonding_failed() status 15
bluetoothd[6945]: src/agent.c:agent_unref() 0x4d3de0: ref=1
bluetoothd[6945]: src/adapter.c:resume_discovery() 
bluetoothd[6945]: src/adapter.c:trigger_start_discovery() 
bluetoothd[6945]: src/adapter.c:cancel_passive_scanning() 
bluetoothd[6945]: src/adapter.c:new_settings_callback() Settings: 0x00000ad0
bluetoothd[6945]: src/adapter.c:settings_changed() Changed settings: 0x00000001
bluetoothd[6945]: src/adapter.c:cancel_passive_scanning() 
bluetoothd[6945]: src/adapter.c:adapter_remove_connection() 
bluetoothd[6945]: src/adapter.c:adapter_remove_connection() 
bluetoothd[6945]: src/adapter.c:adapter_stop() adapter /org/bluez/hci0 has been disabled
bluetoothd[6945]: src/adapter.c:new_settings_callback() Settings: 0x00000ad1
bluetoothd[6945]: src/adapter.c:settings_changed() Changed settings: 0x00000001
bluetoothd[6945]: src/adapter.c:adapter_start() adapter /org/bluez/hci0 has been enabled
bluetoothd[6945]: src/adapter.c:trigger_passive_scanning() 

I'm very suspicious of this "not powered" status, it makes me think I need to do something to this controller before it'll work.

sj26 commented 4 years ago

It took some finessing to get the bluetooth stack up and running correctly, but then a pairing request worked:

[bluetooth]# pair D0:CF:5E:3E:4B:D7
Attempting to pair with D0:CF:5E:3E:4B:D7
[CHG] Device D0:CF:5E:3E:4B:D7 Connected: yes
[CHG] Device D0:CF:5E:3E:4B:D7 Paired: yes
Pairing successful
[CHG] Device D0:CF:5E:3E:4B:D7 ServicesResolved: yes
bluetoothd[19834]: src/device.c:bonding_request_new() Requesting bonding for D0:CF:5E:3E:4B:D7
bluetoothd[19834]: src/agent.c:agent_ref() 0x4d8690: ref=3
bluetoothd[19834]: src/agent.c:agent_unref() 0x4d8690: ref=2
bluetoothd[19834]: src/adapter.c:suspend_discovery() 
bluetoothd[19834]: src/adapter.c:adapter_bonding_attempt() hci0 bdaddr D0:CF:5E:3E:4B:D7 type 1 io_cap 0x04
bluetoothd[19834]: src/adapter.c:connected_callback() hci0 device D0:CF:5E:3E:4B:D7 connected eir_len 0
bluetoothd[19834]: src/gatt-database.c:connect_cb() New incoming LE ATT connection
bluetoothd[19834]: attrib/gattrib.c:g_attrib_ref() 0x4e72b0: g_attrib_ref=1 
bluetoothd[19834]: profiles/gap/gas.c:gap_accept() GAP profile accept (D0:CF:5E:3E:4B:D7)
bluetoothd[19834]: src/service.c:change_state() 0x4e3180: device D0:CF:5E:3E:4B:D7 profile gap-profile state changed: disconnected -> connected (0)
bluetoothd[19834]: profiles/deviceinfo/deviceinfo.c:deviceinfo_accept() deviceinfo profile accept (D0:CF:5E:3E:4B:D7)
bluetoothd[19834]: profiles/deviceinfo/deviceinfo.c:handle_characteristic() Unsupported characteristic: 00002a24-0000-1000-8000-00805f9b34fb
bluetoothd[19834]: profiles/deviceinfo/deviceinfo.c:handle_characteristic() Unsupported characteristic: 00002a26-0000-1000-8000-00805f9b34fb
bluetoothd[19834]: profiles/deviceinfo/deviceinfo.c:handle_characteristic() Unsupported characteristic: 00002a29-0000-1000-8000-00805f9b34fb
bluetoothd[19834]: src/service.c:change_state() 0x4e3750: device D0:CF:5E:3E:4B:D7 profile deviceinfo state changed: disconnected -> connected (0)
bluetoothd[19834]: src/gatt-client.c:btd_gatt_client_connected() Device connected.
bluetoothd[19834]: src/device.c:gatt_debug() MTU exchange complete, with MTU: 247
bluetoothd[19834]: src/adapter.c:pair_device_complete() Authentication Failed (0x05)
bluetoothd[19834]: src/adapter.c:bonding_attempt_complete() hci0 bdaddr D0:CF:5E:3E:4B:D7 type 1 status 0x5
bluetoothd[19834]: src/device.c:device_bonding_complete() bonding 0x4e0d10 status 0x05
bluetoothd[19834]: src/device.c:device_bonding_failed() status 5
bluetoothd[19834]: src/agent.c:agent_unref() 0x4d8690: ref=1
bluetoothd[19834]: src/adapter.c:resume_discovery() 
bluetoothd[19834]: src/adapter.c:dev_disconnected() Device D0:CF:5E:3E:4B:D7 disconnected, reason 2
bluetoothd[19834]: src/adapter.c:adapter_remove_connection() 
bluetoothd[19834]: plugins/policy.c:disconnect_cb() reason 2
bluetoothd[19834]: src/adapter.c:bonding_attempt_complete() hci0 bdaddr D0:CF:5E:3E:4B:D7 type 1 status 0xe
bluetoothd[19834]: src/device.c:device_bonding_complete() bonding (nil) status 0x0e
bluetoothd[19834]: src/device.c:device_bonding_failed() status 14
bluetoothd[19834]: src/adapter.c:resume_discovery() 
bluetoothd[19834]: profiles/gap/gas.c:read_device_name_cb() Reading device name failed with ATT errror: 0
bluetoothd[19834]: profiles/gap/gas.c:read_appearance_cb() Reading appearance failed with ATT error: 0
bluetoothd[19834]: src/device.c:gatt_debug() MTU Exchange failed. ATT ECODE: 0x00
bluetoothd[19834]: src/device.c:gatt_client_ready_cb() status: failed, error: 0
bluetoothd[19834]: src/device.c:device_svc_resolved() /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7 err -5
bluetoothd[19834]: src/device.c:att_disconnected_cb() 
bluetoothd[19834]: src/device.c:att_disconnected_cb() Software caused connection abort (103)
bluetoothd[19834]: src/service.c:change_state() 0x4e3180: device D0:CF:5E:3E:4B:D7 profile gap-profile state changed: connected -> disconnecting (0)
bluetoothd[19834]: src/service.c:change_state() 0x4e3180: device D0:CF:5E:3E:4B:D7 profile gap-profile state changed: disconnecting -> disconnected (0)
bluetoothd[19834]: src/service.c:change_state() 0x4e3750: device D0:CF:5E:3E:4B:D7 profile deviceinfo state changed: connected -> disconnecting (0)
bluetoothd[19834]: src/service.c:change_state() 0x4e3750: device D0:CF:5E:3E:4B:D7 profile deviceinfo state changed: disconnecting -> disconnected (0)
bluetoothd[19834]: src/gatt-client.c:btd_gatt_client_disconnected() Device disconnected. Cleaning up.
bluetoothd[19834]: src/device.c:att_disconnected_cb() Automatic connection disabled
bluetoothd[19834]: attrib/gattrib.c:g_attrib_unref() 0x4e72b0: g_attrib_unref=0 
bluetoothd[19834]: src/agent.c:agent_ref() 0x4d8690: ref=2
bluetoothd[19834]: src/device.c:bonding_request_new() Requesting bonding for D0:CF:5E:3E:4B:D7
bluetoothd[19834]: src/agent.c:agent_ref() 0x4d8690: ref=3
bluetoothd[19834]: src/agent.c:agent_unref() 0x4d8690: ref=2
bluetoothd[19834]: src/adapter.c:suspend_discovery() 
bluetoothd[19834]: src/adapter.c:adapter_bonding_attempt() hci0 bdaddr D0:CF:5E:3E:4B:D7 type 1 io_cap 0x04
bluetoothd[19834]: src/adapter.c:connected_callback() hci0 device D0:CF:5E:3E:4B:D7 connected eir_len 0
bluetoothd[19834]: src/adapter.c:pair_device_complete() Failed (0x03)
bluetoothd[19834]: src/adapter.c:bonding_attempt_complete() hci0 bdaddr D0:CF:5E:3E:4B:D7 type 1 status 0x3
bluetoothd[19834]: src/device.c:device_bonding_complete() bonding 0x4d66a0 status 0x03
bluetoothd[19834]: src/device.c:device_bonding_failed() status 3
bluetoothd[19834]: src/agent.c:agent_unref() 0x4d8690: ref=1
bluetoothd[19834]: src/adapter.c:resume_discovery() 
bluetoothd[19834]: src/adapter.c:dev_disconnected() Device D0:CF:5E:3E:4B:D7 disconnected, reason 0
bluetoothd[19834]: src/adapter.c:adapter_remove_connection() 
bluetoothd[19834]: plugins/policy.c:disconnect_cb() reason 0
bluetoothd[19834]: src/adapter.c:bonding_attempt_complete() hci0 bdaddr D0:CF:5E:3E:4B:D7 type 1 status 0xe
bluetoothd[19834]: src/device.c:device_bonding_complete() bonding (nil) status 0x0e
bluetoothd[19834]: src/device.c:device_bonding_failed() status 14
bluetoothd[19834]: src/adapter.c:resume_discovery() 
bluetoothd[19834]: src/agent.c:agent_ref() 0x4d8690: ref=2
bluetoothd[19834]: src/device.c:bonding_request_new() Requesting bonding for D0:CF:5E:3E:4B:D7
bluetoothd[19834]: src/agent.c:agent_ref() 0x4d8690: ref=3
bluetoothd[19834]: src/agent.c:agent_unref() 0x4d8690: ref=2
bluetoothd[19834]: src/adapter.c:suspend_discovery() 
bluetoothd[19834]: src/adapter.c:adapter_bonding_attempt() hci0 bdaddr D0:CF:5E:3E:4B:D7 type 1 io_cap 0x04
bluetoothd[19834]: src/adapter.c:connected_callback() hci0 device D0:CF:5E:3E:4B:D7 connected eir_len 0
bluetoothd[19834]: src/gatt-database.c:connect_cb() New incoming LE ATT connection
bluetoothd[19834]: attrib/gattrib.c:g_attrib_ref() 0x4db100: g_attrib_ref=1 
bluetoothd[19834]: profiles/gap/gas.c:gap_accept() GAP profile accept (D0:CF:5E:3E:4B:D7)
bluetoothd[19834]: src/service.c:change_state() 0x4e3180: device D0:CF:5E:3E:4B:D7 profile gap-profile state changed: disconnected -> connected (0)
bluetoothd[19834]: profiles/deviceinfo/deviceinfo.c:deviceinfo_accept() deviceinfo profile accept (D0:CF:5E:3E:4B:D7)
bluetoothd[19834]: profiles/deviceinfo/deviceinfo.c:handle_characteristic() Unsupported characteristic: 00002a24-0000-1000-8000-00805f9b34fb
bluetoothd[19834]: profiles/deviceinfo/deviceinfo.c:handle_characteristic() Unsupported characteristic: 00002a26-0000-1000-8000-00805f9b34fb
bluetoothd[19834]: profiles/deviceinfo/deviceinfo.c:handle_characteristic() Unsupported characteristic: 00002a29-0000-1000-8000-00805f9b34fb
bluetoothd[19834]: src/service.c:change_state() 0x4e3750: device D0:CF:5E:3E:4B:D7 profile deviceinfo state changed: disconnected -> connected (0)
bluetoothd[19834]: src/gatt-client.c:btd_gatt_client_connected() Device connected.
bluetoothd[19834]: src/device.c:gatt_debug() MTU exchange complete, with MTU: 247
bluetoothd[19834]: src/device.c:gatt_debug() MTU exchange complete, with MTU: 247
bluetoothd[19834]: profiles/gap/gas.c:read_device_name_cb() GAP Device Name: CH-DIMMER_4BD7
bluetoothd[19834]: profiles/gap/gas.c:read_appearance_cb() GAP Appearance: 0x6009
bluetoothd[19834]: src/adapter.c:new_irk_callback() hci0 new IRK for D0:CF:5E:3E:4B:D7 RPA 00:00:00:00:00:00
bluetoothd[19834]: src/adapter.c:new_long_term_key_callback() hci0 new LTK for D0:CF:5E:3E:4B:D7 type 2 enc_size 16
bluetoothd[19834]: src/device.c:device_set_bonded() 
bluetoothd[19834]: src/device.c:device_bonding_complete() bonding 0x4d1db0 status 0x00
bluetoothd[19834]: src/agent.c:agent_unref() 0x4d8690: ref=1
bluetoothd[19834]: src/adapter.c:resume_discovery() 
bluetoothd[19834]: src/adapter.c:pair_device_complete() Success (0x00)
bluetoothd[19834]: src/adapter.c:bonding_attempt_complete() hci0 bdaddr D0:CF:5E:3E:4B:D7 type 1 status 0x0
bluetoothd[19834]: src/device.c:device_bonding_complete() bonding (nil) status 0x00
bluetoothd[19834]: src/adapter.c:resume_discovery() 
bluetoothd[19834]: src/device.c:gatt_debug() Primary services found: 5
bluetoothd[19834]: src/device.c:gatt_debug() start: 0x0001, end: 0x0005, uuid: 00001800-0000-1000-8000-00805f9b34fb
bluetoothd[19834]: src/device.c:gatt_debug() start: 0x0006, end: 0x000c, uuid: 0000180a-0000-1000-8000-00805f9b34fb
bluetoothd[19834]: src/device.c:gatt_debug() start: 0x000d, end: 0x0022, uuid: 720a7080-9c7d-11e5-a7e3-0002a5d5c51b
bluetoothd[19834]: src/device.c:gatt_debug() start: 0x0023, end: 0x0028, uuid: 1d14d6ee-fd63-4fa1-bfa4-8f47b42119f0
bluetoothd[19834]: src/device.c:gatt_debug() start: 0x0029, end: 0xffff, uuid: 720a9080-9c7d-11e5-a7e3-0002a5d5c51b
bluetoothd[19834]: src/device.c:gatt_client_ready_cb() status: success, error: 0
bluetoothd[19834]: src/gatt-client.c:btd_gatt_client_ready() GATT client ready
bluetoothd[19834]: src/gatt-client.c:create_services() Exporting objects for GATT services: D0:CF:5E:3E:4B:D7
bluetoothd[19834]: src/device.c:device_svc_resolved() /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7 err 0
sj26 commented 4 years ago
[CH-DIMMER_4BD7]# list-attributes
Primary Service
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0006
    0000180a-0000-1000-8000-00805f9b34fb
    Device Information
Characteristic
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0006/char0007
    00002a24-0000-1000-8000-00805f9b34fb
    Model Number String
Characteristic
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0006/char0009
    00002a26-0000-1000-8000-00805f9b34fb
    Firmware Revision String
Characteristic
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0006/char000b
    00002a29-0000-1000-8000-00805f9b34fb
    Manufacturer Name String
Primary Service
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service000d
    720a7080-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Characteristic
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service000d/char000e
    720a7081-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Descriptor
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service000d/char000e/desc0010
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
Characteristic
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service000d/char0011
    720a7082-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Descriptor
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service000d/char0011/desc0013
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
Descriptor
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service000d/char0011/desc0014
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
Characteristic
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service000d/char0015
    720a7083-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Descriptor
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service000d/char0015/desc0017
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
Descriptor
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service000d/char0015/desc0018
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
Characteristic
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service000d/char0019
    720a7084-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Descriptor
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service000d/char0019/desc001b
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
Characteristic
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service000d/char001c
    720a7085-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Descriptor
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service000d/char001c/desc001e
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
Characteristic
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service000d/char001f
    720a7086-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Descriptor
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service000d/char001f/desc0021
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
Descriptor
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service000d/char001f/desc0022
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
Primary Service
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0023
    1d14d6ee-fd63-4fa1-bfa4-8f47b42119f0
    Vendor specific
Characteristic
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0023/char0024
    f7bf3564-fb6d-4e53-88a4-5e37e0326063
    Vendor specific
Descriptor
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0023/char0024/desc0026
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
Characteristic
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0023/char0027
    984227f3-34fc-4045-a5d0-2c581f81a153
    Vendor specific
Primary Service
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0029
    720a9080-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Characteristic
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0029/char002a
    720a9081-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Descriptor
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0029/char002a/desc002c
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
Descriptor
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0029/char002a/desc002d
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
Characteristic
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0029/char002e
    720a9082-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Descriptor
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0029/char002e/desc0030
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
Descriptor
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0029/char002e/desc0031
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
Characteristic
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0029/char0032
    720a9083-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Descriptor
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0029/char0032/desc0034
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
Descriptor
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0029/char0032/desc0035
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
Characteristic
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0029/char0036
    720a9084-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Descriptor
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0029/char0036/desc0038
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
Descriptor
    /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0029/char0036/desc0039
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description

[CH-DIMMER_4BD7]# select-attribute 720a9081-9c7d-11e5-a7e3-0002a5d5c51b
[CH-DIMMER_4BD7:/service0029/char002a]# select-attribute 720a9081-9c7d-11e5-a7e3-0002a5d5c51b[CH-DIMMER_4BD7:/service0029/char002a]# read
Attempting to read /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0029/char002a
[CHG] Attribute /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0029/char002a Value:
  01                                               .               
  01                                               .               
[CH-DIMMER_4BD7:/service0029/char002a]# write data=00
Invalid value at index 0
[CH-DIMMER_4BD7:/service0029/char002a]# write 0      
Attempting to write /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0029/char002a
[CH-DIMMER_4BD7:/service0029/char002a]# write 1
Attempting to write /org/bluez/hci0/dev_D0_CF_5E_3E_4B_D7/service0029/char002a

My lights just turned on and off, controlled from my wifi router :tada:

phindmarsh commented 4 years ago

🥳 so pairing was the trick. Damn. Would have taken me ages to figure that out!

So do you think it’s the Bluetooth 4.2 that made it possible, or something more specific? What’s the UDM hardware?

sj26 commented 4 years ago

Yeah I reckon it's Bluetooth 4.2. It introduced a new key exchange mode for BLE devices that I think this is using. Fortunately bluez takes care of most of it.

I'll be ordering some new usb bluetooth adapters 😅

phindmarsh commented 4 years ago

Nice, I've got some Pi 3s which only have 4.1, and trying a pair doesn't seem to work:

[bluetooth]# pair CC:CC:CC:F8:C3:E0
Attempting to pair with CC:CC:CC:F8:C3:E0
Failed to pair: org.bluez.Error.AuthenticationCanceled

Looks like I need to buy some more adapters too, or just a new Pi 4

sj26 commented 4 years ago

Check your software, too — you might just need a new kernel or bluetooth stack.

CalumOchkas commented 4 years ago

Been following this intently :-)

It took some finessing to get the bluetooth stack up and running correctly, but then a pairing request worked

What did you try differently? I've just tried from a Pi4 with the standard bluez stack and I'm getting the same error:

[bluetooth]# version
Version 5.50
[bluetooth]# info 90:FD:9F:5C:E0:28
Device 90:FD:9F:5C:E0:28 (public)
    Name: CH-DIMMER_E028
    Alias: CH-DIMMER_E028
    Paired: no
    Trusted: yes
    Blocked: no
    Connected: no
    LegacyPairing: no
    ManufacturerData Key: 0x02b6
    ManufacturerData Value:

Made trusted to test ^

[bluetooth]# pair 90:FD:9F:5C:E0:28
Attempting to pair with 90:FD:9F:5C:E0:28
[CHG] Device 90:FD:9F:5C:E0:28 Connected: yes
Failed to pair: org.bluez.Error.AuthenticationTimeout
[CHG] Device 90:FD:9F:5C:E0:28 Connected: no

Know what I might be missing?

CalumOchkas commented 4 years ago

Note this after the 3x Tap to begin pairing mode (red flashing). Here's the debug logs:

Oct 08 15:54:20 raspberrypi-bedroom bluetoothd[3836]: src/device.c:bonding_request_new() Requesting bonding for 90:FD:9F:5C:E0:28
Oct 08 15:54:20 raspberrypi-bedroom bluetoothd[3836]: src/agent.c:agent_ref() 0x11c0fb0: ref=3
Oct 08 15:54:20 raspberrypi-bedroom bluetoothd[3836]: src/agent.c:agent_unref() 0x11c0fb0: ref=2
Oct 08 15:54:20 raspberrypi-bedroom bluetoothd[3836]: src/adapter.c:suspend_discovery()
Oct 08 15:54:20 raspberrypi-bedroom bluetoothd[3836]: src/adapter.c:adapter_bonding_attempt() hci0 bdaddr 90:FD:9F:5C:E0:28 type 1 io_cap 0x04
Oct 08 15:54:21 raspberrypi-bedroom bluetoothd[3836]: src/adapter.c:connected_callback() hci0 device 90:FD:9F:5C:E0:28 connected eir_len 31
Oct 08 15:54:22 raspberrypi-bedroom bluetoothd[3836]: src/adapter.c:pair_device_complete() Timeout (0x08)
Oct 08 15:54:22 raspberrypi-bedroom bluetoothd[3836]: src/adapter.c:bonding_attempt_complete() hci0 bdaddr 90:FD:9F:5C:E0:28 type 1 status 0x8
Oct 08 15:54:22 raspberrypi-bedroom bluetoothd[3836]: src/device.c:device_bonding_complete() bonding 0x11bb138 status 0x08
Oct 08 15:54:22 raspberrypi-bedroom bluetoothd[3836]: src/device.c:device_bonding_failed() status 8
Oct 08 15:54:22 raspberrypi-bedroom bluetoothd[3836]: src/agent.c:agent_unref() 0x11c0fb0: ref=1
Oct 08 15:54:22 raspberrypi-bedroom bluetoothd[3836]: src/adapter.c:resume_discovery()
Oct 08 15:54:22 raspberrypi-bedroom bluetoothd[3836]: src/adapter.c:dev_disconnected() Device 90:FD:9F:5C:E0:28 disconnected, reason 1
Oct 08 15:54:22 raspberrypi-bedroom bluetoothd[3836]: src/adapter.c:adapter_remove_connection()
Oct 08 15:54:22 raspberrypi-bedroom bluetoothd[3836]: plugins/policy.c:disconnect_cb() reason 1
Oct 08 15:54:22 raspberrypi-bedroom bluetoothd[3836]: src/adapter.c:bonding_attempt_complete() hci0 bdaddr 90:FD:9F:5C:E0:28 type 1 status 0xe
Oct 08 15:54:22 raspberrypi-bedroom bluetoothd[3836]: src/device.c:device_bonding_complete() bonding (nil) status 0x0e
Oct 08 15:54:22 raspberrypi-bedroom bluetoothd[3836]: src/device.c:device_bonding_failed() status 14
Oct 08 15:54:22 raspberrypi-bedroom bluetoothd[3836]: src/adapter.c:resume_discovery()
phindmarsh commented 4 years ago

My new Pi4 just arrived, and I managed to get it to turn the lights on and off just now after a bit of trial and error, here's what I did. This is on a vanilla install of RaspberryOS, no additional packages installed. I had also upgraded the firmware from the initial version using the Wiser Room app (currently v2.2.0).

Pi 4 info:

[bluetooth]# version
Version 5.50
[bluetooth]# show
Controller DC:A6:32:C6:D9:F9 (public)
    Name: raspberrypi
    Alias: raspberrypi
    Class: 0x00000000
    Powered: yes
    Discoverable: no
    Pairable: yes
    UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
    UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
    UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
    UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
    UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
    Modalias: usb:v1D6Bp0246d0532
    Discovering: no

First, I removed any previous devices I had from past attempts:

[bluetooth]# devices
Device XX:XX:XX:XX:C3:E0 CH-DIMMER_C3E0
[bluetooth]# remove XX:XX:XX:XX:C3:E0
[DEL] Device XX:XX:XX:XX:C3:E0 CH-DIMMER_C3E0
Device has been removed

Then, inspired by these instructions, I did these commands:

[bluetooth]# power on
Changing power on succeeded
[bluetooth]# agent on
Agent is already registered
[bluetooth]# default-agent
Default agent request successful
[bluetooth]# scan on
Discovery started
[CHG] Controller YY:YY:YY:YY:D9:F9 Discovering: yes
... <other devices>
[NEW] Device XX:XX:XX:XX:C3:E0 CH-DIMMER_C3E0
... <other devices>
[bluetooth]# scan off
Discovery stopped
[CHG] Controller YY:YY:YY:YY:D9:F9 Discovering: no
[CHG] Device XX:XX:XX:XX:C3:E0 TxPower is nil
[CHG] Device XX:XX:XX:XX:C3:E0 RSSI is nil
[bluetooth]# trust XX:XX:XX:XX:C3:E0
[CHG] Device XX:XX:XX:XX:C3:E0 Trusted: yes
Changing XX:XX:XX:XX:C3:E0 trust succeeded

At this point I triple pressed the dimmer button to get it to flash green and red, then

[bluetooth]# pair XX:XX:XX:XX:C3:E0
Attempting to pair with XX:XX:XX:XX:C3:E0
[CHG] Device XX:XX:XX:XX:C3:E0 Connected: yes
[CHG] Device XX:XX:XX:XX:C3:E0 UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Device XX:XX:XX:XX:C3:E0 UUIDs: 0000180a-0000-1000-8000-00805f9b34fb
[CHG] Device XX:XX:XX:XX:C3:E0 UUIDs: 1d14d6ee-fd63-4fa1-bfa4-8f47b42119f0
[CHG] Device XX:XX:XX:XX:C3:E0 UUIDs: 720a7080-9c7d-11e5-a7e3-0002a5d5c51b
[CHG] Device XX:XX:XX:XX:C3:E0 UUIDs: 720a9080-9c7d-11e5-a7e3-0002a5d5c51b
[CHG] Device XX:XX:XX:XX:C3:E0 ServicesResolved: yes
[CHG] Device XX:XX:XX:XX:C3:E0 Paired: yes
[NEW] Primary Service
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0006
    0000180a-0000-1000-8000-00805f9b34fb
    Device Information
[NEW] Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0006/char0007
    00002a24-0000-1000-8000-00805f9b34fb
    Model Number String
[NEW] Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0006/char0009
    00002a26-0000-1000-8000-00805f9b34fb
    Firmware Revision String
[NEW] Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0006/char000b
    00002a29-0000-1000-8000-00805f9b34fb
    Manufacturer Name String
[NEW] Primary Service
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d
    720a7080-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
[NEW] Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char000e
    720a7081-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
[NEW] Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char000e/desc0010
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
[NEW] Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char0011
    720a7082-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
[NEW] Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char0011/desc0013
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
[NEW] Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char0011/desc0014
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
[NEW] Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char0015
    720a7083-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
[NEW] Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char0015/desc0017
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
[NEW] Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char0015/desc0018
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
[NEW] Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char0019
    720a7084-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
[NEW] Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char0019/desc001b
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
[NEW] Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char001c
    720a7085-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
[NEW] Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char001c/desc001e
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
[NEW] Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char001f
    720a7086-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
[NEW] Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char001f/desc0021
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
[NEW] Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char001f/desc0022
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
[NEW] Primary Service
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0023
    1d14d6ee-fd63-4fa1-bfa4-8f47b42119f0
    Vendor specific
[NEW] Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0023/char0024
    f7bf3564-fb6d-4e53-88a4-5e37e0326063
    Vendor specific
[NEW] Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0023/char0024/desc0026
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
[NEW] Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0023/char0027
    984227f3-34fc-4045-a5d0-2c581f81a153
    Vendor specific
[NEW] Primary Service
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029
    720a9080-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
[NEW] Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char002a
    720a9081-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
[NEW] Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char002a/desc002c
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
[NEW] Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char002a/desc002d
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
[NEW] Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char002e
    720a9082-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
[NEW] Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char002e/desc0030
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
[NEW] Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char002e/desc0031
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
[NEW] Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char0032
    720a9083-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
[NEW] Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char0032/desc0034
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
[NEW] Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char0032/desc0035
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
[NEW] Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char0036
    720a9084-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
[NEW] Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char0036/desc0038
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
[NEW] Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char0036/desc0039
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
Pairing successful
[CHG] Device XX:XX:XX:XX:C3:E0 Appearance: 0x6009

Pairing successful!

Switching to the gatt menu now, and reading the attribute for the current on/off status:

[CH-DIMMER_C3E0]# menu gatt 
Menu gatt:
Available commands:
-------------------
list-attributes [dev]                             List attributes
select-attribute <attribute/UUID>                 Select attribute
attribute-info [attribute/UUID]                   Select attribute
read [offset]                                     Read attribute value
write <data=xx xx ...> [offset]                   Write attribute value
acquire-write                                     Acquire Write file descriptor
release-write                                     Release Write file descriptor
acquire-notify                                    Acquire Notify file descriptor
release-notify                                    Release Notify file descriptor
notify <on/off>                                   Notify attribute value
register-application [UUID ...]                   Register profile to connect
unregister-application                            Unregister profile
register-service <UUID>                           Register application service.
unregister-service <UUID/object>                  Unregister application service
register-includes <UUID>                          Register as Included service in.
unregister-includes <Service-UUID><Inc-UUID>      Unregister Included service.
register-characteristic <UUID> <Flags=read,write,notify...>  Register application characteristic
unregister-characteristic <UUID/object>           Unregister application characteristic
register-descriptor <UUID> <Flags=read,write...>  Register application descriptor
unregister-descriptor <UUID/object>               Unregister application descriptor
back                                              Return to main menu
version                                           Display version
quit                                              Quit program
exit                                              Quit program
help                                              Display help about this program
export                                            Print evironment variables
[CH-DIMMER_C3E0]# list-attributes
Primary Service
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0006
    0000180a-0000-1000-8000-00805f9b34fb
    Device Information
Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0006/char0007
    00002a24-0000-1000-8000-00805f9b34fb
    Model Number String
Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0006/char0009
    00002a26-0000-1000-8000-00805f9b34fb
    Firmware Revision String
Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0006/char000b
    00002a29-0000-1000-8000-00805f9b34fb
    Manufacturer Name String
Primary Service
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d
    720a7080-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char000e
    720a7081-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char000e/desc0010
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char0011
    720a7082-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char0011/desc0013
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char0011/desc0014
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char0015
    720a7083-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char0015/desc0017
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char0015/desc0018
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char0019
    720a7084-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char0019/desc001b
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char001c
    720a7085-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char001c/desc001e
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char001f
    720a7086-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char001f/desc0021
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service000d/char001f/desc0022
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
Primary Service
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0023
    1d14d6ee-fd63-4fa1-bfa4-8f47b42119f0
    Vendor specific
Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0023/char0024
    f7bf3564-fb6d-4e53-88a4-5e37e0326063
    Vendor specific
Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0023/char0024/desc0026
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0023/char0027
    984227f3-34fc-4045-a5d0-2c581f81a153
    Vendor specific
Primary Service
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029
    720a9080-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char002a
    720a9081-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char002a/desc002c
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char002a/desc002d
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char002e
    720a9082-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char002e/desc0030
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char002e/desc0031
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char0032
    720a9083-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char0032/desc0034
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char0032/desc0035
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
Characteristic
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char0036
    720a9084-9c7d-11e5-a7e3-0002a5d5c51b
    Vendor specific
Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char0036/desc0038
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
Descriptor
    /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char0036/desc0039
    00002901-0000-1000-8000-00805f9b34fb
    Characteristic User Description
[CH-DIMMER_C3E0]# select-attribute 720a9081-9c7d-11e5-a7e3-0002a5d5c51b
[CH-DIMMER_C3E0:/service0029/char002a]# select-attribute 720a9081-9c7d-11e5-a7e3-0002a5d5c51b

The light was currently switched on, so read the state should give me a 1...

[CH-DIMMER_C3E0:/service0029/char002a]# read
Attempting to read /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char002a
[CHG] Attribute /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char002a Value:
  01                                               .               
  01                                               .               

Which it did, so writing a 0 should turn it off...

[CH-DIMMER_C3E0:/service0029/char002a]# write 0
Attempting to write /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char002a

Which it did!

[CH-DIMMER_C3E0:/service0029/char002a]# write 1
Attempting to write /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char002a
[CH-DIMMER_C3E0:/service0029/char002a]# write 0
Attempting to write /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char002a
[CH-DIMMER_C3E0:/service0029/char002a]# write 1
Attempting to write /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char002a

With this I'll now focus on getting it working from Python, so I can wrap that in a home assistant plugin. @sj26 have you started work in that area yet?

CalumOchkas commented 4 years ago

Thanks so much for all the information, but still no good for me.

So weird, I'm doing exactly the same on my Pi, the controller looks identical, deleted the device (which I was running 2.2.0, but now 2.2.8) but still getting AuthenticationTimeout (in < 2 seconds) on pairing after following the same process as you .

I wonder if my BLE switch module is a slightly different model (in New Zealand).

phindmarsh commented 4 years ago

I’m in NZ too, got the dimmers from JA Russell, they are the PDL branded ones.

I have had some problems reconnecting to them after pairing, so it’s not 100% reliable.

I’m away for the long weekend, so will be back to it next week

CalumOchkas commented 4 years ago

Yeah I got mine from JA Russell too. Very odd! Is your intermittent message the same src/adapter.c:pair_device_complete() Timeout (0x08) error? I was running the Lite version of RaspberryPi OS. I've just attempted a reinstall of the full OS and retried but getting the same issue. (Clutching at straw)

CalumOchkas commented 4 years ago

btmon extract showing where the timeout occurs:

> HCI Event: LE Meta Event (0x3e) plen 12                                                                                                                                                                              #16 [hci0] 24.909589
      LE Read Remote Used Features (0x04)
        Status: Connection Timeout (0x08)
        Handle: 64
        Features: 0x2d 0x00 0x00 0x00 0x00 0x00 0x00 0x00
          LE Encryption
          Extended Reject Indication
          Slave-initiated Features Exchange
          LE Data Packet Length Extension

Full log:

@ MGMT Command: Pair Device (0x0019) plen 8                                                                                                                                                                       {0x0001} [hci0] 22.865885
        LE Address: 90:FD:9F:5C:E0:28 (Silicon Laboratories)
        Capability: KeyboardDisplay (0x04)
< HCI Command: LE Add Device To White List (0x08|0x0011) plen 7                                                                                                                                                         #1 [hci0] 22.866038
        Address type: Public (0x00)
        Address: 90:FD:9F:5C:E0:28 (Silicon Laboratories)
> HCI Event: Command Complete (0x0e) plen 4                                                                                                                                                                             #2 [hci0] 22.866603
      LE Add Device To White List (0x08|0x0011) ncmd 1
        Status: Success (0x00)
< HCI Command: LE Set Scan Parameters (0x08|0x000b) plen 7                                                                                                                                                              #3 [hci0] 22.866684
        Type: Passive (0x00)
        Interval: 60.000 msec (0x0060)
        Window: 30.000 msec (0x0030)
        Own address type: Public (0x00)
        Filter policy: Ignore not in white list (0x01)
> HCI Event: Command Complete (0x0e) plen 4                                                                                                                                                                             #4 [hci0] 22.867078
      LE Set Scan Parameters (0x08|0x000b) ncmd 1
        Status: Success (0x00)
< HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2                                                                                                                                                                  #5 [hci0] 22.867151
        Scanning: Enabled (0x01)
        Filter duplicates: Enabled (0x01)
> HCI Event: Command Complete (0x0e) plen 4                                                                                                                                                                             #6 [hci0] 22.867783
      LE Set Scan Enable (0x08|0x000c) ncmd 1
        Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 43                                                                                                                                                                               #7 [hci0] 23.580207
      LE Advertising Report (0x02)
        Num reports: 1
        Event type: Connectable undirected - ADV_IND (0x00)
        Address type: Public (0x00)
        Address: 90:FD:9F:5C:E0:28 (Silicon Laboratories)
        Data length: 31
        Flags: 0x06
          LE General Discoverable Mode
          BR/EDR Not Supported
        Company: Schneider Electric (694)
          Data: 1a4430003700016d00010700010028e05c9ffd9000000000
        RSSI: -54 dBm (0xca)
< HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2                                                                                                                                                                  #8 [hci0] 23.580303
        Scanning: Disabled (0x00)
        Filter duplicates: Disabled (0x00)
> HCI Event: Command Complete (0x0e) plen 4                                                                                                                                                                             #9 [hci0] 23.582606
      LE Set Scan Enable (0x08|0x000c) ncmd 1
        Status: Success (0x00)
< HCI Command: LE Create Connection (0x08|0x000d) plen 25                                                                                                                                                              #10 [hci0] 23.582688
        Scan interval: 60.000 msec (0x0060)
        Scan window: 60.000 msec (0x0060)
        Filter policy: White list is not used (0x00)
        Peer address type: Public (0x00)
        Peer address: 90:FD:9F:5C:E0:28 (Silicon Laboratories)
        Own address type: Public (0x00)
        Min connection interval: 30.00 msec (0x0018)
        Max connection interval: 50.00 msec (0x0028)
        Connection latency: 0 (0x0000)
        Supervision timeout: 420 msec (0x002a)
        Min connection length: 0.000 msec (0x0000)
        Max connection length: 0.000 msec (0x0000)
> HCI Event: Command Status (0x0f) plen 4                                                                                                                                                                              #11 [hci0] 23.583259
      LE Create Connection (0x08|0x000d) ncmd 1
        Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 19                                                                                                                                                                              #12 [hci0] 24.090202
      LE Connection Complete (0x01)
        Status: Success (0x00)
        Handle: 64
        Role: Master (0x00)
        Peer address type: Public (0x00)
        Peer address: 90:FD:9F:5C:E0:28 (Silicon Laboratories)
        Connection interval: 48.75 msec (0x0027)
        Connection latency: 0 (0x0000)
        Supervision timeout: 420 msec (0x002a)
        Master clock accuracy: 0x00
@ MGMT Event: Device Connected (0x000b) plen 44                                                                                                                                                                   {0x0002} [hci0] 24.090269
        LE Address: 90:FD:9F:5C:E0:28 (Silicon Laboratories)
        Flags: 0x00000000
        Data length: 31
        Flags: 0x06
          LE General Discoverable Mode
          BR/EDR Not Supported
        Company: Schneider Electric (694)
          Data: 1a4430003700016d00010700010028e05c9ffd9000000000
@ MGMT Event: Device Connected (0x000b) plen 44                                                                                                                                                                   {0x0001} [hci0] 24.090269
        LE Address: 90:FD:9F:5C:E0:28 (Silicon Laboratories)
        Flags: 0x00000000
        Data length: 31
        Flags: 0x06
          LE General Discoverable Mode
          BR/EDR Not Supported
        Company: Schneider Electric (694)
          Data: 1a4430003700016d00010700010028e05c9ffd9000000000
< HCI Command: LE Read Remote Used Features (0x08|0x0016) plen 2                                                                                                                                                       #13 [hci0] 24.090482
        Handle: 64
> HCI Event: Command Status (0x0f) plen 4                                                                                                                                                                              #14 [hci0] 24.090971
      LE Read Remote Used Features (0x08|0x0016) ncmd 1
        Status: Success (0x00)
> HCI Event: Command Complete (0x0e) plen 14                                                                                                                                                                           #15 [hci0] 24.091042
      LE Read Remote Used Features (0x08|0x0016) ncmd 1
        Status: Success (0x00)
        00 00 00 00 00 00 00 00 00 00                    ..........      
> HCI Event: LE Meta Event (0x3e) plen 12                                                                                                                                                                              #16 [hci0] 24.909589
      LE Read Remote Used Features (0x04)
        Status: Connection Timeout (0x08)
        Handle: 64
        Features: 0x2d 0x00 0x00 0x00 0x00 0x00 0x00 0x00
          LE Encryption
          Extended Reject Indication
          Slave-initiated Features Exchange
          LE Data Packet Length Extension
@ MGMT Event: Command Complete (0x0001) plen 10                                                                                                                                                                   {0x0001} [hci0] 24.909624
      Pair Device (0x0019) plen 7
        Status: Timeout (0x08)
        LE Address: 90:FD:9F:5C:E0:28 (Silicon Laboratories)
> HCI Event: Disconnect Complete (0x05) plen 4                                                                                                                                                                         #17 [hci0] 24.910445
        Status: Success (0x00)
        Handle: 64
        Reason: Connection Timeout (0x08)
@ MGMT Event: Device Disconnected (0x000c) plen 8                                                                                                                                                                 {0x0002} [hci0] 24.910467
        LE Address: 90:FD:9F:5C:E0:28 (Silicon Laboratories)
        Reason: Connection timeout (0x01)
@ MGMT Event: Device Disconnected (0x000c) plen 8                                                                                                                                                                 {0x0001} [hci0] 24.910467
phindmarsh commented 4 years ago

I found I couldn't reconnect after completing those steps. After some digging it appears there might be a firmware issue on the RPi.

Rolling it back has mean I can connect again.

I've also mucked about setting levels, here's the examples that worked:

# select the level attribute
[CH-DIMMER_C3E0:/service0029/char002a]# select-attribute 720a9082-9c7d-11e5-a7e3-0002a5d5c51b

# write the level to be "off"
[CH-DIMMER_C3E0:/service0029/char002e]# write "0x00 0x00"
Attempting to write /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char002e

# write the level to be max (where the "integer value" is 2710)
[CH-DIMMER_C3E0:/service0029/char002e]# write "0x10 0x27"
Attempting to write /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char002e

#write the level to be half(ish) ("integer level" of 1000)
[CH-DIMMER_C3E0:/service0029/char002e]# write "0x00 0x10"
Attempting to write /org/bluez/hci0/dev_XX_XX_XX_XX_C3_E0/service0029/char002e

Still to start with the python side of things, been a busy couple of weeks.

CalumOchkas commented 4 years ago

@phindmarsh Yes I'm in! Thanks a lot, the version was the trick. I had tried a couple of versions but the one you linked worked a treat.

CalumOchkas commented 4 years ago

A really quick play with BluePy this evening and the connection looks good:

> import bluepy
> from bluepy import btle

> p = btle.Peripheral("90:FD:9F:5C:E0:28")

> c = p.getCharacteristics(uuid="720a9082-9c7d-11e5-a7e3-0002a5d5c51b")[0]

> c.read()
'\x00\x00'
phindmarsh commented 4 years ago

Here's my progress so far, a class that can turn on/off a dimmer, and set the level. Assumes the dimmer is already paired with the bluetooth controller device (using bluetoothctl or whatever).

Next step for me is to bridge this into MQTT, because my home assistant instance runs on a VM that doesn't have a bluetooth stack.

https://gist.github.com/phindmarsh/a89cd407a57926e9f604e23cc9f9f5ce

ell249 commented 4 years ago

Following with interest guys - I reckon i've tried BLE connections with Iconic switches since they were released. My experience has been similar - works every time from my iPhone with BLE/GATT apps but really hit and miss from anything else. Interestingly I have some switches in my house that pair no problem and can reconnect anytime, and others that just refuse to even pair. Definitely keen on MQTT - keen to integrate with my Home Assistant!

CalumOchkas commented 3 years ago

Using @phindmarsh 's good work, I've got mine working at least in a test scenario with MQTT, here's the quickly thrown together code which I intend to clean up at some point: https://gist.github.com/CalumOchkas/5c148cecdb33baea32374a0e266b3792

It utilises the MQTT-Light HomeAssistant Integration with the config YAML as follows:

light:
  - platform: mqtt
    name: "Bedroom Light"
    unique_id: bedroomlight
    state_topic: "bedroom/light/status"
    command_topic: "bedroom/light/switch"
    brightness_state_topic: 'bedroom/light/brightness'
    brightness_command_topic: 'bedroom/light/brightness/set'
    brightness_scale: 10000
    qos: 0
    payload_on: "ON"
    payload_off: "OFF"
    optimistic: false
QuantumImmortality commented 3 years ago

Any update on this fellas? Considering buying these Clipsal smart modules but the only thing I'm not keen on is the lack of Home Assistant integration

@CalumOchkas @phindmarsh

CalumOchkas commented 3 years ago

I put this together a while ago, works well for me so I haven’t tried any further: https://github.com/CalumOchkas/PDL-Clipsal-BLEDimmer2MQTT

mathew-ryan commented 3 years ago

I’ve been following this for quite a while too, and have just installed switches but not integrated them yet.

A quick note to keep in mind is that Clipsal have finally made some movement on a hub with smart home integration. If you have a look at the new wiser app it shows options for both direct connection and hub connection, there are also references online to firmware upgrades for the switches which will support this. I’m not holding my breath but it could have impacts on the current solutions.