First I would like to thank for the work in the project. But I’m afraid that I need some help to put it to work.
First I flashed an ESP32 board with the following ESPHome code:
substitutions:
devicename: blegateway # (lower-case) hostname, ap
friendlyname: blegateway # mqtt, sensors.
packages:
device: !include packages/devices/esp32-esp-wroom-32.yaml
base: !include packages/base-esp32.yaml
external_components:
- source: github://myhomeiot/esphome-components
esp32_ble_tracker: # <!---- Is this required?
ble_gateway:
id: blegateway
on_ble_advertise:
then:
homeassistant.event:
event: esphome.on_ble_advertise
data:
packet: !lambda return packet;
binary_sensor:
- platform: homeassistant
id: ble_gateway_discovery
entity_id: binary_sensor.ble_gateway
attribute: discovery
on_state:
then:
lambda: id(blegateway).set_discovery(x);
text_sensor:
- platform: homeassistant
id: ble_gateway_devices
entity_id: binary_sensor.ble_gateway
attribute: devices
on_value:
then:
lambda: id(blegateway).set_devices(x);
switch:
- platform: template
id: switch_ble_gateway_discovery
name: BLE Gateway Discovery
icon: mdi:bluetooth-connect
lambda: return id(blegateway).get_discovery();
turn_on_action: [lambda: id(blegateway).set_discovery(true);]
turn_off_action: [lambda: id(blegateway).set_discovery(false);]
disabled_by_default: true
entity_category: config
Then I added the Bluetooth plugin to HA and left configured like:
Then added a yaml package file with this code:
input_boolean:
settings_ble_gateway:
name: BLE Gateway
icon: mdi:bluetooth
settings_ble_gateway_discovery:
name: BLE Gateway Discovery
icon: mdi:bluetooth-connect
input_text:
settings_ble_gateway_add_device:
name: BLE Gateway Add Device
icon: mdi:bluetooth-connect
initial: ''
template:
- binary_sensor:
- name: BLE Gateway
icon: mdi:bluetooth
state: "{{ is_state('input_boolean.settings_ble_gateway', 'on') }}"
attributes:
discovery: "{{ is_state('input_boolean.settings_ble_gateway_discovery', 'on') }}"
devices: >-
{% set devices = namespace(items = []) %}
{% for s in states | selectattr('entity_id', 'search', '^(device_tracker|sensor).ble_') | map(attribute='entity_id') %}
{% set devices.items = devices.items + [device_id(s)] %}
{% endfor %}
{% set ns = namespace(items = []) %}
{% for s in devices.items | unique %}
{% set ns.items = ns.items + [(device_attr(s, 'identifiers') | first)[1]] %}
{% endfor %}
{{ ns.items | unique | sort | join('') | replace(':', '') ~ (states('input_text.settings_ble_gateway_add_device') | replace(':', '') | trim) if is_state('binary_sensor.ble_gateway', 'on') }}
automation:
- alias: ESPHome BLE Advertise pkg
mode: queued
trigger:
- platform: event
event_type: esphome.on_ble_advertise
action:
- service: ble_monitor.parse_data
data:
packet: '{{ trigger.event.data.packet }}'
#gateway_id: '{{ trigger.event.data.gateway_id }}'
That created three entities:
I really don’t know what they are for. I switched discovery, but nothing happened in the textbox or HA.
I bought 5 LYWSD03MMC, and powered on the first. Activated discovery, but nothing happened. So I looked at the logs and saw the MAC. I added that TO the textbox, I think and then appeared at the BLE integration. I configured the device but left empty the encryption key.
That created this device, with Temp/Hum deactivated:
I activated them but saw no activity, so used the Telink tool as indicated and activated the device and got the key.
But nothing changed. There’s no activity and even in the Gateway log I can’t see nothing.
INFO Successfully connected to esphome-blegateway.local
[20:55:51][D][sensor:125]: 'blegateway_Uptime': Sending state 3.81222 minutes with 0 decimals of accuracy
[20:56:06][D][sensor:125]: 'blegateway_RSSI': Sending state -56.00000 dBm with 0 decimals of accuracy
[20:56:51][D][sensor:125]: 'blegateway_Uptime': Sending state 4.81222 minutes with 0 decimals of accuracy
[20:57:02][I][ota:105]: Boot seems successful, resetting boot loop counter.
[20:57:02][D][esp32.preferences:114]: Saving preferences to flash...
[20:57:02][D][esp32.preferences:131]: NVS data not changed skipping 233825511 len=4
[20:57:03][D][esp32_ble_tracker:217]: Starting scan...
[20:57:03][D][esp32_ble_tracker:726]: Found device 44:1C:A8:6E:5F:9E RSSI=-83
[20:57:03][D][esp32_ble_tracker:747]: Address Type: PUBLIC
[20:57:15][D][esp32_ble_tracker:726]: Found device A4:C1:38:AC:4B:E9 RSSI=-54
[20:57:15][D][esp32_ble_tracker:747]: Address Type: PUBLIC
[20:57:15][D][esp32_ble_tracker:749]: Name: 'LYWSD03MMC'
[20:57:51][D][sensor:125]: 'blegateway_Uptime': Sending state 5.81218 minutes with 0 decimals of accuracy
[20:58:06][D][sensor:125]: 'blegateway_RSSI': Sending state -63.00000 dBm with 0 decimals of accuracy
[20:58:51][D][sensor:125]: 'blegateway_Uptime': Sending state 6.81218 minutes with 0 decimals of accuracy
Can you help me to make it work, please?
The Telink tool showed Temp and Hum values, along with The token and key, but the id was empty.
Does the token has to be put somewhere?
Does the mac has to be altered to be put somewhere?
Thanks in advance.
Edit: Is still required to hard-code the sensor MACs somewhere? I only added the shown code, but I can see something related to ble_monitor
here that I don’t know if it’s required if using the BLE integration.
The documentation is not clear to me as showing the required or not required steps and their order.