-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shelly BTHome Components support #553
Comments
Xiaomi (Mijia) also does not support unregistered devices working in the Mijia format. Perhaps Shelly also requires device registration (on Cloud?). |
@pvvx I'll wait for the Shelly H&T and will check that. |
@Misiu , I have a Shelly 1 mini Gen3 that is picking up the Temp, Humidity and Battery sensors up from the LYWSD03MMC units with pvvx's custom firmware perfectly fine. They show up as "components" under the Shelly. In order to pair the Shelly to the LYWSD03MMC, I needed to add the device as a component in the local Shelly Web Interface via the LYWSD03MMC's MAC. After a couple seconds/minutes (depending on advertising interval) it should appear on the Shelly device. (see screenshot below) To view the LYWSD03MMC, you can look at the local Shelly Web Interface where it is listed as a device with sensors on the Dashboard and Components pages. (see below) If you are looking at the Shelly Cloud interface, you need to navigate to the "components" submenu on the Shelly device you're connecting to. (see below) At the moment, I'm working on checking if I can get the Shelly Cloud interface to thinking that the LYWSD03MMC is a Shelly BLU H&T so that it can be added as a "first class" Shelly Device with all the UI integrations that entails. As is, Shelly does not support Dynamic Components as "first class" devices, but plans on doing so (they have no eta, unfortunately the ticket I opened with them is not public).
|
I haven't tried to get the value from a BTHome Device, but I have a script which gets and sets the values on Virtual Components (the other kind of Dynamic Component) while parsing the values from raw Bluetooth packets. Here's the gist It should be a decent example of how to read events (temp changes) from a Dynamic Component, though you'll need to check the exact syntax for BTHome Sensors. I'm trying to achieve the same goal as you, but for a larger set of people. The reason I'm moving away from the gist approach is because it requires users to go to a specific IP on their local network in order to change the temperature or need to navigate through a bunch of sub menus in Shelly Cloud. If you're just building this thermostat for one household, it's likely more maintainable (arguable) and user friendly to set them up with home assistant - this is what I do for myself and it's worked great. If I get Shelly to accept LYWSD03MMC as a first class component, I'll update this thread. Didn't have much progress yesterday - as you suspected, Shelly doesn't follow the entire BTHome standard and I ran into issues with the emulation. If you could share some of the advertisements and data beacon packets from the Shelly H&T you're purchasing, it would be appreciated. Thanks! |
@shaivadnai thanks for the update, just tell me what to do and I'll be more than happy to help. Here is the output from the Shelly BLE Debug app:
Here raw data from BLE scanner app:
Hope this helps |
Are you, per chance, able to add it to the Shelly cloud directly instead of locally? Does Shelly cloud treat the H&T as a first class component while connected to the Shelly 1 Mini Gen 3 or the to the cloud via the S1MG3? If not, then there's no difference in functionality between the Shelly H&T and the LYWSD03MMC as configured right now. Right? |
currently, I can add LYWSD03MMC as a Bluetooth (BTHome) device by manually entering the MAC address, while BLE H&T was found using Scan functionality. I didn't add BLE H&T to the cloud yet, I can do this, but it must be done via Shelly App. You enable Bluetooth on your phone, then you scan for a new device and it is somehow paired with your account. Then the device is available in the app as a separate device. |
@Misiu, thanks for confirming it's possible to add H&T as a standalone cloud device - I have to log off for a bit, but I'm going to work on rewriting/adding to pvvx's firmware to be compatible with Shelly's standard so we can attempt to add it via the app. Thanks for the additional details regarding the BLU H&T's payload, I can see some misunderstandings I had regarding their spec and will work on rectifying them when I have some more time. I'll push a fork when I have something that works so you can try testing. @pvvx thanks for making this project so easy to work on - the Dev Container was awesome and after pulling the image I was up and running in seconds! |
@Misiu I haven't done this either, but try using the generic Shelly.addEventHandler() to see if some of the events coming through are related to BTHome Devices. If that doesn't work, calling Shelly.getComponentStatus() in a loop will likely be able to retrieve the Sensor's status, though it's not particularly elegant If none of the above works, Shelly.call() will likely allow you to use the BTHomeSensor.GetStatus RPC locally and pass it into a callback function of your choosing. |
@shaivadnai thank you for the help.
it works, but I must test it before I use in in a "production" environment. |
I have bricked my device and seem to be unable to resurrect it via UART (which is what I have on hand). If I can bring it back again, I'll continue working on it - but for now I'm probably going to take a break. This is how I interpreted the packet you got from the Shelly H&T: Raw Packet 0201060D16D2FC4400E201642E3945ED000A08534248542D3030334310FFA90B0111000B03000A7DCE57B6C67C
The existing BTHome firmware implementation uses a PDU function that adds a CRC at the end (and inserts the 0D in 2. for the length) - which is expected as per the BTHome spec. However, I can't see the CRC in the packet you sent. In a poorly thought out attempt to keep the PDU function, but remove the CRC, I bricked my device. If someone can get the device to output a packet which follows the above schema, you can probably add it to the shelly cloud app directly. I'd be curious to hear if it works. |
The program on the smartphone "nrf connect" can create arbitrary BLE advertising.
adv. structure:
There is no CRC in the PDU data. The BTHome description shows the packet transmitted by the Linux driver. This is the RF packet data with additional information - watch description of "HCI". Many are mistaken on this. There are still problems with parsing even a simple 8-bit AD.Flags in Linux (Bluez). Not to mention something else. Linux development in Bluetooth has remained at the level of 2014 (BT4.2 standard). Someone is forcibly holding back Bluetooth development in Linux (kernel, Bluez, Black). BTHome only applies to the format of one structure in the PDU data of a packet: |
@shaivadnai I'm sorry to hear that. I always thought that we can flash and restore the device with a cable connection.
Please let me know if I can use any Windows app or a web app (like your flasher) to help. I can gather additional packets. I think that Shelly detects devices that are manufactured by Shelly. After Scanning or manual adding of the Shelly BLU H&T I see that it is added with the manufacturer name, for LYWSD03MMC I got unknown. @shaivadnai any updates from the Shelly team? Home Assistant supports virtual components, but the Shelly app has terrible support - I was able to add a virtual component to Shelly device, I see it in the app (but I must navigate to components), but I'm unable to add it to "the main view" of a component or to a room. |
I've just got a reply on my ticket. |
In Shelly, the advertising packet in the PDU contains the manufacturer data (structure identifier: 0xff) and the device name. In typical BLE, the device name is transmitted as a response to an active scan request. That is, in an additional packet transmitted on request. Custom firmware transmits the name in the main advertising package only in BT5.0 mode. Since in BT5.0 the size of the transmission package data is limited to kilobytes, and not 20..32 bytes, as in BT4.2. It is also advisable to check if the Shelly "LE Long Range" option works, which provides a 4x increase in the BLE communication range. This is available in the Bluetooth standard since version 5.0 (since 2016). If not, these devices should be moved to the trash bin as obsolete. |
Just FYI, bought a Shelly Blu H&T, when it arrived my HA auto picked it up as BTHome device, seems to be active in the box. Per Shelly used the mobile |
Shelly Gen 3 and Pro devices support BTHome Components - https://shelly.guide/bthome-components/
this way you can bind Shelly BLU devices directly to other devices and use the sensors in scripts or scenes, even without wifi.
I have a couple of LYWSD03MMC units flashed with your firmware, all set to BTHome v2, but the Shelly devices don't pick (find) them.
I'd like to ask for an additional format - Shelly BLU.
LYWSD03MMC reports temperature and humidity so as Shelly BLU H&T.
You can get LYWSD03MMC for 3€, and Shelly H&T costs around 22€, so the price difference is huge.
I'm going to order two Shelly units, so if I can help with providing logs or any other data I can gather from an Android phone or Windows 10 PC please let me know.
I'm not sure what is the difference between Shelly BTHome and BTHome v2 formats, maybe there aren't any differences, but I don't know how to check that and how to fix the issue.
The main idea is to use LYWSD03MMC directly with Shelly without internet access or any proxies or servers.
The text was updated successfully, but these errors were encountered: