Hello. If you are on the side of using Shelly devices through MQTT, and want to use them as a gateway for BLE devices, let me show you the overhauled version of ble-pasv-mqtt-gw.js
script, originally available in Shelly scripts library.
I’ve created a pull request in the Shelly repo, but from what I’ve seen so far, nobody maintains PRs actively (like PRs fixing syntax errors not accepted for months). So, one doesn’t know when it will get to the official repo.
If you are interested, here is the link to the script:
New features
- Added support for Shelly Door/Window BLE, Buttons BLE (H&T, RC Button 4 etc.)
- Buttons are reported with the use of MQTT events
- Added MACs filtering (incl option to use KVS)
- Added (optional) Manufacturer/Model,
- Added
connections
,identifiers
, andvia_device
to the MQTT discovered device - Debug to the console, helping in adding a new device (enabled by default, with an option to disable it)
Improvements
- Fixed Celsius units
- Fixed sensors possibly changing their topic (see breaking changes)
- Fixed window state and tilt turned unknown when restarting HA
- It’s because BLE devices don’t always report these attributes, so after HA restart, they are missing from the retained message
- Rotation state renamed to Tilt
- Window state renamed to Contact, and window class renamed to Opening. Both to allow better flexibility (ie for doors)
- optimizations
- The device is rendered for a processed device only once
- More abbreviations used within MQTT discovery
- More detailed documentation
Breaking changes:
The data are no longer stored in sensor
, telemetry
, and status
topics. The new common topic is data
.
It will not impact users who rely on discovery
Click for details
There are multiple reasons for that:- Reported values may belong to different classes, for example, temperature → sensor, RSSI → telemetry.
- The first message determines creation of MQTT discovery objects incl. data topic. A different set of sensors in subsequent messages might cause pointing to a different topic
- Sensors don’t guarantee that all their values are reported at once. For example, RSSI might be reported with a button, or with temperature (case of Shelly H&T BLE)
It turns out that depending on the combination of values in the event, particular values might got their topic changed as time goes by.
Changed naming schema
- Devices will be named with the format:
mac-model
ormac
if the model is not provided - Names of discovered entities will be set to device class, ie
temperature
. Then HA will create entity_id based onmac-model devclass
, for example (sensor.xxxxxxxxx_ht_temperature
) unique_id
of entities is set tomac-type
(xxxxxxxxx-window
) ormac-type-index
(xxxxxxxxxxx-button-2
)
Click for details
Change to the naming aligns final device and entity names with Home Assistant standards.HA will name the entity to devicename name
, for example: 1a2b3c4d5e6f-H&T BLU Temperature
. Then, renaming the device gives an option to automatically rename entities in order to follow the device name change. For example, changing the name of the device to PCROOM HT
will (after confirmation) turn the entity name into PCROOM HT Temperature
.
On top of that, some HA pages (ie, device view) can strip the device name out of the entity name, making them shorter and less cluttered.