Hi,
I am trying to readout once a day the battery level of a BLE tag I am using for presence detection.
To read out the value I connect the ble client once a day. I would like to keep the battery percentage visible in HA. Now the sensor always becomes unavailable.
Is there any way to prevent ESPhome to send the unavailable flag?
My used code:
esphome:
name: garage
friendly_name: Garage
esp32:
variant: esp32c3
framework:
type: arduino
esp32_ble_tracker:
id: ble_tracker
scan_parameters:
continuous: false
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "**********"
ota:
- platform: esphome
password: "********"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Garage Fallback Hotspot"
password: "*********"
on_connect:
- esp32_ble_tracker.start_scan:
continuous: true
on_disconnect:
- esp32_ble_tracker.stop_scan:
captive_portal:
ble_client:
- mac_address: "00:00:00:00:00:00"
id: AutoTracker
auto_connect: False
on_connect:
then:
- delay: 1ms
- lambda: |-
id(BatteryLevel).update();
binary_sensor:
- platform: ble_presence
mac_address: 00:00:00:00:00:00
name: "Auto Tracker"
min_rssi: -80dB
timeout:
seconds: 60
sensor:
- platform: ble_client
id: BatteryLevel
ble_client_id: AutoTracker
type: characteristic
update_interval: never
notify: False
name: "Autotracker Battery Level"
service_uuid: '180f'
characteristic_uuid: '2a19'
unit_of_measurement: "%"
device_class: battery
time:
- platform: sntp
on_time:
seconds: 0
minutes: 0
hours: 0
then:
- ble_client.connect: AutoTracker
- delay: 10 seconds
- ble_client.disconnect: AutoTracker`Preformatted text`