• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

[Q] how to create a Wi-Fi disconnect condition

eyalkn

Lurker
Jan 27, 2014
3
1
Till now I used to be on a cm based rom so I was using cm profiles in a way that when I left work (disconnected from the Wi-Fi there) I raised all volumes and enabled all app notifications. How do I create a condition similar to that using tasker that is based on disconnect from work Wi-Fi? I successfuly created a condition that is based on connect to home Wi-Fi but I can't find how to do the opposite (disconnect).
 
This profile checks to see if it is near either of my WiFi connections. If it is then WiFi is enabled. If it isn't then WiFi is disabled. When I leave the office WiFi is turned off. When I return WiFi is turned back on.

Profile: X
State: Wifi Near [ SSID:TLANET-2.4GHz/TLANET-5GHz MAC:* Capabilities:* Min. Activate Signal Level:5 Channel:0 Toggle Wifi:Off ]
Enter: Anon
A1: WiFi [ Set:On ]
Exit: Anon
A1: WiFi [ Set:Off ]

... Thom
 
  • Like
Reactions: eyalkn
Upvote 0
It sounds like the best way to do what you want is by using an Exit task (as mentioned in Thom's suggestion), which is an action (or set of actions) to be performed when a profile's Context is no longer satisfied.

I'd create a new profile with the Wifi Connected state (you can even specify your work SSID if you like). Then configure the Task with the actions you want (raise volumes, enable all notifications). Once the profile is created, you can long-press on the Task side and select "Move to Exit". Those actions will now be performed as soon as your device disconnects from your work's wifi.
 
  • Like
Reactions: eyalkn
Upvote 0
Maybe someone can share some light on this ...

The approach I documented works. I have it augmented to verbally announce when WiFi is disabled and enabled.

I leave the office and am about 5 miles away and it is 15 minutes since I left the office and it announces the disable.

When I return and am about 200 feet from the office it announces that it is enabled.

Why the delay in the disable?

... Thom
 
Upvote 0
Maybe someone can share some light on this ...

The approach I documented works. I have it augmented to verbally announce when WiFi is disabled and enabled.

I leave the office and am about 5 miles away and it is 15 minutes since I left the office and it announces the disable.

When I return and am about 200 feet from the office it announces that it is enabled.

Why the delay in the disable?

... Thom

I think the issue probably relates to the "wifi near" state - that's running off of cellular network location, so it can drift quite a bit. You may be better off using the AutoLocation plugin to define a geofenced area, and using that to toggle the profile.
 
  • Like
Reactions: Thom and D-U-R-X
Upvote 0
This profile checks to see if it is near either of my WiFi connections. If it is then WiFi is enabled. If it isn't then WiFi is disabled. When I leave the office WiFi is turned off. When I return WiFi is turned back on.

Profile: X
State: Wifi Near [ SSID:TLANET-2.4GHz/TLANET-5GHz MAC:* Capabilities:* Min. Activate Signal Level:5 Channel:0 Toggle Wifi:Off ]
Enter: Anon
A1: WiFi [ Set:On ]
Exit: Anon
A1: WiFi [ Set:Off ]

I have been watching this now for about a month ...

I leave the office and it turns off after 15-20 minutes. It doesn't seem to make any difference where I am (if more than 200 feet from the office) it never disables in less than 15 minutes.

When I return and am about 200 feet from the office it is enabled.

So the disable seems to be on a 15-20 minute cycle and the enable is instantaneous. Is there a way to reduce the timing on the disable?

... Thom
 
Upvote 0
I have been watching this now for about a month ...

I leave the office and it turns off after 15-20 minutes. It doesn't seem to make any difference where I am (if more than 200 feet from the office) it never disables in less than 15 minutes.

When I return and am about 200 feet from the office it is enabled.

So the disable seems to be on a 15-20 minute cycle and the enable is instantaneous. Is there a way to reduce the timing on the disable?

... Thom

Did you try using that AutoLocation plugin by chance? If so, any change?

By the way, I did find a bit of information about how the Wifi-Near context handles its Exit task:
Wifi Near doesn't exit until two consecutive Wifi scans show that the specified Wifi network is no longer near. Using default settings of scanning every 2 minutes when the screen is on, and every 10 minutes when the screen is off, it could take up to 20 minutes for Wifi Near to exit after moving out of range.

Another option may be to break it out into two profiles.

Profile 1:
State: Wifi Near [work SSID]
Enter: Wifi On

Profile 2:
State: Wifi Connected [work SSID]
Exit:
- Wait 30s
- Variable Split: %WIFII
- If %WIFII1 ~ "<<<CONNECTION>>>"
- - Stop
- Else
- - Wifi Off
- End If

This *should* wait 30 seconds after it loses connection to your work Wifi, and check again to make sure it hasn't reconnected (in the event of a brief network blip). If connected, it will exit the task. If not connected, it will turn Wifi off. I haven't tested this, of course, so don't hate me if it doesn't work. It works great in my head though! :D
 
  • Like
Reactions: Thom
Upvote 0
Some excellent ideas there.

I did not try the earlier suggestion. It didn't seem to fit my problem.

With this one, I tried your suggestions. This is the real code ...

Profile: tlaOfficeIn
State: Wifi Near [ SSID:TLANET-2.4GHz/TLANET-5GHz MAC:* Capabilities:* Min. Activate Signal Level:5 Channel:0 Toggle Wifi:Off ]
Enter: tlaWiFiEnabled


Profile: tlaOfficeOut
State: Wifi Connected [ SSID:TLANET-2.4GHz/TLANET-5GHz MAC:* IP:* ]
Exit: Anon
A1: Wait [ MS:0 Seconds:30 Minutes:0 Hours:0 Days:0 ]
A2: Variable Split [ Name:%WIFI Splitter: Delete Base:Off ]
A3: If [ %WIFI1 !~ <<<CONNECTION>>> ]
A4: Perform Task [ Name:tlaWiFiDisabled Stop:Off Priority:5 Parameter 1 (%par1): Parameter 2 (%par2): Return Value Variable: ]
A5: End If


tlaWiFiDisabled
A1: WiFi [ Set:Off ]
A2: Say [ Text:WiFi is disabled Engine:Voice:default:default Stream:5 Pitch:5 Speed:5 Respect Audio Focus:On Continue Task Immediately:On ] If [ %Say_Text ~ enabled ]
A3: Popup [ Title: Text:WiFi
 
Upvote 0
Try using the %WIFII variable (Wifi Info, not a typo ;) ) instead of %WIFI (Wifi Status = On/Off). Not sure that will fix the issue, but it should at least make it more correct ;)

Also, reading a bit at Tasker: Location Without Tears suggests that you may want to use the Toggle Wifi option of the Wifi Near state - otherwise Tasker may not be able to determine that it is near the desired Wifi AP. And, again, I imagine that the Wifi Scan interval will play a large role in how quickly the Profile reacts. I still kind of think that using an alternate means of determining location would likely be more reliable/responsive.
 
Upvote 0
The statement ...
A3: If [ %WIFII1 !~ <<<CONNECTION>>> ]
... should be ...
A3: If [ %WIFII2 !~ CONNECTION]

It seems to me that one of the profiles is interfering with the other and when it is disabled the other works properly. I don't know at this hour how to tweak it and will revert to the old method for the time being.

... Thom
 
  • Like
Reactions: codesplice
Upvote 0
The statement ...
A3: If [ %WIFII1 !~ <<<CONNECTION>>> ]
... should be ...
A3: If [ %WIFII2 !~ CONNECTION]

It seems to me that one of the profiles is interfering with the other and when it is disabled the other works properly. I don't know at this hour how to tweak it and will revert to the old method for the time being.

... Thom

Ah, good catch. I was thinking that the Split would default to using a space as a delimiter, but it seems to treat the "<<<" as a separate word for some reason. I'm not seeing any other glaring errors, but I'm not entirely awake. I'll check back in a bit later :)
 
Upvote 0
I made one change to both Tasks that enable and disable. They now check to see if the state is already set and instead of just setting it again they change the voice message to say "WiFi is still xxxxxx" and do not set it again.

This approach is now working ... it disables after 30 seconds after leaving the signal area. It enables 15 minutes after disabling if I have returned to the signal area.

The code ...

Profile: tlaOfficeDisable
State: Wifi Connected [ SSID:TLANET-2.4GHz/TLANET-5GHz MAC:* IP:* ]
Exit: Anon
A1: Wait [ MS:0 Seconds:30 Minutes:0 Hours:0 Days:0 ]
A2: Variable Split [ Name:%WIFII Splitter: Delete Base:Off ]
A3: Perform Task [ Name:tlaWiFiDisable Stop:Off Priority:5 Parameter 1 (%par1): Parameter 2 (%par2): Return Value Variable: ] If [ %WIFII2 !~ CONNECTION ]
A4: Stop [ With Error:Off Task: ]

Profile: tlaOfficeEnable
State: Wifi Near [ SSID:TLANET-2.4GHz/TLANET-5GHz MAC:* Capabilities:* Min. Activate Signal Level:5 Channel:0 Toggle Wifi:Off ]
Enter: tlaWiFiEnable
A1: If [ %WIFI !~ on ]
A2: WiFi [ Set:On ]
A3: Say [ Text:WiFi is enabled Engine:Voice:default:default Stream:5 Pitch:5 Speed:5 Respect Audio Focus:On Continue Task Immediately:On ] If [ %Say_Text ~ enabled ]
A4: Else
A5: Say [ Text:WiFi is still enabled Engine:Voice:default:default Stream:5 Pitch:5 Speed:5 Respect Audio Focus:On Continue Task Immediately:On ] If [ %Say_Text ~ enabled ]
A6: End If
A7: Popup [ Title: Text:WiFi &#8226; Enabled Background Image: Layout:tlaPopup096 Timeout (Seconds):2 Show Over Keyguard:On ]

tlaWiFiDisable
A1: If [ %WIFI !~ off ]
A2: WiFi [ Set:Off ]
A3: Say [ Text:WiFi is disabled Engine:Voice:default:default Stream:5 Pitch:5 Speed:5 Respect Audio Focus:On Continue Task Immediately:On ] If [ %Say_Text ~ enabled ]
A4: Else
A5: Say [ Text:WiFi is still disabled Engine:Voice:default:default Stream:5 Pitch:5 Speed:5 Respect Audio Focus:On Continue Task Immediately:On ] If [ %Say_Text ~ enabled ]
A6: End If
A7: Popup [ Title: Text:WiFi &#8226; Disabled Background Image: Layout:tlaPopup096 Timeout (Seconds):2 Show Over Keyguard:On ]

tlaWiFiEnable
A1: If [ %WIFI !~ on ]
A2: WiFi [ Set:On ]
A3: Say [ Text:WiFi is enabled Engine:Voice:default:default Stream:5 Pitch:5 Speed:5 Respect Audio Focus:On Continue Task Immediately:On ] If [ %Say_Text ~ enabled ]
A4: Else
A5: Say [ Text:WiFi is still enabled Engine:Voice:default:default Stream:5 Pitch:5 Speed:5 Respect Audio Focus:On Continue Task Immediately:On ] If [ %Say_Text ~ enabled ]
A6: End If
A7: Popup [ Title: Text:WiFi &#8226; Enabled Background Image: Layout:tlaPopup096 Timeout (Seconds):2 Show Over Keyguard:On ] .

This appears to be a Tasker "feature".

... Thom
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones