Time in Variable

Is there a context (or any other) variable that can add trigger times to a variable?
I know I can create separate rules but I’m wondering I this is possible in a single rule

Triggers
6pm
9pm

If
variable is X then set Y (add time triggered)
Else If
variable is Y then set Z (add time triggered)

Not officially. There’s an undocumented $context.event.timestamp variable, but it’s in UTC so I don’t think it would be useful in the way many people would want to use it.

Feel free to create a feature request! When we originally built out the context variables concept, we bounced around the idea of time related data, but we weren’t sure what the use-cases were… and we figured there would be other requirements (eg. display format, which timezone, etc) but hadn’t heard any requests for it, so we prioritized other requested features.

You can use time within IF conditions, so you could accomplish what you’re looking for in your example rule.

Since we know the triggers are 6PM and 9PM, we can use a time condition that checks if it’s before or after some time between the two triggers. In other words: if it’s before 7PM then it’s our 6PM trigger, otherwise it’s after 7PM so it’s our 9PM trigger

2 Likes

Thanks Josh, maybe $context.event.timestamp variable could be good enough for record purposes, is it available ? How can I get it ? Thanks.
UPDATE: I had found how do it my friend. I will try !..thanks.

Set {{$context.event.timestamp}} to a text variable …

1 Like

º

I think the “USER LOGs Creation” feature request could include this, for each record, user can add timestamp… but has 0 votes … :pensive:

Thanks for the update and glad you got it working.

While they perhaps could work very well together, I still see the request for Timestamp related features as its own distinct request. As mentioned above, it’s still not clear what the requirements for a Timestamp feature request would be, but I suspect there might be a need for formatting timestamps, converting timezones, etc… :slight_smile:

1 Like

I tried using the timestamp variable in a Pushover notice. I’m setting up a rule to check if garage doors are open in the middle of the night and to close them if they are open. I want to know when they were closed. I can count backwards from the timestamp on the Pushover notice (e.g., it might say it was sent 2 hours ago). However, I’d like the Pushover notice to display the time (and maybe date). Is there no variable to do this? If not, I suppose I could do math on the timestamp variable to change to my timezone? And what about truncating it? The formatting is a bit rought as it is (the T for time is right next to the date, which showed tomorrow because I’m 4 hours behind UTC and it’s 824 eastern). Thanks.

The $context.event.timestamp variable is an ISO 8601 formatted timestamp and will be in UTC.

So if you’re ultimately passing this to Tasker, it should be able to parse ISO 8601 formats. Or if you’re just displaying the notification directly, you might be able to use the /date endpoint noted in this thread and pass the $context.event.timestamp to the input field.

:tada: With the release of Expressions, we would recommend using those directly.

This is great. Thanks. I’m using a Pushover notice, but the concept is the same. How do I use New York time, though? I’ve tried all kinds of combos to get New York or eastern time and it keeps throwing errors. I poked around the ISO 8601 standard, but couldn’t the right format. Maybe it’s not New York but something like eastern or Atlantic? Thanks.

The other thread has a link to the list of timezones. ISO8601 is just a standard for formatting timestamps. The timezones are covered by another standard for timezones called IANA.

With expressions, the timezone will automatically be pulled from the location associated with your account, so just make sure to set a timezone on your location.

formatDate($context.event.timestamp, "L LT")

Alternatively, if you want to explicitly override the timezone, you’re looking for America/New_York.

timezone = "America/New_York"
formatDate($context.event.timestamp, "L LT")

:tada: Update: With the release of Expressions, we would recommend using those directly as noted in the edited post above.

Old Labs Approach

https://lab.sharptools.dev/date?input=2022-08-11%2008:00&timezone=America/New_York&inputTimezone=America/New_York&format=L%20LT

Ah, I didn’t think about putting an underscore between New & York! I tried several other combos, though. And now I see the other post as well with add’l info. Thanks.

1 Like

By the way, this works great. I see, though, that it’s a “lab” link. If this ever moves to a different URL, please let us know. Thanks.

1 Like

Question on time please… the action to one of my rules is an SMS message to my phone. I want the message to say, “The Garage Door is Open Too Late at ”. I essentially want the time or date at the end of my SMS message. I can actually do it with the $context.event.timestamp value but as many have said that is kind of useless. So is there a way to put the date and/or time at the end of an SMS message? Thanks!!

Expressions are available now and include a variety of date related functions.

For example, you can use ‘inline expressions’ within double squigglys in a notification:

The time is {{ formatDate(now(), "hh:mm a") }}

And here’s how it looks in a notification while editing it (once you tap out, the double squigglys disappear and it’s replaced with a grey rounded box).