aioshelly
aioshelly copied to clipboard
aioshelly BLE script MAC address filtering
Hi all,
While preparing the rollout of our product, we have noticed that enabling shelly BLE scanning (in order to support Shelly BLU), causes quite an increase in network traffic. As there will be many Shellies on the same network, the effect gets amplified.
The script "aioshelly BLE script 1.0" reports every single BLE scan result to Home Assistant, without any means of rate limiting or filtering. As we are only interested in supporting Shelly BLU, would it be possible to filter the scan results based on mac prefix and only report matching devices? For example the following is working quite well:
// aioshelly BLE script 1.0 - filtered
BLE.Scanner.Subscribe(function (ev, res) {
if (ev === BLE.Scanner.SCAN_RESULT) {
prefix = "5c:c7:c1";
if (res.addr.slice(0, prefix.length) === prefix)
{
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,
});
Ideally the prefix list would be dynamic/adjustable, so that others could use this to target devices from a different vendor.
Thanks!
You can manually upload any script you want to the device and do not enable the BT proxy from HA. We can't support different scripts as there are endless options with scripts (I am already using a different script for another purpose)
Hi @thecode,
OK, that could work for us. But when we disable the BT proxy in HA, the BT scanner gets unregistered and we don't receive any data from BLU devices:
DEBUG (MainThread) [homeassistant.components.bluetooth.manager] Unregistering scanner shelly_ble (48:55:19:05:21:24)
We can still see the BLE scan events in our MQTT Debug connection, they are just not being processed in HA anymore.
Is there a way how this could be achieved?
Thank you for your support.
You can manually upload any script you want to the device and do not enable the BT proxy from HA. We can't support different scripts as there are endless options with scripts (I am already using a different script for another purpose)
Is there a way how we could use a custom BLE scanning script with stock Home Assistant BT Proxy implementation? As mentioned earlier disabling BT proxy in HA stops the processing of data from BLU devices...
Do I understand correctly, you want to use the HA BT proxy but not use its script, which is an integral part of the HA BT proxy? Users use BT proxy for devices from different manufacturers, so MAC filtering is not a good idea.
Do I understand correctly, you want to use the HA BT proxy but not use its script, which is an integral part of the HA BT proxy? Users use BT proxy for devices from different manufacturers, so MAC filtering is not a good idea.
Yes, that is correct. The problem is, that if you are in an area where there are many bluetooth devices, and you have multiple (shelly) proxies feeding the advertisements to HA, this generates a lot of network traffic. So we would like to implement the filtering in the shelly proxies, so that the traffic would be greatly suppressed.
@thecode : Would it be possible to have a fourth option "Own script" at this point?
Hi @RadekHvizdos, thank you for suggestion.
We internally evaluated pros and contras and decided not going with your suggestion. The risk that unskilled users change the script and complain is not working are too high for us.
In any way, I want to propose you a couple of steps that may resolve your issue:
- enable Bluetooth scanner mode from HA
- connect to the device via its own Web UI and overwrite the script with your own
That way you should achive your goal.
Let me know if it works for you.
@chemelli74 As I know that Shelly integration overwrites the script every time, when device is connecting or when HA restarts.
Not only it overwrites it constantly, but if I select "Disabled" in the Hass Bluetooth scanner mode and then I run the shelly plus script manually, without the remote upload, it still does not work, as it seems that the shelly script callbacks are not listened by my hass install. So I'm a bit lost.