本帖最后由 silas3082 于 2022-9-24 09:59 编辑
之前发表了个"电动车靠近开锁,离开锁车思路"帖子,打算用esp32蓝牙功能扫描手环或者手机蓝牙实现电动车自动开锁。进过几天的实践,发现esp32直接扫描不到手机蓝牙,手环蓝牙偶尔能扫描到(我的是小米4nfc版),大多数时候扫描不到,很不稳定,搜索了半天也没找到好的解决方法(有坛友提出用beacon,我也研究了一下,没怎么深入,不知道具体怎么实现,没采用)
偶然看esphome官网时候看到可以利用wifi进行相关自动化,比如wifi连接上就执行……或者wifi信号变化就……,故打算手机开热点,8266连接手机wifi,信号在-30到-120的时候就的时候打开电动车电门,超出范围或者wifi断开就关闭,从而实现"电动车靠近开锁,离开锁车"
这里我在D1控制电门继电器,增加了D2,D3来控制一个led灯和单位门禁,不需要的直接可以忽略,直接用Switch D1和sensor那段就行。
esphome:
name: wifi2
esp8266:
board: nodemcuv2
# Enable logging
logger:
# Enable Home Assistant API
api:
reboot_timeout: 0s
ota:
password: "*********************"
wifi:
ssid: "你自己的热点"
password: "热点密码"
reboot_timeout: 0s
# Enable fallback hotspot (captive portal) in case wifi connection fails
captive_portal:
switch:
- platform: gpio
pin: D1
name: "dianmen" ##关锁状态输出电压0V,开锁状态输出电压与电池电压相同
id: dianmen
restore_mode: ALWAYS_OFF
- platform: gpio
pin: D2
name: "LED"
id: led
restore_mode: ALWAYS_OFF
remote_transmitter:
pin: D3
carrier_duty_percent: 50%
sensor:
- platform: wifi_signal
name: "WiFi Signal Sensor"
update_interval: 1s
on_value_range:
- below: -120
then:
- switch.turn_off: dianmen
- above: -120
below: -10
then:
- switch.turn_on: dianmen
- above: -1
then:
- switch.turn_off: dianmen
binary_sensor:
- platform: gpio
pin:
number: D4
mode:
input: true
pullup: true
name: "menjinkaiguan"
id: menjinkaiguan
device_class: opening
filters:
- delayed_on_off: 100ms #这里一定要加这个这个起到滤波的作用。
on_press:
- switch.turn_on: led
- repeat:
count: 20
then:
- remote_transmitter.transmit_rc_switch_raw:
code: '***********************'
protocol: 1
repeat:
wait_time: 0s
times: 10
- delay: 1s
- switch.turn_off: led
|