There are many reasons use MQTT along side HA. It is a pretty integral tool that HA uses. I like being able to keep my sensors and other things that communicate with HA outside of HA and use MQTT as the entry for the sensor data into HA, keeps HA cleaner and more stable I think. I find that I can customize the behavior of MQTT sensors much more extensively that other sensors where the functions and attributes are baked in.
As far as the bluetooth sensors, using one or more external collector boxes like a RPI in my case, or esp32’s in other models, lets you have better reception range. If you only use the bluetooth adapter in you HA server, this may limit your coverage range.
I have flashed the same firmware but now I’m lost on how to get it working with HA ? sorry still finding my way around it home you can help. like which platform did you use? what did you set the advertising format to? thanks
I have to say that you first need to check that your Bluetooth (BT) controller is capable of communicating with the new firmware. My controller is BT v4.1 and it does not see the Xiaomi sensors with the new firmware .So I had to downgrade back to stock firmware. I could buy a new BT controller - but my position is that the new firmware should as a minimum be backward compatible - which it is not - so I do not use it anymore. There is nothing in the new firmware that cannot be achieved with BT4.1
So first you need to check your BT version If you do not have BT 5.0 or higher then I think the firmware will not work so go back to OEM.
In terms of HA,
It’s all described here:
This is my config as an example
ble_monitor:
hci_interface: 0
discovery: False
active_scan: False
report_unknown: False
batt_entities: True
rounding: False
decimals: 1
period: 60
log_spikes: False
use_median: True
restore_state: False
devices:
#-- replace {MAC-addr} with MAC address of sensor but leave the single quotes
- mac: '{MAC-addr}'
#-- replace {key} with MAC address of sensor but leave the single quotes
encryption_key: '{key}'
temperature_unit: C
Interested to know what Bluetooth version 5 adapter you recommend for Linux and Home Assistant? I am pretty sure there are no Bluetooth version 5 adapters that currently have linux drivers. If someone made a product that required Bluetooth 5 today, they would probably sell about five units… The ACT_Mi custom firmware works fine with every Bluetooth v4.x adapter I have tried, maybe six different ones.
This is what I found at the end and it is working fine with the RaspberryPi 3 Bluetooth except for the battery it is still showing unknown after a day! same configuration as you except that I don’t have encryption_key.
I might try reflashing to see if the changes I did to the configuration has anything to do with it. I will also try without the custom fw since it is easy to get the key anyway. If I find differences in battery consumption I might switch since this is what many seems to complain about.
Not sure what are you taking about. bluz5 is quite common and widely supported . One would have to go far back to kernel 4.0 for blz5 to be incompatible. Current linux recommendation is to move to kernel 5.5 to secure latest BT compatibility.
The Pi3 runs kernel 5.4 (assuming a headless raspberry OS in install). Hence the sensor custom firmware does not work on any of my Pi boxes.
I’m sure members would love to know how you got it working on “about 6 of them”. What adapters, name them, show us a dump - for each - of Bluetooth and kernel logging when scanning and pairing using the custom fw. I would show mine but it’s pointless because it doesn’t work and so the logs are not going to positively assert anything of tangible benefit. Only the OEM fw for these sensors, will work.
I could upgrade the kernel but I’m not, for these sensors offer no useful functionality to my need as what I have working is sufficiently acceptable. My post earlier on was misguidedly made as I had not attempted to use the sensor with latest fw on my HA install node, I was using a PC on which it did work (under Windows 10 not Linux)
EDIT: I just remembered I wanted to test a new bluetooth keyboard that doest work with my HA Pi3 box … so I will upgrade the kernel and retest the sensor custom fw at the same time.
EDIT1:
Oh hell. I didn’t see that bit. I bet that is why it aint working. Arggg. I will reflash…I sense I may be coming back here with my tail between the legs …hang on…
EDIT:2
Nope, still doesn’t work. All sensors can be seen by all boxes in the house (all linux 5.4 kernels) with OEM fw but not with ATC or pvvx firmware.
Been working with these for 2 weeks or so and all is well in so far as tx/rx and HA sensors. Works well.
However
My bt controller keeps going to ‘DOWN’ every two days or so, sometimes a day, sometimes three days.
My box is an RPi3b with the integrated bt controller. Had this box for a few years now and bt keyboards and headsets worked flawlessly. Since using these sensors and the HA integration here, the bt controller is periodically going down and I do not know why. There is nothing specific in the HA logs other than the usual “HCI loop aborted” thing (because HA cannot access the controller) but I think one needs to set DEBUG as an option on bt somewhere in the linux config to get system logging. I don’t know so will look into this.
I can restore things through the command line by using
systemctl stop homeassistant
then
hciconfig reset hci0
hciconfig command sometimes times-out and gives an error. I just keep repeating it every 5 seconds and all is well , eventually.
If I leave it there, all is well , until I restart homeassistant. After a few hours, the bt goes down again. So there is a pattern.
I am going to try debug log level for bluetooth and this integration. Will come back with updates - but in the meantime is anyone else seeing the same issue at all?
EDIT: By the way, I’m using the pi-bluetooth stack and not bluez. I could not get much success at all with the bt controller even working with bluez (which masks hci packages and the hci interfaces by the way).
and best of all, zero downtime. I found that this integration kept loosing the BT controller, although it is important for me to make it clear that the BT controller going down is not an issue with this integration but rather a symptom of buggy python bluetooth stack.
I think based on this I will try the XiaoMi Mijia LCD Bluetooth Thermometer Hygrometer 2 High Precision Sensor. I just want a bluetooth, RF, or zigbee device that has a read out on the screen.