Math / Date Expressions!

You can use Variables in device actions, so you can have the expression save the result to a variable and then use that in a device command.

@Zach_Imler has you pointed in the right direction.

Keep in mind what each function is doing and what the output is.

  • date(input, format) - takes a string input along with an input format string, parses the input, and outputs a date (in milliseconds)

  • formatDate(date, format[, locale]) - takes a date input along with an output format string and outputs a string in the specified format

So if you need to display a date, then formatDate() is likely going to be your friend. If you need to parse a string as a date so you can perform math / comparisons on it, then date() is likely what you need.

So in your third line where you’re trying to use fulltime to calculate a duration, you probably would want to parse fulltime with date() and then compare that directly with now() since those would both be dates in milliseconds:

today = formatDate(now(), "YYYY-MM-DD ")
fulltime = concat(today, $Night)
duration = now() - date(fulltime, "YYYY-MM-DD h:mm a")
minutes = round(durationAs(duration, "minutes"),0)
minutes == 0

An alternative would be to compare the ‘time’ string for each

nowTime = formatDate(now(), "h:mm a")
equalText(nowTime, $Night)

I was hesitant to respond to this as the vast majority of time that something is being done every minute, it could be rewritten as an event driven rule. There are exceptional cases, like this one may be, where you want to check for a specific time and have a top-level IF Condition determine if the rule should run and that’s fine. But I would otherwise caution people against running rules every minute and instead feel free to create a thread where we can help see if there’s an event driven approach that works better.