Difference between revisions of "Trigger: Wifi State Change"

(Update)
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
== Introduction ==
+
<pre class="header-style">This trigger will fire when the wifi state changes. You can configure it to fire when wifi is enabled or disabled, or when connected to/disconnected from a specific network.</pre>
<pre style="background-color: #ACC8E5; color: #112A46; border-radius: 10px; padding: 10px;">
 
This trigger will fire when the wifi state changes.
 
  
Please note that since Android 8.1 this functionality requires location permission and location services enabled in order to detect connect/ disconnect events.
+
''' Options '''
</pre>
 
  
==<p><b>Available Features </b></p>==
+
''' Trigger States '''
  
=== Connected to network ===
+
* '''Wifi Enabled''': Trigger when wifi is turned on
* ''''' Any Network '''''
+
* '''Wifi Disabled''': Trigger when wifi is turned off
<pre style="background-color: #ACC8E5; color: #112A46; border-radius: 10px; padding: 10px;">
+
* '''Connected to Network''': Trigger when connected to a wifi network
It will react to any connected Wi-Fi (SSID).
+
* '''Disconnected from Network''': Trigger when disconnected from a wifi network
</pre>
 
  
* ''''' Select manually '''''
+
''' Network Selection (for Connected/Disconnected) '''
<pre style="background-color: #ACC8E5; color: #112A46; border-radius: 10px; padding: 10px;">
 
Manually select one or more Wi-Fi networks (SSID) that the trigger will react to.
 
</pre><br>
 
  
=== Disconnected from network ===
+
When selecting "Connected to Network" or "Disconnected from Network":
* ''''' Any Network '''''
 
<pre style="background-color: #ACC8E5; color: #112A46; border-radius: 10px; padding: 10px;">
 
It will react to any disconnected Wi-Fi (SSID).
 
</pre>
 
  
* ''''' Select manually '''''
+
* '''Any Network''': Trigger on connection/disconnection from any wifi network
<pre style="background-color: #ACC8E5; color: #112A46; border-radius: 10px; padding: 10px;">
+
* '''Specific Networks''': Select one or more specific wifi networks by SSID
Manually select one or more Wi-Fi networks (SSIDs) that the activator will react to when disconnected.
+
* '''Add SSID''': Manually add an SSID that is not currently in range
</pre><br>
 
  
=== Wifi disabled ===
+
The network selection dialog shows:
<pre style="background-color: #ACC8E5; color: #112A46; border-radius: 10px; padding: 10px;">
+
* Networks detected during wifi scanning
It is activated when Wi-Fi is deactivated.
+
* Previously configured wifi networks on your device
</pre><br>
+
* Manually added SSIDs
  
=== Wifi enabled ===
+
Multiple networks can be selected, and the trigger will fire when connecting to or disconnecting from any of the selected networks.
<pre style="background-color: #ACC8E5; color: #112A46; border-radius: 10px; padding: 10px;">
 
It is activated when WiFi is activated.
 
</pre><br>
 
  
==<p><b>Examples</b></p>==
+
''' Requirements '''
  
=== Connected to network ===
+
* '''Location Permission''': On Android 8.1 (Oreo MR1) and above, location permission is required for connect/disconnect detection
* ''''' Turn off mobile data when you connect to a Wi-Fi network '''''
+
* '''Location Services''': Location services must be enabled on Android 8.1+ for connect/disconnect events
<pre style="background-color: #AC2424; color: white; border-radius: 10px; padding: 10px;">
+
* '''Helper App''': On Android 10+ some features may require the MacroDroid Connectivity Helper or Universal Helper app
Triggers
 
  
Connected to network
+
''' Examples '''
Any network
 
</pre><br>
 
<pre style="background-color: #1665B0; color: white; border-radius: 10px; padding: 10px;">
 
Actions
 
  
Mobile data OFF
+
  <pre class="trigger-style">Triggers
* Requires adb or root hack
 
</pre><br>
 
<pre style="background-color: green; color: white; border-radius: 10px; padding: 10px;">
 
Constraints
 
  
 +
Wifi State Change (Connected to Network: Home_Wifi)</pre>
 +
  <pre class="action-style">Actions
  
</pre><br>
+
AutoSync On
<pre style="background-color: teal; color: white; border-radius: 10px; padding: 10px;">
+
Set Variable: [location] = Home</pre>
Local variables
 
  
 +
''Configure device settings when connecting to home wifi.''
  
</pre><br>
+
----
  
=== Disconnected from network ===
+
  <pre class="trigger-style">Triggers
* ''''' Turn on mobile data when you disconnect from a Wi-Fi network '''''
 
<pre style="background-color: #AC2424; color: white; border-radius: 10px; padding: 10px;">
 
Triggers
 
  
Disconnected from network
+
Wifi State Change (Wifi Disabled)</pre>
Any network
+
  <pre class="action-style">Actions
</pre><br>
 
<pre style="background-color: #1665B0; color: white; border-radius: 10px; padding: 10px;">
 
Actions
 
  
Mobile data ON
+
Enable Mobile Data
* Requires adb or root hack
+
Notification: Wifi disabled, mobile data enabled</pre>
</pre><br>
 
<pre style="background-color: green; color: white; border-radius: 10px; padding: 10px;">
 
Constraints
 
  
 +
''Automatically enable mobile data when wifi is turned off.''
  
</pre><br>
+
----
<pre style="background-color: teal; color: white; border-radius: 10px; padding: 10px;">
 
Local variables
 
  
 +
  <pre class="trigger-style">Triggers
  
</pre><br>
+
Wifi State Change (Disconnected from Network: Any Network)</pre>
 +
  <pre class="action-style">Actions
 +
 
 +
Wait 30 seconds
 +
If Wifi Connected = false
 +
    Set Wifi: Off
 +
    Set Wifi: On
 +
End If</pre>
 +
 
 +
''Auto-reconnect wifi after disconnection.''
 +
 
 +
''' Notes '''
 +
 
 +
* Since Android 8.1, location permission and enabled location services are required to detect connect/disconnect events.
 +
* The trigger listens for NETWORK_STATE_CHANGED_ACTION, WIFI_STATE_CHANGED_ACTION, and SUPPLICANT_CONNECTION_CHANGE_ACTION system broadcasts.
 +
* For "Connected to Network" and "Disconnected from Network" options, wifi must be enabled to configure the trigger (you will be prompted to enable it if disabled).
 +
* Multiple SSIDs can be selected for connect/disconnect triggers.
 +
* Use "Any Network" if you want to trigger on all wifi connection/disconnection events regardless of the network name.
 +
 
 +
''' See Also '''
 +
 
 +
* [[Trigger:_Wifi_SSID_Transition|Wifi SSID Transition Trigger]]
 +
* [[Constraint:_Wifi_State|Wifi State Constraint]]
 +
* [[Action:_Wifi_Configure|Wifi Configure Action]]

Latest revision as of 22:18, 7 January 2026

This trigger will fire when the wifi state changes. You can configure it to fire when wifi is enabled or disabled, or when connected to/disconnected from a specific network.

Options

Trigger States

  • Wifi Enabled: Trigger when wifi is turned on
  • Wifi Disabled: Trigger when wifi is turned off
  • Connected to Network: Trigger when connected to a wifi network
  • Disconnected from Network: Trigger when disconnected from a wifi network

Network Selection (for Connected/Disconnected)

When selecting "Connected to Network" or "Disconnected from Network":

  • Any Network: Trigger on connection/disconnection from any wifi network
  • Specific Networks: Select one or more specific wifi networks by SSID
  • Add SSID: Manually add an SSID that is not currently in range

The network selection dialog shows:

  • Networks detected during wifi scanning
  • Previously configured wifi networks on your device
  • Manually added SSIDs

Multiple networks can be selected, and the trigger will fire when connecting to or disconnecting from any of the selected networks.

Requirements

  • Location Permission: On Android 8.1 (Oreo MR1) and above, location permission is required for connect/disconnect detection
  • Location Services: Location services must be enabled on Android 8.1+ for connect/disconnect events
  • Helper App: On Android 10+ some features may require the MacroDroid Connectivity Helper or Universal Helper app

Examples

Triggers

Wifi State Change (Connected to Network: Home_Wifi)
Actions

AutoSync On
Set Variable: [location] = Home

Configure device settings when connecting to home wifi.


Triggers

Wifi State Change (Wifi Disabled)
Actions

Enable Mobile Data
Notification: Wifi disabled, mobile data enabled

Automatically enable mobile data when wifi is turned off.


Triggers

Wifi State Change (Disconnected from Network: Any Network)
Actions

Wait 30 seconds
If Wifi Connected = false
    Set Wifi: Off
    Set Wifi: On
End If

Auto-reconnect wifi after disconnection.

Notes

  • Since Android 8.1, location permission and enabled location services are required to detect connect/disconnect events.
  • The trigger listens for NETWORK_STATE_CHANGED_ACTION, WIFI_STATE_CHANGED_ACTION, and SUPPLICANT_CONNECTION_CHANGE_ACTION system broadcasts.
  • For "Connected to Network" and "Disconnected from Network" options, wifi must be enabled to configure the trigger (you will be prompted to enable it if disabled).
  • Multiple SSIDs can be selected for connect/disconnect triggers.
  • Use "Any Network" if you want to trigger on all wifi connection/disconnection events regardless of the network name.

See Also