Hi, I have an automation which works fine. I have a google calendar to keep track of the days I work. The automation reads the calendar, on days I am working it sends a message to my phone to create an alarm to wake me up.
The problem I have is the alarm hour and minute are hard coded in the action part. What I’d like to do is read the calendar event start time, subtract 33 minutes from the start time, then extract the hour and the minute part from that calculation to send in the intent_extras of my automation.
In some pseudo code I’d do
var alarmTime = Dateadd(minute, -33, trigger.calendar_event.start_time);
var h = alarmTime.hour;
var m = alarmTime.minute;
Then I’d poke these values into the code below. I’m just not sure how I do this in an automation and would appreciate some pointers. Thanks.
Thanks again for replying. I finally got it working using the following. I had to change ‘today_at’ to ‘as_datetime’ as using the first function was always returned todays date so ended up with an incorrect alarm time.
Yes, but since the action only sends hour and minutes to the phone the date is irrelevant.
When your calendar says 6:40 for example and the automation is triggered the day before it will believe it shall set an alarm for yesterday.
But the intent extras only care about hour and minutes so the phone will assume it’s an alarm for tomorrow.
Are you sure it didn’t work or did you just not try it? Or does the calendar start have full date time?
That could mean it doesn’t work with today at…
I realize this as I’m writing this post.
Good that you got it working!
It is only sending the hour and minute, but using the today_at seemed to return midnight when using a date of tomorrow, so the subtraction seemed to be from midnight and the wrong hour and minute was sent. Using the datetime preserved the actual time and the subtraction seemed to work okay. That’s all assumptions on my part by the way, but again thanks for your help I wouldn’t have got there without it.