home-assistant.io icon indicating copy to clipboard operation
home-assistant.io copied to clipboard

itegration: husqvarna_automower_ble: Initial commit

Open alistair23 opened this issue 1 year ago • 11 comments

Proposed change

This PR adds documentation for the Husqvarna Automower BLE integration.

The Husqvarna Automower BLE integration provides connectivity with Husqvarna Automowers lawn mowers via a local Bluetooth connection. This allows connecting and controlling an Automower without any accounts, cloud or network connection.

The integration is based on AutoMower-BLE, a unofficial reverse engineered Husqvarna Automower Connect BLE library.

Type of change

  • [ ] Spelling, grammar or other readability improvements (current branch).
  • [ ] Adjusted missing or incorrect information in the current documentation (current branch).
  • [X] Added documentation for a new integration I'm adding to Home Assistant (next branch).
  • [ ] Added documentation for a new feature I'm adding to Home Assistant (next branch).
  • [ ] Removed stale or deprecated documentation.

Additional information

  • Link to parent pull request in the codebase: https://github.com/home-assistant/core/pull/108326
  • Link to parent pull request in the Brands repository: https://github.com/home-assistant/brands/pull/4655
  • This PR fixes or closes issue: fixes #

Checklist

  • [X] This PR uses the correct branch, based on one of the following:
    • I made a change to the existing documentation and used the current branch.
    • I made a change that is related to an upcoming version of Home Assistant and used the next branch.
  • [X] The documentation follows the Home Assistant documentation standards.

alistair23 avatar Jan 18 '24 22:01 alistair23

As people have been asking for this feature and this PR seems to have stalled. If you would like to manually install this component you can follow these steps

Add version to manifest

You need to add a version to the manifest, you can apply this diff

diff --git a/homeassistant/components/husqvarna_automower_ble/manifest.json b/homeassistant/components/husqvarna_automower_ble/manifest.json
index cb3ee2a502..bd7db5f1f1 100644
--- a/homeassistant/components/husqvarna_automower_ble/manifest.json
+++ b/homeassistant/components/husqvarna_automower_ble/manifest.json
@@ -12,5 +12,6 @@
   "dependencies": ["bluetooth_adapters"],
   "documentation": "https://www.home-assistant.io/integrations/???",
   "iot_class": "local_polling",
-  "requirements": ["automower-ble==0.1.32"]
+  "requirements": ["automower-ble==0.1.32"],
+  "version": "0.1.0"
 }

Install component

Then just rsync the entire homeassistant/components/husqvarna_automower_ble directory from this PR to /root/homeassistant/custom_components/ on your HA instance

Enable logging for debugging

You will also want to enable debug logging by adding this to your homeassistant/configuration.yaml file. That helps identify any issues.

logger:
  # default: debug
  logs:
    custom_components.husqvarna_automower_ble: debug
    custom_components.husqvarna_automower_ble.config_flow: debug
    automower_ble.mower: debug

Then reboot.

ESPHome setup

Make sure you don't have a ble_client element in your setup

After that it should work. If you have any issues please file an issue on either the HA GitHub instance or at https://github.com/alistair23/AutoMower-BLE. Please include the logs of any issues cat ./config/home-assistant.log | grep mow is generally a good place to start.

If this works for you maybe comment here, that might help convince someone to review this

alistair23 avatar Mar 25 '24 11:03 alistair23

Hello, we wrote an email together a few days ago. I can hardly wait until it is hopefully firmly integrated into HA. Unfortunately I have no skills to integrate it. My new RASPI 5 8GB runs with Zigbee2MQTT, Masiquito, Home Asstistant Tasmota and so on in a docker system. 11 Zigbee components running in Node Red and HA. Is it worth the wait because it is then totally easy to integrate? Or is there a guide for beginners?

Does a device have to run with ESP Home? The RASPI 5 can do that too, can't it?

Can i klick anywhere to make a like or a WANT IT, that can help you ?

wlan4you avatar Apr 05 '24 17:04 wlan4you

Hi Alistair, I have replaced by ESP32 with a new one with an external antenna and have copied over my YAML, which includes the BLE MAC address of the mower.

Do I need to clear anything in HA, or just go through the pairing process again and re-add the integration?

My ESP is reporting as follows, but I cannot see the custom_component when I try and add the integration and I can't see anything in the logs for 'mow' or 'ble'. I have cleared the previous custom_components folder and copied the latest version over, but cannot see the component as an integration.

[17:39:01][I][esp32_ble_client:067]: [3] [0C:EC:80:E0:64:EE] 0x00 Attempting BLE connection
[17:39:01][D][esp32_ble_client:110]: [3] [0C:EC:80:E0:64:EE] ESP_GATTC_CONNECT_EVT
[17:39:01][D][esp32_ble_client:110]: [3] [0C:EC:80:E0:64:EE] ESP_GATTC_OPEN_EVT
[17:39:01][D][esp32_ble_client:110]: [3] [0C:EC:80:E0:64:EE] ESP_GATTC_SEARCH_CMPL_EVT
[17:39:01][I][esp32_ble_client:227]: [3] [0C:EC:80:E0:64:EE] Connected
[17:39:01][D][ble_client:058]: All clients established, services released
[17:39:01][D][esp32_ble_client:188]: [3] [0C:EC:80:E0:64:EE] cfg_mtu status 0, mtu 65

Can you help me installing the integration? Thank you so much https://github.com/alistair23/AutoMower-BLE/issues/43

al31c0 avatar May 09 '24 20:05 al31c0

HI @alistair23 I have replaced my ESP32 with a new model and external antenna, but I have a couple of issues. Could you guide me?

I cannot get the Integration working again in HA. I have removed it from custom_components and re-added the latest version. I didn't have a manifest.json file, so have created one, but when I try to add the integration it says it needs manual configuration. If I add config flow: true it fails with an unexpected handling error reporting that config_flow.py does not exist. Should this be set and if so, I can't find the .py in the current files listing.

{   
    "domain": "husqvarna_automower_ble",
    "name": "Husqvarna Automower BLE",
    "dependencies": ["bluetooth_adapters"],
    "documentation": "https://www.home-assistant.io/integrations/???",
    "iot_class": "local_polling",
    "requirements": ["automower-ble==0.1.32"],
    "version": "0.1.0"
}

Also, do I need to re-do anything in my ESP YAML? I note that the instructions say to not have a ble_client entry, but it isn't clear whether this gets automatically populated when pairing or not.

esp32_ble_tracker:
  scan_parameters:
    active: false
    continuous: false
    duration: 50sec

bluetooth_proxy:
  active: true
  cache_services: true

ble_client:
  - mac_address: 0C:EC:80:E0:64:EE
    id:  automower_305
    on_disconnect:
      then:
        - esp32_ble_tracker.start_scan:

Many thanks!

Fayrewood avatar May 10 '24 11:05 Fayrewood

As people have been asking for this feature and this PR seems to have stalled. If you would like to manually install this .... If this works for you maybe comment here, that might help convince someone to review this

And for the lazy people (like myself 😆)

Oneliner, be inside the custom_components folder when executing this

curl -LJO https://github.com/alistair23/homeassistant-core/archive/refs/heads/alistair/husqvarna_automower_ble.zip && unzip -q homeassistant-core-alistair-husqvarna_automower_ble.zip && mv homeassistant-core-alistair-husqvarna_automower_ble/homeassistant/components/husqvarna_automower_ble ./husqvarna_automower_ble && rm homeassistant-core-alistair-husqvarna_automower_ble.zip && rm -rf homeassistant-core-alistair-husqvarna_automower_ble

jkaberg avatar May 13 '24 08:05 jkaberg

FABULOUS!! Thank You!

I've got a manifest file which I was missing now!

Don't forget to add "version": "0.1.0" to the end of the manifest file.

And for the lazy people (like myself 😆)

Oneliner, be inside the custom_components folder when executing this

curl -LJO https://github.com/alistair23/homeassistant-core/archive/refs/heads/alistair/husqvarna_automower_ble.zip && unzip -q homeassistant-core-alistair-husqvarna_automower_ble.zip && mv homeassistant-core-alistair-husqvarna_automower_ble/homeassistant/components/husqvarna_automower_ble ./husqvarna_automower_ble && rm homeassistant-core-alistair-husqvarna_automower_ble.zip && rm -rf homeassistant-core-alistair-husqvarna_automower_ble

Fayrewood avatar May 13 '24 09:05 Fayrewood

I am really struggling to get my mower paired after replacing my ESP32. What I do is:

  1. Power on the mower (A305) and put it into pairing mode.
  2. Power on the ESP32 BT Proxy
  3. Add the MAC address into the Integration config flow windows

From my early experiences, PIN security is turned off and I have tried pairing several times.

I get the following errors - any ideas?

[15:15:02][I][esp32_ble_client:067]: [3] [0C:EC:80:E0:64:EE] 0x00 Attempting BLE connection
[15:15:02][D][esp32_ble_client:110]: [3] [0C:EC:80:E0:64:EE] ESP_GATTC_CONNECT_EVT
[15:15:02][D][esp32_ble_client:110]: [3] [0C:EC:80:E0:64:EE] ESP_GATTC_OPEN_EVT
[15:15:02][D][esp32_ble_client:110]: [3] [0C:EC:80:E0:64:EE] ESP_GATTC_SEARCH_CMPL_EVT
[15:15:02][I][esp32_ble_client:227]: [3] [0C:EC:80:E0:64:EE] Connected
[15:15:02][D][ble_client:058]: All clients established, services released
[15:15:02][D][esp32_ble_client:188]: [3] [0C:EC:80:E0:64:EE] cfg_mtu status 0, mtu 65
[15:15:20][D][sensor:094]: 'BT Irrigation WiFi dB': Sending state -46.00000 dBm with 0 decimals of accuracy
[15:15:20][D][sensor:094]: 'BT Irrigation WiFi Percent': Sending state 100.00000 Signal % with 0 decimals of accuracy
[15:15:23][I][bluetooth_proxy:282]: [0] [0C:EC:80:E0:64:EE] Connecting v3 without cache
[15:15:23][I][esp32_ble_client:067]: [0] [0C:EC:80:E0:64:EE] 0x00 Attempting BLE connection
[15:15:23][D][esp-idf:000]: W (58533) BT_GATT: gatt_connect wrong state 4

[15:15:23][D][esp32_ble_client:110]: [0] [0C:EC:80:E0:64:EE] ESP_GATTC_OPEN_EVT
[15:15:23][D][esp32_ble_client:110]: [0] [0C:EC:80:E0:64:EE] ESP_GATTC_SEARCH_CMPL_EVT
[15:15:23][I][esp32_ble_client:227]: [0] [0C:EC:80:E0:64:EE] Connected
[15:15:23][D][esp32_ble_client:188]: [0] [0C:EC:80:E0:64:EE] cfg_mtu status 0, mtu 65
[15:15:23][D][esp32_ble_client:110]: [0] [0C:EC:80:E0:64:EE] ESP_GATTC_READ_CHAR_EVT
[15:15:24][D][esp32_ble_client:110]: [0] [0C:EC:80:E0:64:EE] ESP_GATTC_READ_CHAR_EVT
[15:15:24][D][esp32_ble_client:110]: [0] [0C:EC:80:E0:64:EE] ESP_GATTC_READ_CHAR_EVT
[15:15:24][D][esp32_ble_client:110]: [0] [0C:EC:80:E0:64:EE] ESP_GATTC_READ_CHAR_EVT
[15:15:24][D][esp32_ble_client:110]: [0] [0C:EC:80:E0:64:EE] ESP_GATTC_READ_CHAR_EVT
[15:15:24][W][bluetooth_proxy.connection:076]: [0] [0C:EC:80:E0:64:EE] Error reading char/descriptor at handle 0x E, status=5
[15:15:24][D][esp32_ble_client:110]: [0] [0C:EC:80:E0:64:EE] ESP_GATTC_READ_CHAR_EVT
[15:15:24][D][esp32_ble_client:110]: [0] [0C:EC:80:E0:64:EE] ESP_GATTC_READ_CHAR_EVT
[15:15:24][I][esp32_ble_client:084]: [0] [0C:EC:80:E0:64:EE] Disconnecting.
[15:15:24][D][esp32_ble_client:110]: [0] [0C:EC:80:E0:64:EE] ESP_GATTC_CLOSE_EVT

Here's my ESP32 code:

substitutions:
  name: esphome-web-685e2c
  friendly_name: BT and Irrigation

esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  name_add_mac_suffix: false
  project:
    name: esphome.web
    version: '1.0'

esp32:
  board: esp32dev
  framework:
    type: esp-idf
    version: recommended

# Enable logging
logger:
  level: debug

# Enable Home Assistant API
api:

# Allow Over-The-Air updates
ota:

# Allow provisioning Wi-Fi via serial
improv_serial:

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Garden-Proxy-Irrigation"
    password: "passwordredacted"

captive_portal:

esp32_ble_tracker:
  scan_parameters:
    active: false
    continuous: false
    duration: 50sec

bluetooth_proxy:
  active: true
  cache_services: true

ble_client:
  - mac_address: 0C:EC:80:E0:64:EE
    id:  automower_305
    on_disconnect:
      then:
        - esp32_ble_tracker.start_scan:

time:
  - platform: homeassistant
    on_time:
      - seconds: 0
        minutes: '*'
        then:
          esp32_ble_tracker.start_scan:


button:
  - platform: restart
    name: Restart
    entity_category: diagnostic
    disabled_by_default: false
    icon: mdi:restart
    device_class: restart


sensor:
  - platform: wifi_signal # Reports the WiFi signal strength/RSSI in dB
    name: "BT Irrigation WiFi dB"
    id: irrigation_wifi_signal_db
    update_interval: 60s
    entity_category: "diagnostic"

  - platform: copy # Reports the WiFi signal strength in %
    source_id: irrigation_wifi_signal_db
    name: "BT Irrigation WiFi Percent"
    filters:
      - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
    unit_of_measurement: "Signal %"
    entity_category: "diagnostic"
    device_class: ""




switch:
  - platform: gpio
    pin: 14
    name: "R1 Pergola"

  - platform: gpio
    pin: 12
    name: "R2 Beds"

  - platform: gpio
    pin: 4
    name: "R3 Spare"

  - platform: gpio
    pin: 5
    name: "R4 Spare"

Fayrewood avatar May 13 '24 14:05 Fayrewood

I commented out the ble_client in the ESP32 yaml and paired successfully. Now removed comments, so that it will force a scan on disconnect.

Fayrewood avatar May 13 '24 14:05 Fayrewood

As people have been asking for this feature and this PR seems to have stalled. If you would like to manually install this .... If this works for you maybe comment here, that might help convince someone to review this

And for the lazy people (like myself 😆)

Oneliner, be inside the custom_components folder when executing this

curl -LJO https://github.com/alistair23/homeassistant-core/archive/refs/heads/alistair/husqvarna_automower_ble.zip && unzip -q homeassistant-core-alistair-husqvarna_automower_ble.zip && mv homeassistant-core-alistair-husqvarna_automower_ble/homeassistant/components/husqvarna_automower_ble ./husqvarna_automower_ble && rm homeassistant-core-alistair-husqvarna_automower_ble.zip && rm -rf homeassistant-core-alistair-husqvarna_automower_ble

Can you help me installing the integration? Thank you so much https://github.com/alistair23/AutoMower-BLE/issues/43

al31c0 avatar May 13 '24 22:05 al31c0

Can you help me installing the integration? Thank you so much

I can try, but I've had issues and happy to try and help.

Firstly, have you got your Bluetooth proxy ESP32 set up? If not, I can share my ESP32 code. Comment out anything you have under ble_client for now (we'll need it later).

Secondly, go to a terminal session in HA via the SSH / Terminal add on and change directory to the ./config/custom_components folder. Delete anything you may currently have for husqvarna-Automower and rub the curl command as above to copy the correct files.

Find the MAC address of the mower which is easiest done with an android device, or an app on IOS device to scan for BT devices.

Then, edit the manifest file and add a version entry at the end of the file: "version": "0.1.0" and save the file.

Check that the mower security level is set to low (no pin required other than power on) and put it into New Pairing mode from the accessories menu.

Restart HA and go to Integrations and ADD. You should see husqvarna BLE as a new integration. With the mower still in pairing mode, add an entry and enter the Mac address with the colons between each address pair.

It's worth having a second window open to view the ESP logs as it's connecting. You should see green entries for success messages and yellow for any issues.

Back in the integration, your mower should be connected and you'll see two entries for the device name and the battery level.

If that hasn't worked, try the pairing again, paying attention to the logs in the ESP window.

If it has worked, remove the comments from the ESP code for the ble_client so that in the event of a disconnect, it will force a scan and reconnect.

Hope this help you get further.

Fayrewood avatar May 14 '24 07:05 Fayrewood

I've been using code from this repo, which is using a slightly newer version of the lib. Note that I'm in a specific commit to avoid some issues as the repo is for testing purposes: https://github.com/erikmol/hass-automower-ble-hacs/tree/f95f5e1e0e955e74a5ee6c468b82b33670abfed3/custom_components/husqvarna_automower_ble

For ESPHome I only have this configuration as a minimal for bluetooth. Not sure if it's the best, but it works except a bit unstable.

esp32_ble_tracker:
  scan_parameters:
    active: true
    continuous: true
    duration: 50sec

bluetooth_proxy:
  active: true
  cache_services: true

peternijssen avatar May 14 '24 15:05 peternijssen