BM2 battery monitoring using ble tracker component

@peterkeen thank you for your work. Just a question. Is it possible to change the script so that if the bm2 is not available, it returns the value “unknown” or “not available”? The background is that if my car is not there, the last value is still there.

Did you figure out how to fix this :point_up_2: ? I find it really anoying and I can not even update the ESP configuration wirelessly because of this as I get a timeout on confirmation message.

Sorry no. I gave up. I got the impression the current incarnation does not allow you to change it.

1 Like

@coyote1 I updated the script in the gist to output “unknown” for the voltage and 0.0 for the charge because HA doesn’t seem to appreciate a non-numeric number there. That said I couldn’t get it to actually change to that value, so if you want to play with the script and/or the template sensor and see if you can make it do that, I’d love to hear how to fix it.

Thanks for posting this! I’m trying to set this up and I am running into some errors and hoping for some guidance if you can!

I installed Pyscript with both config boxes checked. I also copied your bt.py file into the Pyscript directory under /custom_components/pyscript and added your template.yaml code to my configuration.yaml with the serial / mac address for my BM2 unit.

As of now, I have the entity showing in HA as unavailable and am getting the following two errors:

Logger: custom_components.pyscript.file.bt.get_charger_data
Source: custom_components/pyscript/eval.py:510
integration: Pyscript Python scripting

Exception in <file.bt.get_charger_data> line 26: for (k,v) in service_info.manufacturer_data.items(): ^ AttributeError: ‘NoneType’ object has no attribute ‘manufacturer_data’

As well as:

Logger: custom_components.pyscript.function
Source: custom_components/pyscript/function.py:453
integration: Pyscript Python scripting

run_coro: got exception Traceback (most recent call last): File “/config/custom_components/pyscript/eval.py”, line 755, in call raise TypeError(f"{self.name}() called with unexpected keyword arguments: {unexpected}") TypeError: get_charger_data() called with unexpected keyword arguments: response_variable

I BELIEVE I’ve followed everything correctly and just hoping you could provide some insight to point me in the right direction on this. I don’t believe there are any other additions needed in the ESPHome config for my Bluetooth ESP32 or anywhere else with your config correct? Thanks again for provide the code for ESPHome!

I updated the gist to gracefully handle this case. There are a few potential reasons for this, but the first thing I would check is if you have the mac address for your bm2 correct and in the correct format. It needs to be all upper-case letters and numbers, in groups of two, each group separated by a colon.

Check the indentation in your YAML file for response_variable. It needs to be at the same level as data (i.e. one level less indented than address). Make sure not to mix tabs and spaces in the same file.

@peterkeen

Hi Peter, I have updated the python script. But it doesn’t work the way I imagined it would :slight_smile: After the update it is now like this: The auto with the BM2 was not there when I reloaded the script, it was then also displayed as “unknown” for voltage. So far correct. The car was then within range and the voltage and charge status were displayed, but if the car is not there now, the last value remains on the display. I thought that if the BM2 is not reachable, “unknown” is displayed, but this is not the case.
Here is another screenshot where you can see it clearly, in the area marked in red, the car was not in range. Can anything be done about this?

i must be missing something because I get this error on compile.