Bluetooth communication between Gen4 devices - It works!
Okay, so this is just a proof-of-concept script. It doesn't handle errors at all, and everything is hard coded. But it works!
I have a Shelly 1 Gen4 and a Shelly Plug US Gen4, both flashed to the 2.0.0-beta1 firmware. I'm using a Shelly 1 instead of an i4 so it can be powered by 12VDC, because my desk in the house isn't a place where I want exposed line voltages just lying around.
There can sometimes be a bit of a lag, but I've seen the same thing with official BTHome components like the Button1 or the Blu Remote I also have connected to this Plug.
Okay, caveats out of the way - it works!
Here's what I did:
On the Shelly 1 Gen4 -
- Update to firmware 2.0.0-beta1
- Add a script. My script looks like this, though I'm not sure whether the scan response is necessary since it doesn't seem to autodetect anyway. This script is written for the Shelly 1; when I try this on an i4, I'll update the script to check all four inputs for changes (as you'd do for a 4-way switch.)
Shelly.addStatusHandler(function(e) {
if (e.component === "input:0") {
BLE.AdvBuilder.reset();
BTHome.DataBuilder.reset();
BTHome.DataBuilder.addObject(0x0f, e.delta.state);
BLE.AdvBuilder.addBTHomeServiceData(BTHome.DataBuilder.build());
let adv = BLE.AdvBuilder.build();
BLE.AdvBuilder.reset();
BLE.AdvBuilder.addName("Hallway Switches", true);
BLE.advertiseOnce(adv, BLE.AdvBuilder.build());
}
});
- Start the script
- Set the script to start on boot
- Go to the Bluetooth settings and copy or write down the MAC address shown there
On the Plug US Gen4 -
- Update to firmware 2.0.0-beta1
- Go to the Components tab and click the + button in the BTHome devices section
- Click on the arrow next to "Add a device by MAC address"
- Paste or type the MAC address you got from the Shelly 1
- Leave the device model set to Unknown
- Click Add
- Wait for the device to be added. You should see the page reload after 30 seconds or so.
- You should now see a component with a name like "BTHomeDevice 204 - 7c:2c:67:7e:d5:36" (That's what mine's named. Yours will have a different MAC address, obviously.)
- Click on the gear next to the new device
- Flip the switch attached to the Shelly 1. You did connect a switch, right?
- Make sure you see a "Generic_boolean[0]" sensor in the Supported sensors section
- Save the settings
- Go to the Actions tab and create an action
- You should be able to find "Generic_boolean[0]" in the "Select component" dropdown.
- Go nuts! I set my action up to toggle the output on a state change, which effectively makes the switch an input to my Plug US Gen4.