Well, here are the results of my testing today. For those who joined us late and are following from home what I'm trying to achieve with Tasker is that I want the phone to send an email to the secretaries whenever I leave the office. I do not want this email sent when I return to the office, just when I leave.
I found a script that would generate this email and was looking for the proper contexts to call the script under. Uncle Mike offered me a solution that I was skeptical of. I came up with a solution that I was skeptical of as well. My car adapter is recognized as an AC adapter so I'm using that condition as being in my car.
UncleMike's solution:
Profile 1 - Set's work hours variable
Context - Day of week = M, T, W, Th, F
Context - Time of day = 0800 - 1700
Task - %WORKHOURS = 1
Exit Task - Variable reset %WORKHOURS
Profile 2 - sends the email
Context - %WORKHOURS = 1
Context - Power = not AC
Context - GPS Loc = Work
Task - Run email script
My solution
Profile 1 - Set power state variable
Context - Power = AC
Task - %PWRST = 1
Exit task - Variable reset - %PWRST
Profile 2 - While loop for Power that counts up while on AC power
Context - %PWRST = 1
Task - Stop if %PWRST = 0
%PWRCT = PWRCT + 1
Go to line 1
Profile 3 - Sends the email
Context - %WORKHOURS = 1
Context - PWRCT = 1
Context - GPS Loc = Work
Task - Send email
Now, my way is insanely more complicated and convoluted than UncleMike's. I freely admit this. Yesterday I tried it out and it didn't work, but there was an issue with my Workhours variable. So I fixed that.
Today I was running a few minutes late. My task sent me 7 emails by the time I pulled into the parking lot at 8:05. I may have set the GPS radius too wide. In any case, this wasn't what I was wanting. UncleMike's task did not send the email when I arrived at the office which is what I was wanting. When I left the office, my task generated an email, but did not generate an email when I returned.
So far, my task has generated 7 emails that were unwanted and all when I pulled in to work late. When I left for lunch, my task generated an email.
UncleMike's task has not sent me a single email. It may be interfering with my task though. I think for tomorrow I will backup the profile sending my email and try with just UncleMike's.
Edit: I'll also add that one of these two profiles is screwing with GPS on my phone. This morning I got to the office by 8 and my phone was dead by 11 and was running very, very hot the whole time. I suspect one or both of these profiles had GPS turned on constantly as I've made no other changes to the phone and installed no other programs recently. I have no idea which of these two profiles it is though.
Re: my profiles...
It may be just mis-typed in your post, but the task in my second profile should be an exit task. Aside from that, with the logic I used, the profile should have been active while you were at work and uplugged during work hours. Was it active at the right when it should be?
I'm at a loss at the moment as to why no emails were sent.
If you have GPS enabled in Android, my profile with Location and Not Power are likely causing battery drain.
Re: your profiles...
You're incrementing %POWERCT as a means of only sending the email at the moment you're powered, right? If so, it needs to be reset at some point, and I'm not seeing where that happens. I think it should happen in the enter task of profile 1.
Profile 2 could accomplish the same result (if I understand what you're doing) by waiting 1 minute and incrementing once, instead of constantly looping. I think this is an excellent solution to detecting the act of being plugged in as opposed to the state of being powered. This same function could be included in profile 1, eliminating the need for profile 2.
Your profile 3 generated one email when you left the office, and none when you returned... this is good, and I think your incrementing idea is responsible.
As above, I'm also at a loss as to why multiple emails were sent in the 5 minutes before you arrived at work. My first reaction was that the never-ending incrementing was somehow wrapping around after reaching the maximum allowed by the data type Tasker is using internally. But I've doubled a number many times in Tasker and now have a variable with a value of 17592186044416, while being unable to produce any type or wrapping effect.
Re: general...
How are you identifying which profile caused the email to be sent?
You can add use Notify actions in the tasks, so you can look at the notification bar to see when a task was last executed. This may help in tracking down what's happening when you can't look at your phone.
Keep up the good work. It will be worth it in the end.
