Fabian-Schmidt / esphome-victron_ble

Use official Victron BLE endpoint for fetching data from Victron devices via Bluetooth LE via ESPHome.
GNU General Public License v3.0
158 stars 16 forks source link

Not connecting to BLE-devices #1

Closed snipah closed 1 year ago

snipah commented 1 year ago

Hi Fabian!

Brief question: What do I need to do for the devices to connect?

1) BLE is enabled in SmartSolar and Shunt 2) Mac-App connected and MAC/ Key extracted

''' {7fd30867-507c-9c8f-5f19-e7b0d96d6203}|e289af4fb6c8ed333494297acc0bb637 {7660ef55-97e5-49c3-59cc-5810c2bd7d05}|3af563e56794c0fb9198f541af2f08a9 ''' I assume, the MAC-addresses are e7:b0:d9:6d:62:03 and 58:10:c2:bd:7d:05 and the keys printed above are the AES-keys needed?

ESPhome compiles and boots up... but obviously nothing connects.

''' INFO Reading configuration /config/esphome/esp-poessl.yaml... INFO Starting log output from 192.168.1.29 using esphome API INFO Successfully connected to 192.168.1.29 [16:59:20][I][app:102]: ESPHome version 2023.3.0-dev compiled on Mar 1 2023, 16:38:56

[16:59:20][C][wifi:362]: Local MAC: 0C:B8:15:CD:8F:F4 [16:59:20][C][wifi:363]: SSID: 'poessl.net'[redacted] [16:59:20][C][wifi:364]: IP Address: 192.168.1.29 [16:59:20][C][wifi:366]: BSSID: 94:18:65:0A:A6:C5[redacted]

[16:59:20][C][wifi:369]: Signal strength: -38 dB ▂▄▆█ [16:59:20][C][wifi:373]: Channel: 13 [16:59:20][C][wifi:374]: Subnet: 255.255.255.0 [16:59:20][C][wifi:375]: Gateway: 192.168.1.1 [16:59:20][C][wifi:376]: DNS1: 0.0.0.0 [16:59:20][C][wifi:377]: DNS2: 0.0.0.0

[16:59:20][C][logger:294]: Level: DEBUG [16:59:20][C][logger:295]: Log Baud Rate: 115200 [16:59:20][C][logger:296]: Hardware UART: UART0 [16:59:20][C][victron_ble:014]: Victorn BLE: [16:59:20][C][victron_ble:015]: Address: E7:B0:D9:6D:62:03 [16:59:20][C][victron_ble:014]: Victorn BLE: [16:59:20][C][victron_ble:015]: Address: 58:10:C2:BD:7D:05 [16:59:20][C][victron_ble.binary_sensor:010]: Victron Binary Sensor 'Battery has Alarm' [16:59:20][C][victron_ble.binary_sensor:011]: Type 0 [16:59:20][C][victron_ble.binary_sensor:010]: Victron Binary Sensor 'MPPT is in Fault state' [16:59:20][C][victron_ble.binary_sensor:011]: Type 4 [16:59:20][C][victron_ble.binary_sensor:010]: Victron Binary Sensor 'MPPT has Error' [16:59:20][C][victron_ble.binary_sensor:011]: Type 1 [16:59:20][C][victron_ble.sensor:010]: Victron Sensor 'Time remaining' [16:59:20][C][victron_ble.sensor:010]: Device Class: 'duration' [16:59:20][C][victron_ble.sensor:010]: State Class: 'measurement' [16:59:20][C][victron_ble.sensor:010]: Unit of Measurement: 'min' [16:59:20][C][victron_ble.sensor:010]: Accuracy Decimals: 0

[16:59:20][C][victron_ble.sensor:011]: Type 22 [16:59:20][C][victron_ble.sensor:010]: Victron Sensor 'Battery voltage' [16:59:20][C][victron_ble.sensor:010]: Device Class: 'voltage' [16:59:20][C][victron_ble.sensor:010]: State Class: 'measurement' [16:59:20][C][victron_ble.sensor:010]: Unit of Measurement: 'V' [16:59:20][C][victron_ble.sensor:010]: Accuracy Decimals: 2

[16:59:20][C][victron_ble.sensor:011]: Type 9 [16:59:20][C][victron_ble.sensor:010]: Victron Sensor 'Starter Battery' [16:59:20][C][victron_ble.sensor:010]: Device Class: 'voltage' [16:59:20][C][victron_ble.sensor:010]: State Class: 'measurement' [16:59:20][C][victron_ble.sensor:010]: Unit of Measurement: 'V' [16:59:20][C][victron_ble.sensor:010]: Accuracy Decimals: 2

[16:59:20][C][victron_ble.sensor:011]: Type 7 [16:59:20][C][victron_ble.sensor:010]: Victron Sensor 'Current' [16:59:20][C][victron_ble.sensor:010]: Device Class: 'current' [16:59:20][C][victron_ble.sensor:010]: State Class: 'measurement' [16:59:20][C][victron_ble.sensor:010]: Unit of Measurement: 'A' [16:59:20][C][victron_ble.sensor:010]: Accuracy Decimals: 3

[16:59:20][C][victron_ble.sensor:011]: Type 8 [16:59:20][C][victron_ble.sensor:010]: Victron Sensor 'Consumed Ah' [16:59:20][C][victron_ble.sensor:010]: State Class: 'measurement' [16:59:20][C][victron_ble.sensor:010]: Unit of Measurement: 'Ah' [16:59:20][C][victron_ble.sensor:010]: Accuracy Decimals: 1

[16:59:20][C][victron_ble.sensor:011]: Type 11 [16:59:20][C][victron_ble.sensor:010]: Victron Sensor 'State of charge' [16:59:20][C][victron_ble.sensor:010]: Device Class: 'battery' [16:59:20][C][victron_ble.sensor:010]: State Class: 'measurement' [16:59:20][C][victron_ble.sensor:010]: Unit of Measurement: '%' [16:59:20][C][victron_ble.sensor:010]: Accuracy Decimals: 1

[16:59:20][C][victron_ble.sensor:011]: Type 20 [16:59:20][C][victron_ble.sensor:010]: Victron Sensor 'Battery Voltage' [16:59:20][C][victron_ble.sensor:010]: Device Class: 'voltage' [16:59:20][C][victron_ble.sensor:010]: State Class: 'measurement' [16:59:20][C][victron_ble.sensor:010]: Unit of Measurement: 'V' [16:59:20][C][victron_ble.sensor:010]: Accuracy Decimals: 2

[16:59:20][C][victron_ble.sensor:011]: Type 9 [16:59:20][C][victron_ble.sensor:010]: Victron Sensor 'Battery Current' [16:59:20][C][victron_ble.sensor:010]: Device Class: 'current' [16:59:20][C][victron_ble.sensor:010]: State Class: 'measurement' [16:59:20][C][victron_ble.sensor:010]: Unit of Measurement: 'A' [16:59:20][C][victron_ble.sensor:010]: Accuracy Decimals: 3

[16:59:20][C][victron_ble.sensor:011]: Type 8 [16:59:20][C][victron_ble.sensor:010]: Victron Sensor 'Yield Today' [16:59:20][C][victron_ble.sensor:010]: Device Class: 'energy' [16:59:20][C][victron_ble.sensor:010]: State Class: 'measurement' [16:59:20][C][victron_ble.sensor:010]: Unit of Measurement: 'kWh' [16:59:20][C][victron_ble.sensor:010]: Accuracy Decimals: 2

[16:59:20][C][victron_ble.sensor:011]: Type 23 [16:59:20][C][victron_ble.sensor:010]: Victron Sensor 'PV Power' [16:59:20][C][victron_ble.sensor:010]: Device Class: 'power' [16:59:20][C][victron_ble.sensor:010]: State Class: 'measurement' [16:59:20][C][victron_ble.sensor:010]: Unit of Measurement: 'W' [16:59:20][C][victron_ble.sensor:010]: Accuracy Decimals: 0

[16:59:20][C][victron_ble.sensor:011]: Type 19 [16:59:20][C][victron_ble.sensor:010]: Victron Sensor 'Load Current' [16:59:20][C][victron_ble.sensor:010]: Device Class: 'current' [16:59:20][C][victron_ble.sensor:010]: State Class: 'measurement' [16:59:20][C][victron_ble.sensor:010]: Unit of Measurement: 'A' [16:59:20][C][victron_ble.sensor:010]: Accuracy Decimals: 1

[16:59:20][C][victron_ble.sensor:011]: Type 15 [16:59:20][C][victron_ble.text_sensor:010]: Victron Text Sensor 'Battery Alarm reason' [16:59:20][C][victron_ble.text_sensor:011]: Type 2 [16:59:20][C][victron_ble.text_sensor:010]: Victron Text Sensor 'MPPT state' [16:59:20][C][victron_ble.text_sensor:011]: Type 4 [16:59:20][C][victron_ble.text_sensor:010]: Victron Text Sensor 'MPPT Error reason' [16:59:20][C][victron_ble.text_sensor:011]: Type 3 [16:59:20][C][esp32_ble:214]: ESP32 BLE: [16:59:21][C][esp32_ble_tracker:583]: BLE Tracker: [16:59:21][C][esp32_ble_tracker:584]: Scan Duration: 300 s [16:59:21][C][esp32_ble_tracker:585]: Scan Interval: 320.0 ms [16:59:21][C][esp32_ble_tracker:586]: Scan Window: 30.0 ms [16:59:21][C][esp32_ble_tracker:587]: Scan Type: ACTIVE [16:59:21][C][esp32_ble_tracker:588]: Continuous Scanning: True

[16:59:21][C][mdns:109]: Hostname: esp-poessl [16:59:21][C][ota:093]: Over-The-Air Updates: [16:59:21][C][ota:094]: Address: 192.168.1.29:3232 [16:59:21][C][api:138]: API Server: [16:59:21][C][api:139]: Address: 192.168.1.29:6053 [16:59:21][C][api:143]: Using noise encryption: NO [16:59:32][D][esp32_ble_tracker:238]: Starting scan... '''

Fabian-Schmidt commented 1 year ago

Hi, If you activate VERY_VERBOSE log level the ble tracker will print all devices it found and the mac addresses. It must be among them.

snipah commented 1 year ago

Thanks! But the keys extracted from the SQL-DB should be the correct ones? Will try but VERBOSE makes the ESP veeeeery slow, obviously :) Will report back!

Fabian-Schmidt commented 1 year ago

Use the USB connection when logging in VERY_VERBOSE and increase the speed by setting baud_rate: 2000000 (I got an CP2104 and they support baud rate of up to 2mbit).

The keys extracted look correct. ESP Home will refuse to build if they are too long or short. When the device is found I validate that the key might be correct by comparing the first byte of the key.

snipah commented 1 year ago

Now it works! Truma and Victron on one device, but I can't get the log to work anymore: ERROR Logger is not configured!, even though a have

logger: level: DEBUG

configured. But at least it is working now!

On to adding Topeka and getting the log up and running at least to be able to check if everything if working properly.

Thanks a lot for your support !

Fabian-Schmidt commented 1 year ago

What was the issue? As a lesson learned for others.

snipah commented 1 year ago

First of all: Everything seems to be fully working now without errors and without losing connection. Is it better to turn the debug-log off now? What do you think?

I can think of two possble reasons, why it did not work: 1) The db-extract gave me the wrong MAC-address. Might be, because I'm on Mac. Your tip with the "VERY VERBOSE"-Log was great! 2) Because of 1) I was unable to tell, which key belongs to which device! But to the key have to be in quotation marks? I tried without and now it is working.

If anything else comes to my mind, I will add it here!

Anyway: Thanks a lot!