Variable help: Set variable 2 hours after trigger


1) Give a description of the problem
Need helping correcting variable to send in message

2) What is the expected behaviour?
Send message that command will execute 2 hours after trigger time

3) What is happening/not happening?
triggerTime variable logs time when event happens
executeTime - unsure how to add 2 hours to trigger time.
Message is being sent with trigger time that was saved.

**4) Post a Green Snapshot of the piston!

5) Attach logs after turning logging level to Full
I don’t think logs are necessary as the pistons works but my variables are written wrong.


addMinutes() or addHours should do it


I updated to
time executeTime = {triggerTime, addHours(2)}

it is adding 4 hours. I also tried with addMinutes(120), same result.

triggerTime = 2:18pm
executeTime = 6:18pm


Should be like this… executeTime = addHours(triggerTime,2)

(expression) addHours($now,2) »»» (datetime) 1619825649385 (expression) formatDateTime(addHours($now,2)) »»» (string) Fri, Apr 30 2021 @ 4:34:18 PM MST


Thank you so much!


If it’s not too much trouble, I have 1 more question. Different scenario but same topic

If triggerTime is $now, eventTime is set for 4am (the following day) is it possible to write into the command that event will trigger in X hours:minutes?
I’m guessing I’ll have to use formatDuration?


Yes, formatDateTime() will do it. The details are in the wiki also. Let me know if you get stuck.

Edit: Sorry, misread that post. Yes formatDuration sirius give you your target formatting.


I am completely stuck. Using the same piston as before to test

This pistons works but returns a time value of 16hr and X minutes. It should only be 8-ish hours.

I tried using datetime for the triggerTime variable device type but it logs the date as 5/1/2021(tomorrow) with correct (current) time.
Then I have the problem of not knowing how to set the execute time using the datetime for 4AM the next day.
I could not figure out the formatDateTime() syntax.

BTW, thank you so much for your help and patience!!!


That is interesting, I’ll try and play with it also after I get done installing my eufy doorbell :slight_smile:


After a few trial and errors… I noticed the values for times were not being stored correctly and this is what I came up with after some debugging.


That seems to work. A couple questions…

  1. Will the date in the executeTime var update to the following day automatically (so that this can be used daily)

  2. What did the log info do?

  1. No, I just hardcoded the info for testing.
  2. The log was used for debugging to see what the variables contain.


Thanks for the lesson! I’m still learning.

So how would I make the execute variable work for daily use?


Hmm, after execution, you can add another task addDays(executeTime,1). Today’s value is 5/2/21 at 4AM, after the execution, it should change it to 5/3/21 4AM ready for the next day.