不能用wifi.disable,他会关闭整个射频模块。
当前关闭wifi但是保留espnow的方法,比较简单的是:
1、配置wifi sta 开机不启动
wifi:
enable_on_boot: false
2. 使用一个模板开关和开机脚本来控制wifi sta 行为
switch:
- platform: template #wifi开关
id: wifi_enable_sw_template
optimistic: true
restore_mode: RESTORE_DEFAULT_ON
on_turn_on:
- if:
condition:
not:
- wifi.enabled:
then:
- wifi.enable:
on_turn_off:
- if:
condition:
and:
- lambda: |-
return id(system_boot_completed);
- wifi.enabled:
then:
- delay: 2s
- lambda: |-
App.safe_reboot();
esphome:
on_boot:
- priority: -100
then:
- delay: 2s
- if:
condition:
- switch.is_on: wifi_enable_sw_template
then:
- wifi.enable:
- lambda: |-
ESP_LOGI("wifi_control", "reboot with WiFi enabled");
- lambda: |-
id(system_boot_completed) = true;
globals:
- id: system_boot_completed
type: bool
restore_value: no
initial_value: "false"
|