Index base station ble_client

Hiya, fellas

I’ve created a BLE tracking configuration for the Valve Index base stations using an esp32, and I’m looking to share it here. I’ve seen the HACS community integration, but I was already working on this when I found it. This is working as-is, but if anyone knows how to encapsulate the sensor into the switch lambda, that would cut down on yet another state item in my DB. You can find your MAC address for your own base stations using a variety of command line tools or smartphone apps, the name will start with “LHB” and can be detected with the base stations on or off.

ble_client:
  - mac_address: XX:XX:XX:XX:XX:XX
    id: LHB_X

sensor:
  - platform: ble_client
    type: characteristic
    ble_client_id: LHB_X
    name: "LHB_X state"
    id: "LHB_X_state"
    service_uuid: '00001523-1212-efde-1523-785feabcd124'
    characteristic_uuid: '00001525-1212-efde-1523-785feabcd124'
    icon: 'mdi:access-point'
    update_interval: 01min

switch:
  - platform: template
    name: "LHB_X Switch"
    turn_on_action:
      - ble_client.ble_write:
          id: LHB_X
          service_uuid: 00001523-1212-efde-1523-785feabcd124
          characteristic_uuid: 00001525-1212-efde-1523-785feabcd124
          # List of bytes to write.
          value: 0x01
    turn_off_action:
      - ble_client.ble_write:
          id: LHB_X
          service_uuid: 00001523-1212-efde-1523-785feabcd124
          characteristic_uuid: 00001525-1212-efde-1523-785feabcd124
          # List of bytes to write.
          value: 0x00
    lambda: |-
      if (id(LHB_X_state).state) {
        return true;
      } else {
        return false;
      }
4 Likes

I just wanted to say thank you, because I’ve been trying to control the basestations with HACS integration but something goes wrong now and then and in the end almost all the time I need to boot them from the phone because the automation is broken.
I’ll make some testing with this method and let you know the results.

Thank you again for sharing :slight_smile:

Hi Edupop,

Thanks for this, I’ve tried the homeassistant-basestation HACS integration and it works fine, but I’m not able to get the base stations to sleep with 0x02.
With your method I can get them to sleep with 0x02 but I seem to only be able to control one base station.

Do you have any suggestions on how to control more than 3 base stations?

Again, thanks!

Should have checked here first. I just implemented this very similarly for my two base stations. I just added the following config to an ESP32 doing Bluetooth proxy duties.

Just replace MAC_OF_LIGHTHOUSE_1_HERE and MAC_OF_LIGHTHOUSE_2_HERE with the MAC addresses of your lighthouses

esp32_ble_tracker:

ble_client:
  - mac_address: MAC_OF_LIGHTHOUSE_1_HERE
    id: lighthouse_ble_client_1
  - mac_address: MAC_OF_LIGHTHOUSE_2_HERE
    id: lighthouse_ble_client_2

sensor:
  - platform: ble_client
    type: characteristic
    ble_client_id: lighthouse_ble_client_1
    id: lighthouse_1_state
    name: "Lighthouse 1 power"
    service_uuid: "00001523-1212-efde-1523-785feabcd124"
    characteristic_uuid: "00001525-1212-efde-1523-785feabcd124"
    internal: True
    update_interval: 10s
  - platform: ble_client
    type: characteristic
    ble_client_id: lighthouse_ble_client_2
    id: lighthouse_2_state
    name: "Lighthouse 2 power"
    service_uuid: "00001523-1212-efde-1523-785feabcd124"
    characteristic_uuid: "00001525-1212-efde-1523-785feabcd124"
    internal: True
    update_interval: 10s

output:
  - platform: ble_client
    id: lighthouse_1_switch
    ble_client_id: lighthouse_ble_client_1
    service_uuid: "00001523-1212-efde-1523-785feabcd124"
    characteristic_uuid: "00001525-1212-efde-1523-785feabcd124"
    require_response: false
  - platform: ble_client
    id: lighthouse_2_switch
    ble_client_id: lighthouse_ble_client_2
    service_uuid: "00001523-1212-efde-1523-785feabcd124"
    characteristic_uuid: "00001525-1212-efde-1523-785feabcd124"
    require_response: false

switch:
  - platform: template
    name: "Lighthouse 1"
    lambda: |-
      return id(lighthouse_1_state).state;
    turn_on_action:
      - output.turn_on: lighthouse_1_switch
    turn_off_action:
      - output.turn_off: lighthouse_1_switch
  - platform: template
    name: "Lighthouse 2"
    lambda: |-
      return id(lighthouse_2_state).state;
    turn_on_action:
      - output.turn_on: lighthouse_2_switch
    turn_off_action:
      - output.turn_off: lighthouse_2_switch

Hi thex, I managed to get up to three working at a time but not more. I’m currently using the ble_proxy but it’s not being very reliable… but it works with more than 3 devices at least.
Would be nice to manually start a connection, do an action, break the connection and continue with another device.