Manually entering captive portal

In the documentation for the wifi component there is the setting for ap_timeout. Which states "

That last bit is in which I’m interested. Instead of defaulting to an AP which everybody can access when I reboot my access point, I would like to be able to trigger that from software. For example by holding the button. But even though the documentation states it should be an option, I still have not found a way to do it!

A Factory Reset Switch would trigger the captive portal but it does wayyyyy more. I would just like to manually enter the AP-mode with captive portal. Anybody any idea?

Yes, hard to see the way straight off. Perhaps using

https://esphome.io/components/wifi.html#wifi-enable-action

The - wifi.enable: did not work for me.
I have got it to work with this:

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

But this enables the default ESP WIFI (Not ESP-Home WIFI) without password

Thank you for the help both! You answers help me to confirm it is indeed an oversight in ESPHome :smiley:

@Hellis81 I first tried to use the actions directly in a template button. That only resulted in the device becoming ‘unavailable’ in HA for a split second. After which I made the same script and used that in the template button. That indeed results in an AP (ESP_xxxxxx) without password. But I’m not able to connect to it. Can you connect?

Yes I can connect to it.
You need to open 192.168.4.1 in the browser

I’ll give it a try in the coming days. But I wasn’t even able to connect to the AP :confused:

Did you test with a ESP32 or ESP8266?

I have tried on a ESP32 S2.
Have not tried on the S3 yet but I will probably try it tomorrow.

Can you kindly post the exact code that you have used to achieve “launching a cacptive portal by a button press during boot”. i’m looking for this from a long time.
my equipments are getting restarted quite ofter due to a poor wifi network.

I don’t use a button.
But here is how you run a script.
https://esphome.io/components/script.html#script-execute-action
So just add this line where your button is

Hi Hellis,
Many thanks for quick reply.
you mean place this code under button?

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

Could you kindly confirm.

also, is the IP “192.168.4.1” fixed? or is it possible to give any name for this. anyways i will also figure this out.

also, if you can share what is your implementation strategy instead of button. if it is efficient than my strategy i will also use the same.
Thank you.

You can place that code wherever you want but this is just the script itself.
I
You need to run the script where your button is with the syntax I linked to.

Yes the IP is fixed

Hi I’m using ESP8266 device.

with following code.

script:
  - id: activate_wifi_fallback
    mode: restart
    then:
      - logger.log: "in AP mode"
      - delay: 5s
      - lambda: WiFi.mode(WIFI_AP);
      - delay: 10min
      - logger.log: "AP mode off"
      - lambda: WiFi.mode(WIFI_OFF);

after button press i can see the logger.log message in “AP mode”.
but
it results in an AP (ESP_xxxxxx) without password. i’ve connected to PC / phone.
and when i enter 192.168.4.1 (or) 192.168.4.2 it refuses to connect.
any help here please?

My work laptop also refuses connection but my phone works.
Not sure where the issue is

Hi,

I’ve used the solution described in following post. that is what i was looking for somehow.
link here