Restart equivalent action

I have a device that I want to enable fallback hotspot for say 10 minutes at command.

Looking here WiFi Component — ESPHome
I can use this to enable/disable the wifi, which is good enough for me since the device is not ever in range of normal WIFI connection.

on_...:
  then:
    - wifi.disable:


on_...:
  then:
    - wifi.enable:

So I could do:

on_...:
  then:
    - wifi.enable:
    - delay: 10min
    - wifi.disable:

But lets say I command this twice within this 10 minute period how can I make sure it stays on for 10 minutes after the last command?

So what is the equivalent of an HA automation set in restart mode?

Scripts have this functionality:
https://esphome.io/components/script.html

If you’re not familiar with them already, while obviously simple, they open up a lot of options in an incredibly easy way.

2 Likes

That is interesting.
I will have a look at that tomorrow.

Thanks!

It seems that did not work as expected…

script:
  - id: wifi_temp_on
    mode: restart
    then:
      - wifi.enable:
      - delay: 10min
      - wifi.disable:

Will disable the wifi after 10 minutes, but it will not enable the wifi.
The device currently has wifi on when I boot it, but eventually that should be off and only on command should the wifi be on.
But it seems I can’t enable the wifi only disable.

Anyone who has managed to toggle wifi like this?

I tried to replace it with:

script:
  - id: wifi_temp_on
    mode: restart
    then:
      - lambda: WiFi.mode(WIFI_AP);
      - delay: 10min
      - lambda: WiFi.mode(WIFI_OFF);

And this works except it creates a different open AP.
I would expect it to create the AP that is in the yaml but it creates a “default” AP called ESPxxxx.

I’ve used the WiFi enable command before without any issues. In my case, it was tied to a physical switch, not within a script (but that shouldn’t make a difference).