『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
楼主: silang521

[已解决] 请教关于esp32c3接入home assistant蓝牙追踪传感器数量少

[复制链接]

32

主题

285

帖子

1817

积分

金牌会员

Rank: 6Rank: 6

积分
1817
金钱
1532
HASS币
0
发表于 2022-11-23 23:30:29 | 显示全部楼层
silang521 发表于 2022-11-23 23:26
那不能麻烦你测试一下,删除双引号重新刷固件,删除ha的esphome,重新连接看看是不是两个 ...

刚刚试了下,还是两个
回复

使用道具 举报

6

主题

257

帖子

1453

积分

金牌会员

Rank: 6Rank: 6

积分
1453
金钱
1196
HASS币
0
 楼主| 发表于 2022-11-23 23:30:47 | 显示全部楼层
justion 发表于 2022-11-23 23:24
好像不是,我没加引号的时候也能显示两个

我的不知道什么原因一直都是一个实体
回复

使用道具 举报

6

主题

257

帖子

1453

积分

金牌会员

Rank: 6Rank: 6

积分
1453
金钱
1196
HASS币
0
 楼主| 发表于 2022-11-23 23:31:54 | 显示全部楼层
justion 发表于 2022-11-23 23:30
刚刚试了下,还是两个

好的 感谢,你的完整的代码能不能给我借鉴一下
回复

使用道具 举报

32

主题

285

帖子

1817

积分

金牌会员

Rank: 6Rank: 6

积分
1817
金钱
1532
HASS币
0
发表于 2022-11-23 23:35:53 | 显示全部楼层
silang521 发表于 2022-11-23 23:31
好的 感谢,你的完整的代码能不能给我借鉴一下

我用的是宇合的esp32,之前一直在吃灰,今天看到有人也在用,所以拿出来又试试看,算是刷进去了。
substitutions:
  # Name the device and it's entities
  device: ble_gateway
  device_name: blegateway1

esphome:
  name: $device_name
  comment: $device
  platformio_options:
    board_build.flash_mode: dio

esp32:
  board: esp32-c3-devkitm-1
  variant: esp32c3
  framework:
    type: arduino
    version: 2.0.2
    platform_version: https://github.com/tasmota/platform-espressif32/releases/download/v2.0.2.3/platform-espressif32-2.0.2.3.zip

external_components:
  - source: github://myhomeiot/esphome-components

esp32_ble_tracker:
  scan_parameters:
   interval: 120ms
   window: 100ms
# Enable logging
logger:

# Enable Home Assistant API
api:
  reboot_timeout: 1h

ota:
  password: !secret ota_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:    
    static_ip: 192.168.1.118    
    gateway: 192.168.1.1    
    subnet: 255.255.255.0

  # Enable fallback hotspot in case wifi connection fails
  ap:
    ssid: "$device_name Fallback Hotspot"
    password: !secret ap_password

ble_gateway:
  id: $device_name
  # devices:
  #   - mac_address: 01:23:45:67:89:AB
  #   - mac_address: !secret lywsd03mmc_mac
  on_ble_advertise:
    then:
      - homeassistant.service:
          service: ble_monitor.parse_data
          data:
            packet: !lambda return packet;
            gateway_id: $device_name
      - 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($device_name).set_discovery(x);
  - platform: ble_presence
    id: S21_Ultra
    mac_address: C8:BD:69:D5:87:46
    name: "S21 Ultra(BT)"
  - platform: ble_presence
    id: Galaxy_Watch4
    mac_address: 60:3A:AF:E1:20:40
    name: "Galaxy Watch4 Classic (4LQJ)"


text_sensor:
  - platform: homeassistant
    id: ble_gateway_devices
    entity_id: binary_sensor.ble_gateway
    attribute: devices
    on_value:
      then:
        lambda: id($device_name).set_devices(x);
  # IP address of device. Not really needed for HA (as HA already knows it), but for showing on the display during startup. The startup screen will leave on if no instance connects to the API.
  - platform: wifi_info
    ip_address:
      name: $device_name IP address
      id: ip_address
  # ESPHome version used to compile the app
  - platform: version
    name: $device_name ESPHome Version

sensor:
  # WiFi signals strength sensor
  - platform: wifi_signal
    name: $device_name WiFi Signal Sensor
    update_interval: 60s


评分

参与人数 1金钱 +5 收起 理由
silang521 + 5 膜拜大神!

查看全部评分

回复

使用道具 举报

6

主题

257

帖子

1453

积分

金牌会员

Rank: 6Rank: 6

积分
1453
金钱
1196
HASS币
0
 楼主| 发表于 2022-11-23 23:37:23 | 显示全部楼层
justion 发表于 2022-11-23 23:35
我用的是宇合的esp32,之前一直在吃灰,今天看到有人也在用,所以拿出来又试试看,算是刷进去了。

感谢 我试试
回复

使用道具 举报

6

主题

257

帖子

1453

积分

金牌会员

Rank: 6Rank: 6

积分
1453
金钱
1196
HASS币
0
 楼主| 发表于 2022-11-23 23:43:02 | 显示全部楼层
justion 发表于 2022-11-23 23:35
我用的是宇合的esp32,之前一直在吃灰,今天看到有人也在用,所以拿出来又试试看,算是刷进去了。

请教一下,你是不是ha的配置configuration.yaml文件还增加了input_boolean:
  ha_started:
    initial: false
  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 Add Device
        state: "{{ (state_attr('binary_sensor.ble_gateway_add_device', 'mac_address')) }}"
        availability: "{{ is_state('input_boolean.ha_started', 'on') }}"
        attributes:
          mac_address: "{{ states('input_text.settings_ble_gateway_add_device') | replace(':', '') | trim }}"
  - binary_sensor:
      - name: BLE Gateway
        icon: mdi:bluetooth
        state: "{{ is_state('input_boolean.settings_ble_gateway', 'on') }}"
        availability: "{{ is_state('input_boolean.ha_started', 'on') }}"
        attributes:
          discovery: "{{ is_state('input_boolean.settings_ble_gateway_discovery', 'on') }}"
          devices: "{{ states | selectattr('entity_id', 'search', '^(device_tracker||(binary_)?sensor).ble_') | selectattr('attributes.mac_address', 'defined') | map(attribute='attributes.mac_address') | unique | sort | join('') | replace(':', '') if is_state('binary_sensor.ble_gateway', 'on') }}"
回复

使用道具 举报

6

主题

257

帖子

1453

积分

金牌会员

Rank: 6Rank: 6

积分
1453
金钱
1196
HASS币
0
 楼主| 发表于 2022-11-23 23:46:20 | 显示全部楼层
@justion 我已经无语啦还是不行你的显示我的就显示一个另外一个还是不显示
4.png
回复

使用道具 举报

6

主题

257

帖子

1453

积分

金牌会员

Rank: 6Rank: 6

积分
1453
金钱
1196
HASS币
0
 楼主| 发表于 2022-11-23 23:49:10 | 显示全部楼层
justion 发表于 2022-11-23 23:35
我用的是宇合的esp32,之前一直在吃灰,今天看到有人也在用,所以拿出来又试试看,算是刷进去了。

可以啦,原因找到啦,name只能用英文或者拼音,中文有bug
回复

使用道具 举报

32

主题

285

帖子

1817

积分

金牌会员

Rank: 6Rank: 6

积分
1817
金钱
1532
HASS币
0
发表于 2022-11-24 09:54:40 | 显示全部楼层
silang521 发表于 2022-11-23 23:49
可以啦,原因找到啦,name只能用英文或者拼音,中文有bug

找到了就好,唉我的还是不能没有状态变化,人都麻了,不知道问题出在哪里
帮我看下esphome的日志对不对
INFO Reading configuration /config/esphome/blegateway.yaml...
WARNING The selected Arduino framework version is not the recommended one. If there are connectivity or build issues please remove the manual version.
WARNING The selected Arduino framework version is not the recommended one. If there are connectivity or build issues please remove the manual version.
INFO Starting log output from 192.168.1.118 using esphome API
INFO Successfully connected to 192.168.1.118
[09:51:56][I][app:102]: ESPHome version 2022.11.2 compiled on Nov 24 2022, 00:39:09
[09:51:56][C][wifi:504]: WiFi:
[09:51:56][C][wifi:362]:   Local MAC: 60:55:F9:74:3C:34
[09:51:56][C][wifi:363]:   SSID: 'OpenWrt'[redacted]
[09:51:56][C][wifi:364]:   IP Address: 192.168.1.118
[09:51:56][C][wifi:366]:   BSSID: 10:44:00:48:26:28[redacted]
[09:51:56][C][wifi:367]:   Hostname: 'blegateway1'
[09:51:56][C][wifi:369]:   Signal strength: -24 dB ▂▄▆█
[09:51:56][C][wifi:373]:   Channel: 6
[09:51:56][C][wifi:374]:   Subnet: 255.255.255.0
[09:51:56][C][wifi:375]:   Gateway: 192.168.1.1
[09:51:56][C][wifi:376]:   DNS1: 0.0.0.0
[09:51:56][C][wifi:377]:   DNS2: 0.0.0.0
[09:51:56][C][logger:293]: Logger:
[09:51:56][C][logger:294]:   Level: DEBUG
[09:51:56][C][logger:295]:   Log Baud Rate: 115200
[09:51:56][C][logger:296]:   Hardware UART: UART0
[09:51:56][C][ble_gateway:055]: BLE Gateway: Discovery NO, 2 device(s) configured:
[09:51:56][C][ble_gateway:057]:   MAC address: A4:C1:38:EC:AA:60  #这个是小米门磁
[09:51:56][C][ble_gateway:057]:   MAC address: E4:AA:EC:5F:71:E5  #这个是温湿度计
[09:51:56][C][ble_presence:011]: BLE Presence 'S21 Ultra(BT)' #这个是需要判断是在家的手机
[09:51:56][C][ble_presence:011]: BLE Presence 'Galaxy Watch4 Classic (4LQJ)'  #这个是需要判断是在家的手表
[09:51:56][C][version.text_sensor:021]: Version Text Sensor 'blegateway1 ESPHome Version'
[09:51:56][C][version.text_sensor:021]:   Icon: 'mdi:new-box'
[09:51:56][C][esp32_ble_tracker:796]: BLE Tracker:
[09:51:56][C][esp32_ble_tracker:797]:   Scan Duration: 300 s
[09:51:56][C][esp32_ble_tracker:798]:   Scan Interval: 120.0 ms
[09:51:56][C][esp32_ble_tracker:799]:   Scan Window: 100.0 ms
[09:51:56][C][esp32_ble_tracker:800]:   Scan Type: ACTIVE
[09:51:56][C][esp32_ble_tracker:801]:   Continuous Scanning: True
[09:51:56][C][mdns:103]: mDNS:
[09:51:56][C][mdns:104]:   Hostname: blegateway1
[09:51:56][C][ota:093]: Over-The-Air Updates:
[09:51:56][C][ota:094]:   Address: 192.168.1.118:3232
[09:51:56][C][ota:097]:   Using Password.
[09:51:56][C][api:138]: API Server:
[09:51:56][C][api:139]:   Address: 192.168.1.118:6053
[09:51:56][C][api:143]:   Using noise encryption: NO
[09:51:56][C][homeassistant.binary_sensor:039]: Homeassistant Binary Sensor 'ble_gateway_discovery'
[09:51:56][C][homeassistant.binary_sensor:040]:   Entity ID: 'binary_sensor.ble_gateway'
[09:51:56][C][homeassistant.binary_sensor:042]:   Attribute: 'discovery'
[09:51:56][C][wifi_info:009]: WifiInfo IPAddress 'blegateway1 IP address'
[09:51:56][C][wifi_signal.sensor:009]: WiFi Signal 'blegateway1 WiFi Signal Sensor'
[09:51:56][C][wifi_signal.sensor:009]:   Device Class: 'signal_strength'
[09:51:56][C][wifi_signal.sensor:009]:   State Class: 'measurement'
[09:51:56][C][wifi_signal.sensor:009]:   Unit of Measurement: 'dBm'
[09:51:56][C][wifi_signal.sensor:009]:   Accuracy Decimals: 0
[09:51:56][C][homeassistant.text_sensor:023]: Homeassistant Text Sensor 'ble_gateway_devices'
[09:51:56][C][homeassistant.text_sensor:024]:   Entity ID: 'binary_sensor.ble_gateway'
[09:51:56][C][homeassistant.text_sensor:026]:   Attribute: 'devices'
[09:51:57][D][ble_gateway:063]: [A4:C1:38:EC:AA:60] Packet 043E2B0201000060AAEC38C1A41F12161A1860AAEC38C1A40C08CC1AE60A41F60F0B094154435F454341413630CB
[09:52:07][D][ble_gateway:063]: [A4:C1:38:EC:AA:60] Packet 043E2B0201000060AAEC38C1A41F12161A1860AAEC38C1A40C08CC1AE60A41F60F0B094154435F454341413630CB
[09:52:12][D][ble_gateway:063]: [A4:C1:38:EC:AA:60] Packet 043E2B0201000060AAEC38C1A41F12161A1860AAEC38C1A40C08CD1AEA0A42F70F0B094154435F454341413630CB
[09:52:16][D][sensor:127]: 'blegateway1 WiFi Signal Sensor': Sending state -23.00000 dBm with 0 decimals of accuracy
[09:52:17][D][ble_gateway:063]: [A4:C1:38:EC:AA:60] Packet 043E2B0201000060AAEC38C1A41F12161A1860AAEC38C1A40C08CD1AEA0A42F70F0B094154435F454341413630CB
[09:52:19][D][esp32_ble_tracker:812]: Found device F1:4D:CF:5E:3E:F1 RSSI=-95
[09:52:19][D][esp32_ble_tracker:833]:   Address Type: RANDOM
[09:52:27][D][ble_gateway:063]: [A4:C1:38:EC:AA:60] Packet 043E2B0201000060AAEC38C1A41F12161A1860AAEC38C1A40C08CD1AEA0A42F70F0B094154435F454341413630CD
[09:52:32][D][ble_gateway:063]: [A4:C1:38:EC:AA:60] Packet 043E2B0201000060AAEC38C1A41F12161A1860AAEC38C1A40B08CD1AE30A41F80F0B094154435F454341413630CE


回复

使用道具 举报

32

主题

285

帖子

1817

积分

金牌会员

Rank: 6Rank: 6

积分
1817
金钱
1532
HASS币
0
发表于 2022-11-24 09:56:15 | 显示全部楼层
Nchyn 发表于 2022-11-23 23:21
esphome响应速度比较慢,大概得数分钟才能显示断开
rssi不开主动扫描的话更新频率与设备主动广播频率有关 ...

并不是这个愿意,我已经放了一个晚上了,还是没有任何变化
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-24 13:59 , Processed in 0.072694 second(s), 33 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表