1. Download our Official Android App: Forums for Android!

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

Discussion in 'Android Apps & Games' started by eyalkn, Jan 27, 2014.

  1. eyalkn

    eyalkn Lurker
    Thread Starter
    Rank:
    None
    Points:
    6
    Posts:
    3
    Joined:
    Jan 27, 2014

    Jan 27, 2014
    3
    1
    6
    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).
     

    Advertisement

  2. D-U-R-X

    D-U-R-X turbo drinker
    Rank:
    None
    Points:
    1,343
    Posts:
    16,881
    Joined:
    Apr 20, 2011

    Apr 20, 2011
    16,881
    7,193
    1,343
    Work to live, not the other way round!!
    Sheffield, South Yorkshire
    Hello, eyalkin, welcome to Android Forums! :)

    When you create the state "WiFi connected", there is an "Invert" tick box at the bottom right, which makes it "WiFi Not Connected" - should be what you're after :D
     
    eyalkn likes this.
  3. Thom

    Thom  
    VIP Member
    Rank:
     #22
    Points:
    1,318
    Posts:
    11,920
    Joined:
    Feb 16, 2011

    Feb 16, 2011
    11,920
    4,920
    1,318
    Male
    Software Developer
    Keene, NH USA
    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
     
    eyalkn likes this.
  4. codesplice

    codesplice Elite Recognized Moderator
    Moderator
    Rank:
     #13
    Points:
    1,563
    Posts:
    8,718
    Joined:
    Oct 29, 2013

    Oct 29, 2013
    8,718
    10,101
    1,563
    Male
    SysAdmin
    Huntsville, AL
    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.
     
    eyalkn likes this.
  5. eyalkn

    eyalkn Lurker
    Thread Starter
    Rank:
    None
    Points:
    6
    Posts:
    3
    Joined:
    Jan 27, 2014

    Jan 27, 2014
    3
    1
    6
    Thank you all, I did try the exit method and the invert and non of them work. Will try again today and I can always buy the autolocation app.
     
  6. Thom

    Thom  
    VIP Member
    Rank:
     #22
    Points:
    1,318
    Posts:
    11,920
    Joined:
    Feb 16, 2011

    Feb 16, 2011
    11,920
    4,920
    1,318
    Male
    Software Developer
    Keene, NH USA
    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
     
  7. codesplice

    codesplice Elite Recognized Moderator
    Moderator
    Rank:
     #13
    Points:
    1,563
    Posts:
    8,718
    Joined:
    Oct 29, 2013

    Oct 29, 2013
    8,718
    10,101
    1,563
    Male
    SysAdmin
    Huntsville, AL
    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.
     
    Thom and D-U-R-X like this.
  8. eyalkn

    eyalkn Lurker
    Thread Starter
    Rank:
    None
    Points:
    6
    Posts:
    3
    Joined:
    Jan 27, 2014

    Jan 27, 2014
    3
    1
    6
    Tested it again with the exit task and it worked, thank you again for all your help.
     
    codesplice likes this.
  9. Thom

    Thom  
    VIP Member
    Rank:
     #22
    Points:
    1,318
    Posts:
    11,920
    Joined:
    Feb 16, 2011

    Feb 16, 2011
    11,920
    4,920
    1,318
    Male
    Software Developer
    Keene, NH USA
    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
     
  10. codesplice

    codesplice Elite Recognized Moderator
    Moderator
    Rank:
     #13
    Points:
    1,563
    Posts:
    8,718
    Joined:
    Oct 29, 2013

    Oct 29, 2013
    8,718
    10,101
    1,563
    Male
    SysAdmin
    Huntsville, AL
    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:
    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
     
    Thom likes this.
  11. Thom

    Thom  
    VIP Member
    Rank:
     #22
    Points:
    1,318
    Posts:
    11,920
    Joined:
    Feb 16, 2011

    Feb 16, 2011
    11,920
    4,920
    1,318
    Male
    Software Developer
    Keene, NH USA
    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
     
  12. codesplice

    codesplice Elite Recognized Moderator
    Moderator
    Rank:
     #13
    Points:
    1,563
    Posts:
    8,718
    Joined:
    Oct 29, 2013

    Oct 29, 2013
    8,718
    10,101
    1,563
    Male
    SysAdmin
    Huntsville, AL
    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.
     
  13. Thom

    Thom  
    VIP Member
    Rank:
     #22
    Points:
    1,318
    Posts:
    11,920
    Joined:
    Feb 16, 2011

    Feb 16, 2011
    11,920
    4,920
    1,318
    Male
    Software Developer
    Keene, NH USA
    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
     
    codesplice likes this.
  14. codesplice

    codesplice Elite Recognized Moderator
    Moderator
    Rank:
     #13
    Points:
    1,563
    Posts:
    8,718
    Joined:
    Oct 29, 2013

    Oct 29, 2013
    8,718
    10,101
    1,563
    Male
    SysAdmin
    Huntsville, AL
    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 :)
     
  15. Thom

    Thom  
    VIP Member
    Rank:
     #22
    Points:
    1,318
    Posts:
    11,920
    Joined:
    Feb 16, 2011

    Feb 16, 2011
    11,920
    4,920
    1,318
    Male
    Software Developer
    Keene, NH USA
    I found your suggestion of two profiles to be mind opening. I had never considered that in this stylized environment.

    The conflict between elements in both approaches is starting to feel like a Tasker issue.

    ... Thom
     
  16. Thom

    Thom  
    VIP Member
    Rank:
     #22
    Points:
    1,318
    Posts:
    11,920
    Joined:
    Feb 16, 2011

    Feb 16, 2011
    11,920
    4,920
    1,318
    Male
    Software Developer
    Keene, NH USA
    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
     
  17. codesplice

    codesplice Elite Recognized Moderator
    Moderator
    Rank:
     #13
    Points:
    1,563
    Posts:
    8,718
    Joined:
    Oct 29, 2013

    Oct 29, 2013
    8,718
    10,101
    1,563
    Male
    SysAdmin
    Huntsville, AL
    Nice work Thom!
     
  18. Thom

    Thom  
    VIP Member
    Rank:
     #22
    Points:
    1,318
    Posts:
    11,920
    Joined:
    Feb 16, 2011

    Feb 16, 2011
    11,920
    4,920
    1,318
    Male
    Software Developer
    Keene, NH USA
    I just reported it in Google+.

    ... Thom
     
  19. Thom

    Thom  
    VIP Member
    Rank:
     #22
    Points:
    1,318
    Posts:
    11,920
    Joined:
    Feb 16, 2011

    Feb 16, 2011
    11,920
    4,920
    1,318
    Male
    Software Developer
    Keene, NH USA
    One more data point.

    I left the office ... 30sec later it announced disabled. I returned an hour later. When I got close to the office it announced enabled.

    So ... it seems it has to be off for 15 or more minutes between the disable and the enable.

    The message with the code is now updated.

    ... Thom
     

Share This Page

Loading...