Advertisement
GrzegorzM

ESP32 Bluetooth with Passive BLE monitor

Oct 1st, 2022 (edited)
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 3.40 KB | None | 0 0
  1. substitutions:
  2.   mac_address_jukka_salon: 'C4:7C:8D:6C:5B:A0' # Jukka Salon
  3.   mac_address_dracena_salon: 'C4:7C:8D:6C:85:1A' # Dracena Salon
  4.   mac_address_zegarek_salon: 'E7:2E:01:71:B9:21' # Zegarek Salon (LYWSD02MMC)
  5.  
  6. esphome:
  7.   name: 'esp32-dol'
  8.   platform: ESP32
  9.   board: esp-wrover-kit
  10.  
  11. wifi:
  12.   ssid: !secret wifi_ssid
  13.   password: !secret wifi_password
  14.  
  15. # Enable fallback hotspot (captive portal) in case wifi connection fails
  16.   ap:
  17.     ssid: "Esp32 Dol Fallback Hotspot"
  18.     password: !secret ap_wifi_password
  19.  
  20. captive_portal:
  21. # Enable logging
  22. logger:
  23. # Enable Home Assistant API
  24. api:
  25.   password: !secret api_password
  26.  
  27. ota:
  28.   password: !secret ota_password
  29.  
  30. external_components:
  31.   - source: github://myhomeiot/esphome-components
  32.  
  33. # Enable Bluetooth scanning for this ESP32
  34. esp32_ble_tracker:
  35. # PASSIVE
  36. ble_gateway:
  37.   devices:
  38.     - mac_address: ${mac_address_jukka_salon} # Jukka Salon
  39.     - mac_address: ${mac_address_dracena_salon} # Dracaena Salon
  40.     - mac_address: ${mac_address_zegarek_salon} # Zegarek Salon
  41.   on_ble_advertise:
  42.     then:
  43.       homeassistant.service:
  44.         service: ble_monitor.parse_data
  45.         data:
  46.           packet: !lambda return packet;
  47.  
  48. # ACTIVE
  49. # Flower Care (HHCCJCY01) nie raportuje stanu baterii, co 48h nawiązujemy aktywne połączenie w celu odczytania stanu
  50. # Odczytany stan wysyłamy do Passibe BLE Monitor'a
  51. myhomeiot_ble_host:
  52. myhomeiot_ble_client:
  53.   - mac_address: ${mac_address_jukka_salon}
  54.     service_uuid: '1204'
  55.     characteristic_uuid: '1A02'
  56.     update_interval: 48h
  57.     on_value:
  58.       then:
  59.         homeassistant.service:
  60.           service: ble_monitor.parse_data
  61.           data:
  62.             packet: !lambda |-
  63.               if (x.size() < 2)
  64.               {
  65.                 ESP_LOGE("myhomeiot_ble_client", "payload has wrong size (%d)", x.size());
  66.                 return "";
  67.               };
  68.               ESP_LOGI("myhomeiot_ble_client", "Battery (%d%%), firmware (%s)", x[0], std::string(x.begin(), x.end()).substr(2).c_str());
  69.               char buffer[70 + 1];
  70.               const uint8_t *remote_bda = xthis.remote_bda();
  71.               snprintf(buffer, sizeof(buffer), "043E2002010000%02X%02X%02X%02X%02X%02X14020106030295FE0C1695FE41209800000A1001%02X00",
  72.                 remote_bda[5], remote_bda[4], remote_bda[3], remote_bda[2], remote_bda[1], remote_bda[0], x[0]);
  73.               return std::string(buffer).c_str();
  74.   - mac_address: ${mac_address_dracena_salon}
  75.     service_uuid: '1204'
  76.     characteristic_uuid: '1A02'
  77.     update_interval: 48h
  78.     on_value:
  79.       then:
  80.         homeassistant.service:
  81.           service: ble_monitor.parse_data
  82.           data:
  83.             packet: !lambda |-
  84.               if (x.size() < 2)
  85.               {
  86.                 ESP_LOGE("myhomeiot_ble_client", "payload has wrong size (%d)", x.size());
  87.                 return "";
  88.               };
  89.               ESP_LOGI("myhomeiot_ble_client", "Battery (%d%%), firmware (%s)", x[0], std::string(x.begin(), x.end()).substr(2).c_str());
  90.               char buffer[70 + 1];
  91.               const uint8_t *remote_bda = xthis.remote_bda();
  92.               snprintf(buffer, sizeof(buffer), "043E2002010000%02X%02X%02X%02X%02X%02X14020106030295FE0C1695FE41209800000A1001%02X00",
  93.                 remote_bda[5], remote_bda[4], remote_bda[3], remote_bda[2], remote_bda[1], remote_bda[0], x[0]);
  94.               return std::string(buffer).c_str();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement