I have created a flow that changes my WiFi state based on location. I'd like to add a notification to the log as well as to the status bar telling me that the WiFi state changed to on or off. In the notification text area, I tried typing "WiFi {wifi_state}", but I get the notification that says WiFi Null. It's like the variable for the wifi_state is not available for the WiFi state action. I only see things based on location and trigger. If I try "WiFi {trigger}", I get "WiFi Manually".
How can I log and/or notify the current WiFi state when after this action is triggered? Do I need to create another action (of the type Script) to do this?
I'd like to do the same thing for when I change the state of BlueTooth.
Any help or examples would be greatly appreciated.
Kindest Regards,
DataCrypt
Notification of WiFi state when it changes
Moderator: Martin
-
- Posts: 56
- Joined: 16 Mar 2013 14:10
Re: Notification of WiFi state when it changes
You need to have either a condition or action that exposes the Wi-Fi state variable.Use the condition WiFiTthat state and make both the true and false connection go to same place. That will expose the variable.
Bob
Bob
Re: Notification of WiFi state when it changes
UPDATE: Figured it out! I went ahead and ran the output of the WiFi State (true and false) to a Script action. There I wrote my code and set a new variable which I called {state}. Lastly I created the Notification on StatusBar action and was able to get the variable {state} to display in the notification! Very cool. I also figure out the Bluetooth notification. For that I just used the Bluetooth Enabled condition and set a notification action for True or False (since it only has two conditions no need for a script).
Thanks for the prompt reply. I went ahead and added a condition of WiFi State after I set the WiFi on or off. I can then get the {wifi_state} variable from that which I direct to a notification on statusbar action. So, now I'm having a slight issue on how to display the message I want. Since the {wifi_state} is a number 0, 1, 2, 3, or 4. I have the text as "WiFi {wifi_state}" which shows "WiFi 3" (for enabled). I need to replace that with the text "Enabled". I tried doing an if statement and have the text like this:
WiFi if{wifi_state}==3 state="Enabled" else state="Disabled"
(Note: I'm doing the else Disable since I don't really care about the other states right now - if I have issues with it showing Enabling - I may need to add a pause (a sleep action) to the flow.)
but this displays WiFi 3==3 state="Enabled" else state="Disabled"
So, I'm wondering how I can do this (if it's possible here) or if I need to run a script action now?
Thanks again for your time.
Best Regards,
DataCrypt
Thanks for the prompt reply. I went ahead and added a condition of WiFi State after I set the WiFi on or off. I can then get the {wifi_state} variable from that which I direct to a notification on statusbar action. So, now I'm having a slight issue on how to display the message I want. Since the {wifi_state} is a number 0, 1, 2, 3, or 4. I have the text as "WiFi {wifi_state}" which shows "WiFi 3" (for enabled). I need to replace that with the text "Enabled". I tried doing an if statement and have the text like this:
WiFi if{wifi_state}==3 state="Enabled" else state="Disabled"
(Note: I'm doing the else Disable since I don't really care about the other states right now - if I have issues with it showing Enabling - I may need to add a pause (a sleep action) to the flow.)
but this displays WiFi 3==3 state="Enabled" else state="Disabled"
So, I'm wondering how I can do this (if it's possible here) or if I need to run a script action now?
Thanks again for your time.
Best Regards,
DataCrypt
Re: Notification of WiFi state when it changes
Hi,
In this case you can probably still use an inline script in your notification.
Something like this:
WiFi {if(wifi_state==3) "Enabled" else "Disabled"}
The complete text within the curly braces is executed as a script.
If you only care about the enabled state, then you could also use the condition "WiFi State: Enabled" and connect the true-output to a notification "WiFi Enabled" and the false output to another notification "WiFi Disabled" and don't use scripting at all.
Regards,
Martin
In this case you can probably still use an inline script in your notification.
Something like this:
WiFi {if(wifi_state==3) "Enabled" else "Disabled"}
The complete text within the curly braces is executed as a script.
If you only care about the enabled state, then you could also use the condition "WiFi State: Enabled" and connect the true-output to a notification "WiFi Enabled" and the false output to another notification "WiFi Disabled" and don't use scripting at all.
Regards,
Martin
Re: Notification of WiFi state when it changes
Thank you Martin. Would this also be allowed in an Expression action or only a script action?
One thing I noticed last night was that since this was running on a periodic timer trigger, I'd get this notification every time it ran. I only wanted it when it actually changed. Interestingly I could only retrieve the previous_wifi_state variable when I use a trigger of WiFi State. If I put the WiFi State action after a Set WiFi State action, I don't get the previous_wifi_state available to me. This way I could at least write the expression
so I know that it actually changed before showing a notification. Any way to get the previous_wifi_state without having to use WiFi_State as a trigger?
Kindest Regards,
DataCrypt
P.S. This is by far one of the BEST apps for Android! Great job! Thank you for your time put into this.
Code: Select all
WiFi {if(wifi_state==3) "Enabled" else "Disabled"}
Code: Select all
if(wifi_state != previous_wifi_state}
Kindest Regards,
DataCrypt
P.S. This is by far one of the BEST apps for Android! Great job! Thank you for your time put into this.
Re: Notification of WiFi state when it changes
You can add the inline script in almost all text fields of all actions and conditions. Press the [?]-button when you edit an action or condition and see if there is a text "Variables are supported" for a particular text field.
You can also test if a text field supports variables by typing curly braces in a text field and see if the braces are displayed in a blue color. For example you can type {x} in an action Notification on Screen and {x} should be displayed in blue.
The condition WiFi State can only access the current state and has no knowledge of the previous state. You could use a global variable to store the previous state (global_wifi_state=wifi_state).
I'm not entirely sure if this works for your use case but you could build two flows to display the notifications:
flow 1:
-trigger "Wifi State: Enabled"
-action "Notification: turned on"
flow 2:
-trigger "Wifi State: Disabled"
-action "Notification: turned off"
or combine it in one flow:
-trigger "Wifi State: Enabled, Disabled"
-condition "WiFi State: Enabled"
->true: action "Notification: turned on"
->false: action "Notification: turned off"
or with the inline script:
-trigger "Wifi State: Enabled, Disabled"
-action "Notification: Wifi turned {if(wifi_state==3) "on" else "off"}"
Regards,
Martin
You can also test if a text field supports variables by typing curly braces in a text field and see if the braces are displayed in a blue color. For example you can type {x} in an action Notification on Screen and {x} should be displayed in blue.
The condition WiFi State can only access the current state and has no knowledge of the previous state. You could use a global variable to store the previous state (global_wifi_state=wifi_state).
I'm not entirely sure if this works for your use case but you could build two flows to display the notifications:
flow 1:
-trigger "Wifi State: Enabled"
-action "Notification: turned on"
flow 2:
-trigger "Wifi State: Disabled"
-action "Notification: turned off"
or combine it in one flow:
-trigger "Wifi State: Enabled, Disabled"
-condition "WiFi State: Enabled"
->true: action "Notification: turned on"
->false: action "Notification: turned off"
or with the inline script:
-trigger "Wifi State: Enabled, Disabled"
-action "Notification: Wifi turned {if(wifi_state==3) "on" else "off"}"
Regards,
Martin