How to set an action: edit an event in the calendar

pimpontitit

New member
Hi,
I'm currently using a Macro that stores in my calendar my entrance and exit hours from workplace.

Basically it works like that:

Triggers:
-Entrance at worplace (geofencing)
-exit from workplace (geofencing)

Actions:
-If entrance trigger --> add an event in calendar called "entrance work"
-If exit trigger --> add an event in calendar called "exit work"

So, per day, I have two events: one 5 minutes entrance event in the morning, and one 5 minutes exit event in the afternoon.

Instead of two events, I would prefer one long event from 8am to 5pm called "Work"

Is there a way to do that ?

For example is it possible to change the macro to something like:
When entrance trigger --> log the hour and start a countdown
When exit trigger --> use the logged information (entrance hour + countdown/time spent there) to create an event.

Or another way: I keep the original macro as it is, but instead of:
-if exit trigger --> add event
Something like:
-if exit trigger --> edit the last "entrance at work" event and change its end time to the current hour

Is there a way to dot that just with MD ?
If not, I downloaded a plugin called CalendarTask, that offers a "Modify event" option.

But then there are many fields I dont know how to fill as:
-Event ID
-Start time
-End time
-Title
Etc..

How can I make the Event ID field understand that I want the latest "Entrance at work" from my calendar.

Thank you for your help
 
Last edited:

tanutanu

Well-known member
Hi,
I'm currently using a Macro that stores in my calendar my entrance and exit hours from workplace.

Basically it works like that:

Triggers:
-Entrance at worplace (geofencing)
-exit from workplace (geofencing)

Actions:
-If entrance trigger --> add an event in calendar called "entrance work"
-If exit trigger --> add an event in calendar called "exit work"

So, per day, I have two events: one 5 minutes entrance event in the morning, and one 5 minutes exit event in the afternoon.

Instead of two events, I would prefer one long event from 8am to 5pm called "Work"

Is there a way to do that ?

For example is it possible to change the macro to something like:
When entrance trigger --> log the hour and start a countdown
When exit trigger --> use the logged information (entrance hour + countdown/time spent there) to create an event.

Or another way: I keep the original macro as it is, but instead of:
-if exit trigger --> add event
Something like:
-if exit trigger --> edit the last "entrance at work" event and change its end time to the current hour

Is there a way to dot that just with MD ?
If not, I downloaded a plugin called CalendarTask, that offers a "Modify event" option.

But then there are many fields I dont know how to fill as:
-Event ID
-Start time
-End time
-Title
Etc..

How can I make the Event ID field understand that I want the latest "Entrance at work" from my calendar.

Thank you for your help
First, you remember the UNIX epoch time value with a MD magic text, [system_time] in a variable when the entering trigger fire, and get the current time again when exit. So you can calculate the duration like this;
Sub(minutes) = (OUT - IN) / 60,
then you can add the daily working time as an event like this.
 

Attachments

  • Screenshot_20211224-151635~2.png
    Screenshot_20211224-151635~2.png
    154.2 KB · Views: 29
  • Screenshot_20211224-151703~2.png
    Screenshot_20211224-151703~2.png
    122.2 KB · Views: 30
Last edited:

pimpontitit

New member
Awesome !
I tried today and it works exactly as intended, thank you!

I have two questions:

1) instead of creating an "If" condition for setting the first variable (intStartWorking), you used a condition ( "Trigger Fired")
But after you used an "If" for the second trigger.

So my question is, is it totally equal to use
If(trigger fired)-->action-->End
Or
Action (condition-->trigger fired)
?


Is there one that will use more batteries, for example the second one ( because it will "think" about processing the action before thinking about the filled condition.
Whereas the first one is "thinking": is the trigger filled ? No. So dont need to think about the eventual actions ?

Or no, its exactly the same ?

2)I guess [lv=x] mean "the local variable x" ?
 
Last edited:

pimpontitit

New member
And I made some changes:

- last action of the macro is setting the variables to 0

-I take very often the road that passes in front of my workplace. So I was affraid that the trigger "entering workplace" could fire just because I was passing by and not even entering work.

So I did put a countdown of 10 minutes and then an If(localization work)

And for the same reason, to avoid the "Exit work" trigger, I did set an
If(trigger exit work + variable intStartWorking > 1)

what do you think ?


Screenshot_20211226-195830_MacroDroid.jpg
 
Last edited:

tanutanu

Well-known member
Sounds good:) I'm happy to assist you 👍

1) instead of creating an "If" condition for setting the first variable (intStartWorking), you used a condition ( "Trigger Fired")
But after you used an "If" for the second trigger.

So my question is, is it totally equal to use
If(trigger fired)-->action-->End
Or
Action (condition-->trigger fired)
?
Exactly. The constraint hanging under the statement works exactly same as a if condition. I use it for just a statement because it is simple, easy to edit and a little brief to fill statements in the same screen. When I need a code block as if branches, of course I use if/elseif/else/endif statements:)

Is there one that will use more batteries, for example the second one ( because it will "think" about processing the action before thinking about the filled condition.
Whereas the first one is "thinking": is the trigger filled ? No. So dont need to think about the eventual actions ?

Or no, its exactly the same ?
In my opinion, geofence api is enough battery conscious, well saving the battery. So, I don't care about it at all. I benchmarked it and got it as a truth.
The best practice is that you evaluate it logically with the OS accounting feature or so. It's up to you:)
There are so many different devices in the world and configured to a bunch of different conditions. An urban legend is not true or became not true as the device progress.

2)I guess [lv=x] mean "the local variable x" ?
Correct👍 The keyword "lv" seems to be abbreviated form of "Local Variable." The keyword called "magic text" in MD, quoted between brackets "[]" is replaced to a specific value in the runtime. "lv=" direct to extract the assigned variable value.

Clearing the values at the last is a very good manner to avoid an unexpected error in a macro run. I do it in most cases and leave sometimes.
The geofence triggers are reliable enough as my testings, and once it fire, the variables is surely filled with UNIX epoch times as well:)
 
Top