tesla-local-control / tesla_ble_mqtt_docker

Apache License 2.0
18 stars 6 forks source link

VIN calculation wrong? #32

Closed jherby2k closed 2 weeks ago

jherby2k commented 2 weeks ago

Hi, still trying to get this up and running. Currently having issues getting presence detected - might be a bluetooth issue but i've also noticed something weird:

My VIN is 7SAYGDEE4PF778214

if i trigger a scan from HA, i see this in the logs:

Calculating BLE Advert Sda39a3ee5e6b4b0dC from VIN
Scanning Bluetooth for Sda39a3ee5e6b4b0dC, wait 10 secs

It never finds it. When i use bluetoothctl manually, i see a S5d99a0ac254c2a27C. I set that device's MAC and things are working now.

iainbullock commented 2 weeks ago

Hi, still trying to get this up and running. Currently having issues getting presence detected - might be a bluetooth issue but i've also noticed something weird:

My VIN is 7SAYGDEE4PF778214

if i trigger a scan from HA, i see this in the logs:


Calculating BLE Advert Sda39a3ee5e6b4b0dC from VIN

Scanning Bluetooth for Sda39a3ee5e6b4b0dC, wait 10 secs

It never finds it. When i use bluetoothctl manually, i see a S5d99a0ac254c2a27C. I set that device's MAC and things are working now.

@baylanger please could you comment on this one? Thanks

raphmur commented 2 weeks ago

This is weird, we should see S5d99a0ac254c2a27C coming from HA. The command it runs is VIN_HASH=`echo -n "7SAYGDEE4PF778214" | sha1sum` BLE_ADVERT=S${VIN_HASH:0:16}C which outputs S5d99a0ac254c2a27C. @jherby2k you are right, what you did is fine and should work for presence detection. Maybe there is typo in your VIN in the environment variables?

@baylanger I am not sure we are really supporting this type of scan now? Is it still needed to know the BLE LNAME?

jherby2k commented 2 weeks ago

Here, cut/paste from the log so you know i'm not crazy:

Received MQTT message tesla_ble_mqtt/7SAYGDEE4PF778214/config scan_bluetooth VIN: 7SAYGDEE4PF778214 COMMAND: config
Configuration scan_bluetooth requested
Scanning Bluetooth
Calculating BLE Advert Sda39a3ee5e6b4b0dC from VIN
Scanning Bluetooth for Sda39a3ee5e6b4b0dC, wait 10 secs

I pasted the VIN above into said hash function and also got S5d99a0ac254c2a27C.

jherby2k commented 2 weeks ago

Just noticed the scan function is using TESLA_VIN not TESLA_VIN1. Is that it?

edit: yep, that's the bug. If you hash an empty string you get Sda39a3ee5e6b4b0dC

Happy to create a PR but which branch is best? this repo confuses me :)

raphmur commented 2 weeks ago

Nice catch. I tested few typos, but not the empty string 🤦

You can have a look there: https://github.com/tesla-local-control/tesla_ble_mqtt_core WARNING: the code structure has changed quite a bit (more reliable in many ways) Also, now the VINs will be supplied as a list. Your issue should not be happening again...

... wait, I am checking as I write, I think we lost the function in charge of scanning... to get the MAC addresses --> PR created there: https://github.com/tesla-local-control/tesla_ble_mqtt_core/pull/71

We should be fine at next release then

iainbullock commented 2 weeks ago

Fixed in latest version. Re-open if you find otherwise, thanks