Storing DnD status

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
Taomyn
Posts: 5
Joined: 22 Aug 2019 06:01

Storing DnD status

Post by Taomyn » 27 Aug 2019 10:24

Hi,

Another migration from Automate question I'm afraid. I have a flow that waits for me to be connected to the office WiFi, then stores the current status of DnD and then enables DnD. When later it disconnects from my work WiFi is restores the DnD state as it was saved before.

I cannot figure out how to save the current state. I saw another thread mentioning "Notifications on statusbar displayed", but the "Init Variable Notifications Statusbar" doesn't have any statusbar information, only what is currently in the pull-down notifications. Is there somewhere else that I can save the DnD status from?

I'm running on a Pixel 3, Aug update.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Storing DnD status

Post by Desmanto » 29 Aug 2019 19:03

To "wait" for the office wifi, use Wifi Connected trigger, choose your office wifi. You don't actually wait for it, since it is event based. After triggered, You can check current DND status using condition Interruptions Mode, choose All / Always Interrupt. If true, that means DND is off. False, DND on. To store the state, simply assign it to a global variable (glovar). You can save various state to glovar and have more flexibility to use it. From the condition interruption mode, add 2 scripts, each to true and false branch.
True branch

Code: Select all

global_dnd_state = false;
Add action Set Interruption mode to None - don't interrupt.

false branch

Code: Select all

global_dnd_state = true;
false branch doesn't have any additional action, since the DND is already on.

This means after you have connected to your office wifi, it will check the DND mode and save it to global_dnd_state. It only enable the DND if previously DND is off.


Later when you disconnected from your wifi, create another flow with trigger wifi disconnected. Use condition expression

Code: Select all

global_dnd_state
That's it, without any == assignment, since the value is already true/false. True, use action Interruption mode, change to All / Always Interrupt. False do nothing (since you are already in DND state when in office).


For the disconnected event, it is better to use other event that guarantee you are already out from office, for example connected to car bluetooth. If not, this flow will be triggered if you roam around the office, the wifi signal is too weak and get disconnected. Although it won't affect your DnD, but the flow may triggered unnecessarily depends on your activities in the office.

Other method you can use to check DnD is to use Action Init Variable System Setting, [Global] zen_mode. If 1, DnD is on; 0 DnD is off. This require to grant write secure permission to Automagic thru adb.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
Taomyn
Posts: 5
Joined: 22 Aug 2019 06:01

Re: Storing DnD status

Post by Taomyn » 30 Aug 2019 06:44

Desmanto wrote:
29 Aug 2019 19:03
Wow, thank-you for the detailed response, I will go through it thoroughly this weekend and see if I can get it going - needing to use ADB is a annoying but it's something I'm fairly familiar with, and reminds me that I still need to give my syslog app some extra rights on this new phone.

User avatar
Taomyn
Posts: 5
Joined: 22 Aug 2019 06:01

Re: Storing DnD status

Post by Taomyn » 30 Aug 2019 11:39

Desmanto wrote:
29 Aug 2019 19:03
For the disconnected event, it is better to use other event that guarantee you are already out from office, for example connected to car bluetooth. If not, this flow will be triggered if you roam around the office, the wifi signal is too weak and get disconnected. Although it won't affect your DnD, but the flow may triggered unnecessarily depends on your activities in the office.
Hmmm, I just realised this is the kind of thing I had to code when I used to use Tasker before moving to Automate where it was much simpler - its flow simply waited for the WiFi to disconnect, change the DnD back if it was different before looping round and waiting for a connection to the office WiFi.

Screenshot_20190830-133454.png
Screenshot_20190830-133454.png (60.33 KiB) Viewed 12545 times

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Storing DnD status

Post by Desmanto » 30 Aug 2019 18:09

If by waiting, you mean waiting for the event to happen, then Automagic trigger wifi connected/disconnected also behave the same. You simply put it in two flows to make it clear. You can combine them into a single flow if you like, using expression. it is just if you use the same logic as in Automate, then it will behave just like in Automate too. That wifi disconnected/connected will be triggered everytime you lost connection and reconnected again to the office wifi.

If you come from tasker too, you need to adapt to a bit different concept about the event vs state : viewtopic.php?f=5&t=7217&p=20310#p20310
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply