Shelly Plus Bluetooth Proxy set up for presence detection - problems!

Hi - I’m a relative HA newbie but enjoying the journey HA is taking me on. With the recent releases allowing Bluetooth Proxy to work without having a hardware device connected to the HA instance (which I can’t because it’s running in Windows Hyper-V) I though I’d try this out with a view to using presence detection, but I don’t know if I’m missing something or if I need to wait for things to improve.

I’ve got 2 Shelly Plus Plug UK devices, added to native Shelly integration, running >0.12 firmware, clicked on configure and set to passive scanning. Have added the BLE Device tracker in configuration.yaml

device_tracker:
  - platform: bluetooth_le_tracker
    track_new_devices: true

I set up the BLE beacon in the HA companion app on my phone (Samsung Galaxy S20) hoping the Shelly would find it.

I have looked at the known_devices.yaml file, and after having the device plugged in for about 2 days, I now have over 200 devices showing, each with an entry like this:

03_61_52_27_24_0d:
  name: 03:61:52:27:24:0D
  mac: BLE_03:61:52:27:24:0D
  icon:
  picture:
  track: true

First problem is that not one of the mac addresses corresponds to my phone bluetooth mac address (as shown in settings->about phone->status information.

Second problem is that the Shelly doesn’t seem to be reporting the UUID, only the mac.

I notice on the Shelly device that after doing the Configure → Passive setting, a script is installed on the shelly:


// aioshelly BLE script 1.0
BLE.Scanner.Subscribe(function (ev, res) {
    if (ev === BLE.Scanner.SCAN_RESULT) {
        Shelly.emitEvent("ble.scan_result", [
            1,
            res.addr,
            res.rssi,
            btoa(res.advData),
            btoa(res.scanRsp)
        ]);
    }
});
BLE.Scanner.Start({
    duration_ms: -1,
    active: false,
    interval_ms: 320,
    window_ms: 30,
});

So unless the UUID is somehow encoded in advData or scanRsp, it isn’t sending it, and the BLE tracker integration certainly isn’t decoding or displaying it.

The final issue is that I have now set up a second Shelly Plus Plug UK, using all the same steps. I now see yet more things showing up in known_devices.yaml, but with no way of differentiating which Shelly device detected them.

So I guess my question is, are these all bugs or just the result of this being new and more development is needed? Or am I going about this the wrong way? and if so, how should I proceed to use the Shelly Plus devices for presence detection?

Thanks in advance

3 Likes

Forgot to say, I’m running

Home Assistant 2023.1.2
Supervisor 2022.12.1
Operating System 9.4
Frontend 20230104.0 - latest

in Windows Hyper-V on a Windows 10 Pro machine.

Hi Patrick,

I’m trying to get this working as well. In my case not because I run Home Assistant virtualized but to extend the range of Bluetooth in and around my house.

So far I found the following:

  • After setting up the Shelly integration I had to enable the script on the Shelly manually.
  • When visiting the webpage on the Shelly and going to Scripts > aioshelly_ble_integration and enable FULL LOG in the Console screen I can see all discovered devices. Sadly my phone Bluetooth address isn’t showing up.
  • When adding the following line after line 4/the first if statement I can see some devices have an address type ADDRESS_TYPE_RANDOM_RESOLVABLE. I think this is my phone. Line to add :point_down:
Console.log(res.addr, “(“, res.addr_type, “)”)

I don’t know how this is done in the Bluetooth tracker integration that runs on the Home Assistant host since I didn’t have to pair my phone while it’s working when in range of my Home Assistant host (a Raspberry Pi 4 in my case).

I’m currently checking if I can translate the private Bluetooth address into the actual adres. Hope this information helps you further and if you’ve found out how to solve I would love to hear how :slight_smile:

Wilfred

3 Likes

Hi, @wilfreddijksman and @PatrickT1 , have you made progress getting this to work since January?

I didn’t have time to look into it.

This morning I saw Shelly released 0.14.0 and mentions Added BLE Bluetooth observer (see Changelog | Shelly Technical Documentation). Not sure what is meant exactly with that but maybe it makes things work. I didn’t upgrade my Shelly’s yet.

The release today is what prompted me to start looking into finally getting ble working with my setup. I’m pretty sure the ‘Enable Bluetooth gateway’ new option in 0.14 is only for shelly bluetooth devices to communicate to the shelly cloud via a shelly pro device. Not relevant for HA.

2 Likes

I haven’t had time to look any further at this - I kind of gave up and was waiting for a few more releases of both Shelly firmware and HA before looking again to see if anything has changed. Will update if I find anything useful.

Hey all,
I am hitting exactly the same issue have 4 x shelly i4’s installed. Enabled the script and being hit with 100s of entries into known_devices.yaml none of them match any device I care about.

I’ve also added my phones bluetooth address to the list manually, just comes up as device is away when looking at entities.

Strangely enough, enabling the Bluetooth LE tracker in HA and enabling the script in shelly broke my iBeacons … they no longer report. So trying to recover these now before moving on (probably should of done this on a test HA instance haha)

I’ve not played about much more however, I did notice on the Shelly help section for scripts that there is a bit around helpers - BLE.GAP

BLE.GAP.ADDRESS_TYPE_PUBLIC = 1;
BLE.GAP.ADDRESS_TYPE_RANDOM_STATIC = 2;
BLE.GAP.ADDRESS_TYPE_RANDOM_NON_RESOLVABLE = 3;
BLE.GAP.ADDRESS_TYPE_RANDOM_RESOLVABLE = 4;

I’ve not played around with shelly scripts much, but wonder if using Public will help the situation?

Again don’t know enough about this, but just thoughts to try troubleshoot this.

1 Like

I have the same issue.

  1. Shelly Plus 1 PM installed
  2. Bluetooth LE Tracker setup in HA
  3. BLE devices are being found, however, despite having track_battery set to true, no battery state is being added to the discovered devices. Also, a lot of devices are being added.

I think, as @nickcj is pointing out, the script needs to be adapted.

1 Like

Hi @fair_dinkum

Can you please explain point 2. How do I set up BLE Tracker in HA using Shelly Plus? Thanks.

You need to enable active or passive scanning for the Shelly (go to the HA devices, click on your Shelly, then click the 3 dots … and there configure, then you can enable the BT scanning).

In your configuration.yaml, this will enable Bluetooth in general as well as the BLE tracker:

bluetooth:

device_tracker:
  - platform: bluetooth_le_tracker
    track_new_devices: true
    track_battery: true
    track_battery_interval: 3600

All BT scanned devices will now, after a reboot of HA, be added to the known_devices file and be available as devices in HA. Once the devices, which you are looking for, have been added to HA, you can set track_new_devices to false and delete all devices which you don’t need from the known_devices file. You need to reboot HA after setting the flag to false in order to stop discoverimg new BT devices.
BTW, battery tracking does not work with a shelly, according to github, you require an active connection to track the battery status, which is not supported with Shelly devices.

2 Likes

Thank you :blush:

so I managed to get the devices I am looking for and can see them on my developer tools. However all they report is home or not home. How can I implement and use according to their status? i.e. the Shelly Plus 1 is installed in the kitchen, is there anyway where I could name the zone as kitchen and track my phone when it enters the kitchen zone? thanks

Hey @bachoo786 I am interested in doing exactly the same. Still haven’t even started the process, but maybe you could edit the Shelly script to add an identifier you send to HA and then you can read it there? In the Shelly.emitEvent function.

By the way, how did you manage to identify your smartphones? Are you tracking Android or iOS devices?

A note to future researchers of this, Shelly plus battery powered devices, such as the Plus H&T (PlusHT), appear to be fairly useless for presence as there is no way to query nor set a polling interval, it only connects every 2 hours or when there is a temp update…

hey @50bbx

I am using room assistant currently for tracking my android (samsung s22+). Havent had much luck with the shelly plus I am afraid.

So you were able to track your Android device because it showed up in the HA list of devices?

yeah I can track my android device using room assistant but the only issue is the lack of raspberry pis.

I confugured a Shelly BLU Button, but is unusable for getting the presence.

I receive intermittently in presence signal, half-hourly? Is there a way to configure this apparatus to send continuously or to poll?
What other product has this function?

regards

I did not even setup the Shelly BLU Button after all since it forces me to create an account to be able to configure the button. Thus: 2 Shelly BLU Buttons for sale! :smiley:

I ended up purchasing these beacons, the battery is replaceable and according to the specs, the battery lasts 2-4 years (to be proofed :smiley: ) https://aliexpress.com/item/32845366171.html
You can configre the advertising window and signal strength and other details.

Update: the battery of the above lasted only for about 6 months and the its a non-common cell (CR2477). So I replaced them with these Beacons, (2x AAA batteries, also working with rechargeable batteries 1.2V), https://aliexpress.com/item/1005002008916105.html

I debugged the messages / connection with an ESP32 M5Stack Atom BT Proxy to find the right settings, I do not use the M5 Stack in production though, that was only for debugging. The above beacon needs the “active scanning mode” of your BT Proxy, the beacon does not send it when your BT Proxy is in “passive scanning mode”.

Finally, I use the following settings:

  • Shelly Plus 1PM / 2PM: enable active scanning mode
  • HolyIOT Beacon: Beacon Mode
  • HolyIOT Beacon: Advertising window: 300ms or less.
    If you go above 300ms, (next increment is 500ms in the HolyIOT app), the messages are not received reliable when you use a WiFi BT Proxy - might be different with an Ethernet BT Proxy.
  • HolyIOT Beacon: TX strength: 3 (maximum is 6)
    The higher you go, the stronger your BT-signal is, but the more battery-power you need.

This works like a charm and is very reliable as far as I can tell so far!

I do not use room detection, but that should be also possible with room assistant I guess…