Use 2 ESPHome Bleproxies instances to update data for one plant sensor

I am using esphome with the ble_proxy functionality to pick-up measurements from my Xiaomi Miflora plant sensor and feed those into the Plant integration in HA for my plants.

I currently have to ESPs in my house and the plant was planned to be only picked up by one of them location-wise. This all works fine. But now I wanted to start moving the plants based on the weather (e.g. move them outdoors) and as a matter of fact the first ESP can’t pick the readings no longer up but the 2nd can.

So I tried to just copy resp. add the sensor config from the first ESP to the 2nd and it works and I get the readings in HA now form the 2nd ESP.

The config I use is:

  encryption:
    key: "xxx"

ota:
  - platform: esphome
    password: "xxxx"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Bleproxy WZ Fallback Hotspot"
    password: "xxxx"

captive_portal:

esp32_ble_tracker:
  scan_parameters:
    # We currently use the defaults to ensure Bluetooth
    # can co-exist with WiFi In the future we may be able to
    # enable the built-in coexistence logic in ESP-IDF
    active: false
  
sensor:
  - platform: xiaomi_hhccjcy01
    mac_address: 5C:85:7E:13:76:06
    temperature:
      name: "Dipsys Temperature"
    moisture:
      name: "Dipsys Moisture"
    illuminance:
      name: "Dipsys Illuminance"
    conductivity:
      name: "Dipsys Conductivity"
    battery_level:
      name: "Dipsys Battery Level"

  - platform: xiaomi_hhccjcy01
    mac_address: 5C:85:7E:13:73:EA
    temperature:
      name: "Banana Temperature"
    moisture:
      name: "Banana Moisture"
    illuminance:
      name: "Banana Illuminance"
    conductivity:
      name: "Banana Conductivity"
    battery_level:
      name: "Banana Battery Level"

bluetooth_proxy:
  active: true

But the problem is that they are now ofc kind of duplicate as the full names of the readings are “sensor.bleproxy_sz_banana_illuminance” (from the first ESP, no longer updated) and now “sensor.bleproxy_wz_banana_illuminance” (from the 2nd) but the “plant” device is configured to use the bleproxy_sz_* readings. Result: The plant device is not updated with new readings.

Is there a way I can map the readings from the 2 ESPs into one generic reading?

e.g. something along the line (fictive):

sensor:
    plant_banana:
         humidity:
             - bleproxy_sz.banana_humidity
             - bleproxy_wz.banana_humidity

and they get updated by whichever sensor sends the data and I could then map the “plant” to those unified readings?

Any help is greatly appreciated. Thanks

Can you add the devices in Xiaomi BLE integrations rather than having to name them in ESPhome so both bleproxies can pass the info back to HA as the same name.

1 Like

Thank you. I will certainly have a look at this too. I experimented today and realized it as follows:

Add “input_numbers” to configuration:

input_number:
  banana_conductivity:
    name: Banana Conductivity
    min: 0
    max: 100000
    step: 1
    unit_of_measurement: µS/cm
  banana_illuminance:
    name: Banana Illuminance
    min: 0
    max: 100000
    step: 1
    unit_of_measurement: lx
  banana_moisture:
    name: Banana Moisture
    min: 0
    max: 100000
    step: 1
    unit_of_measurement: "%"
  banana_temperature:
    name: Banana Temperature
    min: -20
    max: 100
    step: 0.1
    unit_of_measurement: °C

Have some template sensors:

template:
   - sensor:
      - name: "plant_banana_temperature"
        device_class: temperature
        unit_of_measurement: "°C"
        state: '{{ states.input_number.banana_temperature.state }}'
      - name: "plant_banana_illuminance"
        device_class: illuminance
        unit_of_measurement: "lx"
        state: '{{ states.input_number.banana_illuminance.state }}'
      - name: "plant_banana_conductivity"
        device_class: conductivity
        unit_of_measurement: "µS/cm"
        state: '{{ states.input_number.banana_conductivity.state }}'
      - name: "plant_banana_moisture"
        device_class: moisture
        unit_of_measurement: "%"
        state: '{{ states.input_number.banana_moisture.state }}'

and some automations:

- id: '7837483748374'
  alias: Update Banana Illuminance from any ble_proxy
  triggers:
  - platform: state
    entity_id:
    - sensor.bleproxy_sz_banana_illuminance
    - sensor.bleproxy_wz_banana_illuminance
  conditions:
  - condition: template
    value_template: '{{ trigger.to_state.state not in [''unavailable'', ''unknown'']
      }}

      '
  actions:
  - service: input_number.set_value
    target:
      entity_id: input_number.banana_illuminance
    data:
      value: '{{ trigger.to_state.state | int }}'
- id: '7837483748375'
  alias: Update Banana Temperature from any ble_proxy
  triggers:
  - platform: state
    entity_id:
    - sensor.bleproxy_sz_banana_temperature
    - sensor.bleproxy_wz_banana_temperature
  conditions:
  - condition: template
    value_template: '{{ trigger.to_state.state not in [''unavailable'', ''unknown'']
      }}

(as an example)

It works very well, but probably your approach is less effort.

1 Like

Always good to have another way of doing things if needed later.