klenaers
(Kristof)
July 11, 2020, 3:00pm
1
Hi,
I want to make a sleep training-clock for my daughter and want to check 1 or 2 times a day for the hour when the alarm should go off. Because it’s in the bedroom, I want to disable the wifi for the most of the time. The internal clock should stay working so that’s why no deep sleep is wanted.
’
I tried with following code every
interval:
- interval: 15s
then:
- lambda: |-
ESP_LOGD("main", "Wifi turned off");
WiFi.disconnect();
delay(1000);
WiFi.mode(WIFI_OFF);
WiFi.forceSleepBegin();
delay(100);
This works but every time this happens:
[16:54:59][D][main:205]: Wifi turned off
[16:54:59][W][wifi_esp8266:394]: Event: Disconnected ssid=‘’ bssid=B4:FB:E4:91:3D:15 reason=‘Association Leave’
[16:55:00][W][wifi:100]: WiFi Connection lost… Reconnecting…
[16:55:00][W][wifi:495]: Restarting WiFi adapter…
[16:55:00][I][wifi:194]: WiFi Connecting to ‘’…
[16:55:00][W][wifi_esp8266:191]: wifi_apply_hostname_(clock_test): lwIP error -16 on interface st (index 0)
And the wifi connects again.
Has somebody an idea how to tackle this problem? Of where I can look for the solution?
nickrout
(Nick Rout)
July 11, 2020, 10:04pm
2
Esphome is dependent on wifi, unless in deep sleep.
klenaers
(Kristof)
July 12, 2020, 8:57am
3
Thank you for the feedback. It did me think and … .
I’ve found following. When I go for a short time in deep sleep with WAKE_RF_DISABLED then the wifi is disabled until I do a new deep sleep with WAKE_RF_DEFAULT.
binary_sensor:
- platform: gpio
pin:
number: D2
inverted: yes
mode: INPUT_PULLUP
name: "Turn off Wifi"
on_click:
then:
lambda: |-
ESP_LOGD("main", "Wifi turned off");
ESP.deepSleep(10, WAKE_RF_DISABLED);
yield();
WiFi.mode(WIFI_OFF);
WiFi.forceSleepBegin();
yield();
- platform: gpio
pin:
number: D3
inverted: yes
mode: INPUT_PULLUP
name: "Turn on Wifi"
on_click:
then:
lambda: |-
ESP_LOGD("main", "Wifi turned on");
ESP.deepSleep(10, WAKE_RF_DEFAULT );
yield();
WiFi.mode(WIFI_STA);
yield();
Also important is to disable power_save_mode
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_pass
**#power_save_mode: HIGH**
fast_connect: true
reboot_timeout: 0s
output_power: 10
Esphome will keep trying to connect to the wifi but the wifi-chip is disabled.
[10:27:27][I][wifi:194]: WiFi Connecting to ‘’…
[10:27:29][W][wifi_esp8266:391]: Event: Disconnected ssid=‘WLan’ reason=‘Probe Request Unsuccessful’
[10:27:29][W][wifi:458]: Error while connecting to network.
[10:27:29][W][wifi:495]: Restarting WiFi adapter…
[10:27:30][I][wifi:194]: WiFi Connecting to ‘’…
I’ll do some further testing and see if this works for my project.
nickrout
(Nick Rout)
July 12, 2020, 7:27pm
4
For heaven’s sake, post your code properly. Three backticks before and after the code.
klenaers
(Kristof)
July 12, 2020, 8:26pm
5
Better this way? My first time … .
nickrout
(Nick Rout)
July 12, 2020, 11:29pm
6
That looks better
I don’t know why you want to work around deep sleep though.
Are you scared your daughter’s brain is going to be fried or something?
Thanks Kristof, for sharing this code!
I have a similar need - I want to save battery power.
I have a PIR sensor that wakes up the ESP from deep sleep but I don’t want to activate WIFI on every wakeup, but only once in a while.
I’ll give it a try
nickrout
(Nick Rout)
June 15, 2023, 10:05am
8
Necro post! But co-incidentally I saw this today
j_d
(JD)
June 15, 2023, 11:11am
9
and if anyone is wondering what that means. It’s a little bit hidden.
esphome:dev
← esphome:ashmckenzie/allow-wifi-disable-enable
opened 07:32AM - 12 May 23 UTC
Follow-on from and closes #1249 as the original fork has been deleted.
# What… does this implement/fix?
```yaml
wifi:
enable_on_boot: false # new config option
on_...:
- if:
condition: wifi.enabled # new condition
then:
- wifi.disable: # new action
else:
- wifi.enable: # new action
```
## Types of changes
- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Other
**Related issue or feature (if applicable):** fixes <link to issue>
**Pull request in [esphome-docs](https://github.com/esphome/esphome-docs) with documentation (if applicable):** esphome/esphome-docs#2958
## Test Environment
- [ ] ESP32
- [ ] ESP32 IDF
- [ ] ESP8266
- [ ] RP2040
## Example entry for `config.yaml`:
<!--
Supplying a configuration snippet, makes it easier for a maintainer to test
your PR. Furthermore, for new integrations, it gives an impression of how
the configuration would look like.
Note: Remove this section if this PR does not have an example entry.
-->
```yaml
# Example config.yaml
```
## Checklist:
- [ ] The code change is tested and works locally.
- [ ] Tests have been added to verify that the new code works (under `tests/` folder).
If user exposed functionality or configuration variables are added/changed:
- [ ] Documentation added/updated in [esphome-docs](https://github.com/esphome/esphome-docs).
There is a new feature in the next release to enable or disable WiFi.
nickrout
(Nick Rout)
June 15, 2023, 8:13pm
10
yeah maybe I over assumed on reading ability