home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
70.13k stars 29.18k forks source link

Gardena Bluetooth Irrigation Bluetooth connection is unreliable #103117

Closed alistair23 closed 1 month ago

alistair23 commented 9 months ago

The problem

This is somewhat similar to https://github.com/home-assistant/core/issues/98561 in that the Bluetooth connection disconnects when using an ESPHome Bluetooth proxy. The connection stays up for a few days, but eventually the Gardena device becomes unavailable.

Once the device has become unavailable it won't reappear until I remove and reinsert the battery from the device.

That doesn't always work though. The attached log in the issue is while I power cycle the Gardena device but it doesn't reconnect in the HA UI.

The ESPHome device is located very close to the Gardena Bluetooth controller, but it is a long distance from the WiFi access point. I am working on hard wiring it encase that is the issue.

What version of Home Assistant Core has the issue?

core-2023.10.5

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

gardena_bluetooth

Link to integration documentation on our website

https://www.home-assistant.io/integrations/gardena_bluetooth

Diagnostics information

logs_esp32-bluetooth-proxy_logs.txt

ha.log

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2023-10-27 10:07:48.474 WARNING (MainThread) [homeassistant.components.sensor] Entity sensor.esp32_bluetooth_proxy_front_soil_moisture (<class 'homeassistant.components.esphome.sensor.EsphomeSensor'>) is using native unit of measurement '%' which is not a valid unit for the device class ('voltage') it is using; expected one of ['mV', 'V']; Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+esphome%22

2023-10-27 15:08:18.153 WARNING (MainThread) [aioesphomeapi.connection] esp32-bluetooth-proxy @ 172.16.2.8: Connection error occurred: [Errno 104] Connection reset by peer

2023-10-31 08:41:34.553 WARNING (Recorder) [homeassistant.components.esphome.bluetooth.client] Bluetooth 
Proxy 3daf64 [e0:e2:e6:3d:af:64]: None - E4:E1:12:FF:A3:E0: ESPHomeClient bleak client was not properly d
isconnected before destruction


### Additional information

_No response_
elupus commented 3 months ago

If any body can add that check to their proxy devices, it would be a nice thing to test.

elupus commented 3 months ago

You can test that fix by adding something like this to your config:

external_components:
  - source: github://pr#6590
    components: [ bluetooth_proxy ]
wtom commented 3 months ago

For me it's working now pretty stable without any connection losses, since 2 days. I will post my config later.

elupus commented 3 months ago

I would much appreciate if somebody tested above mentioned fix. I thunk that fix is correct, but unsure if it solves the issue here.

wtom commented 3 months ago

I can try it from Monday on.

wtom commented 3 months ago

Testing it now.

elupus commented 3 months ago

@wtom unlikely to make a difference. Looks like nothing will trigger that change.

There does seem to be potential issues with multiple connections, so having any ble_client section in your esp proxy config it's most likely to just make thing worse.

elupus commented 3 months ago

In theory i have a fix for having a ble_client config in your esp proxy. it is still invalid to have that section there for this device, but should break less with the changes in https://github.com/esphome/esphome/pull/6596

external_components:
  - source: github://pr#6596
    components: [ bluetooth_proxy, esp32_ble_client ]
wtom commented 3 months ago

This config with the Gardena Firmware 1.7.23.29 works so far stable. Since 4 days no connection loss, even with the new start after uploading the pr#6590.

Maximum in the past was like 3 days at most.

packages:
  esphome.bluetooth-proxy: github://esphome/firmware/bluetooth-proxy/esp32-generic.yaml@main

esp32_ble_tracker:

external_components:
  - source: github://pr#6590
    components: [ bluetooth_proxy ]

#ble_client:
#  - mac_address: B0:D2:78:91:4C:42
#    id: gardena_water_switch
#    auto_connect: false

I can add and test the new change as well, if you need to.

wtom commented 3 months ago

Still working stable here without connection loss.

elupus commented 3 months ago

Can you switch to the alternate version i posted above?

wtom commented 3 months ago

Sure, i will install it now.

Edit: After installing, the connection was again made without a power cycle. I will let it run, and i will report if something unexpected will happen.

[09:26:07][I][bluetooth_proxy:278]: [0] [B0:D2:78:91:4C:42] Connecting v3 with cache
[09:26:07][D][esp32_ble_tracker:215]: Pausing scan to make connection...
[09:26:07][I][esp32_ble_client:067]: [0] [B0:D2:78:91:4C:42] 0x00 Attempting BLE connection
[09:26:09][D][esp32_ble_client:110]: [0] [B0:D2:78:91:4C:42] ESP_GATTC_CONNECT_EVT
[09:26:09][D][esp32_ble_client:110]: [0] [B0:D2:78:91:4C:42] ESP_GATTC_OPEN_EVT
[09:26:09][I][esp32_ble_client:154]: [0] [B0:D2:78:91:4C:42] Connected
[09:26:09][D][esp32_ble_tracker:266]: Starting scan...
[09:26:09][D][esp32_ble_client:188]: [0] [B0:D2:78:91:4C:42] cfg_mtu status 0, mtu 247
[09:26:09][D][esp32_ble_client:110]: [0] [B0:D2:78:91:4C:42] ESP_GATTC_READ_CHAR_EVT
[09:26:09][D][esp32_ble_client:110]: [0] [B0:D2:78:91:4C:42] ESP_GATTC_READ_CHAR_EVT
[09:26:10][D][esp32_ble_client:110]: [0] [B0:D2:78:91:4C:42] ESP_GATTC_READ_CHAR_EVT
[09:26:10][D][esp32_ble_client:110]: [0] [B0:D2:78:91:4C:42] ESP_GATTC_READ_CHAR_EVT
[09:26:10][D][esp32_ble_client:110]: [0] [B0:D2:78:91:4C:42] ESP_GATTC_READ_CHAR_EVT
[09:26:10][D][esp32_ble_client:110]: [0] [B0:D2:78:91:4C:42] ESP_GATTC_READ_CHAR_EVT
[09:26:10][D][esp32_ble_client:110]: [0] [B0:D2:78:91:4C:42] ESP_GATTC_READ_CHAR_EVT
[09:26:10][D][esp32_ble_client:110]: [0] [B0:D2:78:91:4C:42] ESP_GATTC_READ_CHAR_EVT
[09:26:10][D][esp32_ble_client:110]: [0] [B0:D2:78:91:4C:42] ESP_GATTC_READ_CHAR_EVT
[09:26:10][D][esp32_ble_client:110]: [0] [B0:D2:78:91:4C:42] ESP_GATTC_READ_CHAR_EVT
[09:26:10][D][esp32_ble_client:110]: [0] [B0:D2:78:91:4C:42] ESP_GATTC_READ_CHAR_EVT
[09:26:10][D][esp32_ble_client:110]: [0] [B0:D2:78:91:4C:42] ESP_GATTC_READ_CHAR_EVT
[09:26:11][D][esp32_ble_client:110]: [0] [B0:D2:78:91:4C:42] ESP_GATTC_READ_CHAR_EVT
[09:26:16][I][esp32_ble_client:084]: [0] [B0:D2:78:91:4C:42] Disconnecting.
[09:26:16][D][esp-idf:000]: W (18337) BT_HCI: hci cmd send: disconnect: hdl 0x0, rsn:0x13

[09:26:16][D][esp-idf:000]: W (18344) BT_APPL: gattc_conn_cb: if=3 st=0 id=3 rsn=0x16

[09:26:16][D][esp-idf:000]: W (18346) BT_APPL: gattc_conn_cb: if=4 st=0 id=4 rsn=0x16

[09:26:16][D][esp-idf:000]: W (18347) BT_APPL: gattc_conn_cb: if=5 st=0 id=5 rsn=0x16

[09:26:16][D][esp32_ble_client:110]: [0] [B0:D2:78:91:4C:42] ESP_GATTC_CLOSE_EVT
[09:26:16][D][esp-idf:000]: W (18381) BT_HCI: hcif disc complete: hdl 0x0, rsn 0x16
wtom commented 3 months ago

No problems so far.

elupus commented 3 months ago

Perfect. @alistair23 could you test with above config too? Make sure there is no active ble client in your config.

alistair23 commented 3 months ago

Testing now. I'll report back in a few days

alistair23 commented 3 months ago
esp32_ble_tracker:
  id: ble_tracker_id
  scan_parameters:
    interval: 1100ms
    window: 1100ms

bluetooth_proxy:
  active: true
  cache_services: true

external_components:
  - source: github://pr#6596
    components: [ bluetooth_proxy, esp32_ble_client ]

Doesn't seem to make a difference. The device still disappears.

The config from https://github.com/home-assistant/core/issues/103117#issuecomment-2068770732 has the same issue as well.

Firmware version: 1.7.8.18

elupus commented 3 months ago

Please remove the tracker did too to start with.

You said you could not update the firmware? My guess is that is the key here.

alistair23 commented 3 months ago

There appears to be no way to update the older firmware, same as https://github.com/home-assistant/core/issues/103117#issuecomment-2056556459

xlemassacre commented 3 months ago

I got both my valves replaced now by Gardena because of the bluetooth issue. I also had a bad/slow connection via official app and couldn't update the firmware. The replaced valves had a newer firmware and I could immediately update them to (probably) the latest firmware (1.7.23.29) via the App . Bluetooth connection is now way better

Regarding bluetooth proxy, I still had issues that the connection was gone after a few minutes. But with that config/PR it looks quite stable. I'll watch it now in the next days

packages:
  esphome.bluetooth-proxy: github://esphome/firmware/bluetooth-proxy/esp32-generic.yaml@main

external_components:
  - source: github://pr#6590
    components: [ bluetooth_proxy ]

esp32_ble_tracker:
wtom commented 2 months ago

8 days now and no problems with


external_components:
  - source: github://pr#6596
    components: [ bluetooth_proxy, esp32_ble_client ]
elupus commented 2 months ago

Perfekt. The changes in pr6596 have been merged upstream. So will not be needed once next esphome release is out.

mback2k commented 2 months ago

Are the changes from that PR enough to make it stable or are additional config changes like mentioned further above still needed compared to the standard Bluetooth Proxy config that ESPHome deploys from their website?

elupus commented 2 months ago

Standard ble proxy should be enough. Enabling additional things are more likely to break it, so avoid that.

stefanogito commented 2 months ago

I have similar issues. Where can I put that script part with "external_components" to? I tried to add it to my configuration.yaml but receive an error right away, complaining about the external_components to be not known.

wtom commented 2 months ago

I have similar issues. Where can I put that script part with "external_components" to? I tried to add it to my configuration.yaml but receive an error right away, complaining about the external_components to be not known.

On the ble proxy yaml file.

marithpl commented 2 months ago

I've added external_components to my esphome yaml, with no huge affect.

Devices are disconnecting almost every few minutes. But once before 9PM disconnects till now.

image

My YAML:

esp32_ble_tracker:
  scan_parameters:
    interval: 2000ms
    window: 1000ms
    active: true

bluetooth_proxy:
  active: true

external_components:
  - source: github://pr#6590
    components: [ bluetooth_proxy ]  
elupus commented 2 months ago

That config wont help. 6590 has no effect. Look at my post above with 6596. But make sure you have new firmware on your device.

jurgenhaas commented 2 months ago

I'd like to go for that configuration as well, but I don't have ESP hardware yet. Can someone point me to a parts list, what I need to buy when I don't have anything yet, not even experience with ESP?

marithpl commented 2 months ago

That config wont help. 6590 has no effect. Look at my post above with 6596. But make sure you have new firmware on your device.

I changed for 6596, for fist 10 minutes valves were unavailable. But now it's finally online - let's see for how long :)

I'd like to go for that configuration as well, but I don't have ESP hardware yet. Can someone point me to a parts list, what I need to buy when I don't have anything yet, not even experience with ESP?

Just ESP32 - it's enough.

elupus commented 2 months ago

Ps. Do note that 6596 has an additional component on it.

bdraco commented 2 months ago

Additionally, there are also some more BLE fixes in ESP-IDF 4.4.7. This was reported to fix a problem where scans stop and don't start again with active scanning for a few users.

esp32:
  framework:
    type: esp-idf
    version: 4.4.7
jurgenhaas commented 2 months ago

I'd like to go for that configuration as well, but I don't have ESP hardware yet. Can someone point me to a parts list, what I need to buy when I don't have anything yet, not even experience with ESP?

Just ESP32 - it's enough.

Do you have a link? On esphome.io I don't find hardware and on Amazon I only find chips that I need to plug into a board, but I don't know what board is needed?

bdraco commented 2 months ago

I use these for my production.

Some slight soldering required.

https://blakadder.com/gl-s10/

bdraco commented 2 months ago

If you want something that requires no soldering

https://www.olimex.com/Products/IoT/ESP32/

ESP32-POE-ISO-EA is the model you want

If you want something that has a case as well

ESP32-EVB-EA

And the box: https://www.olimex.com/Products/IoT/ESP32/BOX-ESP32-EVB-EA/

jurgenhaas commented 2 months ago

Thanks a lot, this is very helpful.

alistair23 commented 2 months ago

For reference, Gardena told me this

Our Global Service in Germany have confirmed any new models with or after firmware version 1.7.13.20 “No FOTA” (remote firmware update) it is possible to conduct an update.

They also said

We have been advised by our Global Tech Team that the water computer you have is not capable of doing a firmware update. We suggest if the computer is still within the 2 year warranty period that you return it to the place of purchase for a replacement.

So if you are reading this and have a version earlier then 1.7.13.20 go and return it. It sounds like it has been recalled, but Gardena are refusing to issue an official recall

marithpl commented 2 months ago

First few hours after change. Works but not stable.

image
elupus commented 2 months ago

haos 12.3 includes bluez fixes that might be relavent for those using ble adapters instead of proxies

marithpl commented 2 months ago

One valve works as it wants - lots of disconnections Second valve is disconnected...

image
elupus commented 2 months ago

@marithpl You have not mentioned what firmware yours are running. As noted, some are seemingly broken

marithpl commented 2 months ago

1.7.23.29 & 1.7.8.18

alistair23 commented 2 months ago

The 1.7.8.18 device will need to be returned, it won't create a reliable connection

https://github.com/home-assistant/core/issues/103117#issuecomment-2107137994

o0larrylurex0o commented 2 months ago

Hello, I'm adding my piece here I have the Water Control Bluetooth 01889-20, brand new. Firmware updated (1.7.23.29)

HA on a RPI4

It has connected very fast to HA the first time I booted it up.

But it won't connect again since I placed it in its location outside. I have a Shelly Plus PM 1 meter away configured as a bluetooth proxy (I tried Active and Passive) That can see it shelly_notification:209 Event from script:1: {"component":"script:1","id":1,"event":"ble.scan_result","data":[2,[["f0:5e:cd:2d:bf:08",-82,"AgEGEQbkbdx1v93lhBpCDgsBAL2Y",""]]],"ts":1715588372.58}

HA can see it aswell, but cannot seem to connect at all I don't understand why the RSSI is so low since the shelly is very close

➜  ~ bluetoothctl | grep F0:5E:CD:2D:BF:08
[CHG] Device F0:5E:CD:2D:BF:08 RSSI: 0xffffffa0 (-96)
hci0 F0:5E:CD:2D:BF:08 type LE Public connect failed (status 0x08, Timeout)
[DEL] Device F0:5E:CD:2D:BF:08 F0-5E-CD-2D-BF-08
[NEW] Device F0:5E:CD:2D:BF:08 F0-5E-CD-2D-BF-08
[CHG] Device F0:5E:CD:2D:BF:08 RSSI: 0xffffffa2 (-94)
hci0 F0:5E:CD:2D:BF:08 type LE Public connect failed (status 0x03, Failed)
[DEL] Device F0:5E:CD:2D:BF:08 F0-5E-CD-2D-BF-08
hci0 F0:5E:CD:2D:BF:08 type LE Public connected eir_len 0
[NEW] Device F0:5E:CD:2D:BF:08 F0-5E-CD-2D-BF-08
hci0 F0:5E:CD:2D:BF:08 type LE Public disconnected with reason 1
[CHG] Device F0:5E:CD:2D:BF:08 Connected: no
[CHG] Device F0:5E:CD:2D:BF:08 RSSI: 0xffffffa1 (-95)
[CHG] Device F0:5E:CD:2D:BF:08 AdvertisingFlags:
[CHG] Device F0:5E:CD:2D:BF:08 RSSI: 0xffffff9c (-100)
[DEL] Device F0:5E:CD:2D:BF:08 F0-5E-CD-2D-BF-08

➜  ~ bluetoothctl info F0:5E:CD:2D:BF:08
Device F0:5E:CD:2D:BF:08 (public)
        Alias: F0-5E-CD-2D-BF-08
        Paired: no
        Bonded: no
        Trusted: no
        Blocked: no
        Connected: no
        LegacyPairing: no
        UUID: Vendor specific           (98bd0001-0b0e-421a-84e5-ddbf75dc6de4)
        RSSI: 0xffffffa3 (-93)
        AdvertisingFlags:  06

And here is the error I got in HA

2024-05-14 17:48:49.222 ERROR (MainThread) [homeassistant.components.gardena_bluetooth] Error fetching Gardena Bluetooth Data Update Coordinator data: Unable to update data for 98bd0f13-0b0e-421a-84e5-ddbf75dc6de4 due to Communcation failed with device: Gardena Bluetooth - F0:5E:CD:2D:BF:08: Failed to connect after 10 attempt(s): No backend with an available connection slot that can reach address F0:5E:CD:2D:BF:08 was found: The proxy/adapter is out of connection slots or the device is no longer reachable; Add additional proxies (https://esphome.github.io/bluetooth-proxies/) near this device

Does anybody have any idea ? Is the shelly not suitable for this purpose ?

thx a lot

mback2k commented 2 months ago

Shellys are not suitable for this purpose as they don't proxy actual Bluetooth connections, they only support advertisements.

o0larrylurex0o commented 2 months ago

ah ..... that solves it .... thx a lot

wtom commented 2 months ago

Here still no problems anymore.

tonnguyen commented 2 months ago

I have two ESP32 proxies and that seems to be a problem. I paired my Gardena BT to the proxy at the second floor and the connection is stable, no disconnect. Then I brought it downstair which has another BT proxy then it kept disconnecting. Brining it back to the second floor then it works again flawlessly.

marithpl commented 2 months ago

And finaly disconnected (today at 2AM).

Home Assistant restarted, ESP restarted and connection won't come back.

image
echavet commented 1 month ago

Hi there, I'm trying to find a way to use my ESP32 as a proxy with the Gardena Bluetooth, and it It seems that this is what some of you are doing. Are you using the gardena bridge? I can't find any documentation on the way to do it. And I am completely confused about how all this is supposed to work. I don't have any gardena bridge and I am wondering is if I can do without it and use a Bluetooth proxy on an ESP32 chip instead, to add a valve control service for HA.

What I understand: There is 2 ways to use the electronic valve.

  1. Without brigde: simply connect the gardena bt directly to the smartphone. In This case, does the ESP32 bt proxy have any interest? How are we supposed to configure the connection of the gardena bt with the ESP? And then the smartphone with the ESP?
  2. With the brigde: Simply plug it, configure the HA integration. In this case how does the esp32 work to provide the bt proxy to the bridge?

Thanks for help of course it would help to see your yaml and to know your setup

echavet commented 1 month ago

I reply to myself:

No need to have a Gardena bridge to get the Gardena Bluetooth vane integrated to home assistant. Just an ESP32 configured as an USB proxy by adding this section in the ESPHome yaml configuration file:

esp32_ble_tracker:
  scan_parameters:
    interval: 1100ms
    window: 1100ms

bluetooth_proxy:
  active: true

I then had to reset the Gardena Vane to factory default like it is suggested here.

After the factory reset, my home assistant instance automatically suggested me (from the "Device and Services section") to install the Gardena Integration. If it does not, you will have to click the "Add Integration" button and to pickup the Gardena Bluetooth integration. I could then retreive all the sensors to manage my gardena device.

Of course, the ESP32 has to be configured to be connected to your home assistant instance. Which should be done automatically once to setup a Wifi section in esphome yaml conf file:

wifi:
  #ssid: !secret wifi_ssid
  #password: !secret wifi_password

  # or with multiple networks
  networks:
  - ssid : !secret wifi_ssid1
    password: !secret wifi_password3
  - ssid: !secret wifi_ssid2
    password: !secret wifi_password