Rule Machine Time Variables

Perhaps this is obvious to everyone, but it wasn't to me until I started playing with the new time variables. They appear to be time and date, not just time -- which makes sense when you consider the offsets and variable math that are available. So, for example, I have a use-case where I'm scheduling a vacuum to run under certain conditions approximately 3-4 days in the future. I can use time variables, as @bravenel described above, to set the timing by adding 72 hours or 96 hours, as examples, to the current time.

However, on the dashboard (by way of a connector), only time of day shows up on the "variable time" tile, but if you use "variable string" or "variable number", you get time and date, but in a fairly unfriendly format.

Anyone figured out a way to show time and date (the value of the time variable's connector) on a tile?

I was wondering same thing; I just haven't asked here yet. Thanks for asking.

But when you trigger off that time variable, does it happen in 3-4 days or every day at that time in the variable?

Time variables are not date-and-time variables. The date object you can see is how time is represented in the system. But the utility of the variables is limited to time-of-day and does not include the date. This is why you can only set a time, and only display a time in a Dashboard.

1 Like

Question:
I created a global variable to hold the time of Sunset. (a few days ago, it was 5:05pm).
Should it be updating itself in Rule Machine:
image

i bet @mluck saw the same thing in the time variable's connector as i did and thought there might be a way to show the time variable exactly in that format in a Dashboard.

Thanks for the fast (immediate?!) clarification, Bruce.

Just so I'm clear: image the following scenario....

  • set TimeVarA to 4:00PM
  • set TimeVarB to TimeVarA + 2880 minutes (i.e., 48 hours later)

I see in the device details page that the connector for TimeVarB correctly shows a value of 2020-01-21T16:00:00, which is in fact 48 hours in the future. I take your point that the two variables can not be used in calculations (e.g., TimeVarB minus TimeVarA yields zero, ignoring the date just as you said). But it appears that the date can be included alongside the time in a "variable number" tile on the dashboard. Any reason to believe this isn't workable just to view on a dashboard? If so, is there a way to format in a more friendly way?

Do I understand correctly that "2020-01-21T16:0000", as in the above example, can NOT be used to trigger a rule without ignoring the date?

And, of course, under the category of "greedy user bastard", can I make a feature request for this to be actually be date and time, not just time?

There is -- use a Variable String or Variable Number tile. It's ugly, but it appears to work.

What is the trigger in the rule? A certain time. It does not say "A Certain Date and Time". The function in RM that uses the time you enter uses the "schedule()" method which takes a date/time field, ignores the date and schedules it for once a day at that time. There is no trigger for specific date/time.

Only if you have a rule that updates it.

1 Like

I take that as a "yes" then...

A yes to what question? You cannot use a time variable as a specific date/time to execute a rule. That is not how they work. I don't know why you disagree with Bruce, since he's the one who wrote the darn thing. But you keep trying. :man_shrugging:

Here is a time variable that I've given a future date to (a pointless thing to do, since date is ignored):

Here is the scheduled job for a rule I made that uses that variable as a trigger using Certain Time:

As you can see, that Certain Time trigger is set for tomorrow morning, not on 01-22. Dates are not part of Time Variables; Time Variables only hold time of day. So 9:15 AM means exactly that and nothing more. Scheduling a Certain Time for 9:15 AM creates a schedule like this:

36%20PM

That means to run the trigger at 9:15:00 every day. First scheduled event is tomorrow morning, as shown above.

When you input a time with a time selector, like this:

48%20PM

That creates a date object, which is represented by a string that looks like this:

2020-01-20T09:15:00.000-0700

While such a date object is the way that time is represented, that does not mean that the 2020-01-20 part of it is used with Time Variables -- it is not. You can edit the time in such a string all you want (for example, on the Time Variable Connector device page). If the format gets messed up, the time won't work -- it must be formatted as shown. This is the way that Groovy (and Java) represent and manipulate time.

That makes total sense -- thanks for the thorough explanation!

While I get that the date is completely ignored by all automations, from my tests it looks like one can at least show the date/time on a dashboard using a couple different tile templates. In a use-case where some automation calculates a time X hours in the future (where X>24), the value of the connector shows the correct date and time, which (I think?) I could plop on a dashboard for information purposes (provided no further calcs are performed on the value of course) .

You see any reason this would be problem?

In your post 49, it looked like you were answering my question, "Do I understand correctly that (blah-blah)". And your answer seemed to confirm my suspicion about the blah-blah part.

When I responded "I take that a yes", I wasn't trying to be smart aleck (though rereading it, I could see how somehow could take it that way). Just acknowledging your answer by saying that I think you confirmed my hypothesis.

Bottom line, appreciate the help.

Well, let's read what I actually said, instead of what it looked like I was saying. I said,

I was answering my own question. I didn't ask anything. The trigger is Certain Time not Certain Date/Time.

Bottom line, don't use the date in that field. You can't even access it from RM so how would you use it for anything. Just ignore the date and your world will get a lot simpler.

Lol this has gotten a bit silly. I'll take 100% of the blame as the noob around these parts. I'm not interested in spending more time on semantics nor over-extending your original graciousness.
That said, on the off-chance it's helpful, I'm talking about a question that I asked to which you helpfully responded:

When you helped me understand the connection to the schedule() method and that it's a once-daily kinda thing, you cinched it for me! I realized my original hypothesis was correct--that field cannot be used to trigger a rule (not to mention any other automation). Bruce then made that conclusion even more clear later. Question answered! Thanks again....night.

@mluck I was right there with you in the confusion when I saw the date in the connector page. I work in Excel a lot. If I enter of 3:00pm into an Excel cell and format as a time, I only see that as a time, However, Excel assigns a date of 1/0/19 even though I don't see it. If I add 15 hours to that cell in a formula in another cell, the new cell will show as 6:00am but if I then format that cell as Time & date, the value shown is 1/1/19 6:00. Sometimes, this can bite you in the ass if you forget that there is also a date stored in that cell when adding, subtracting, multiplying, etc.

So, when I saw that the time variable too was showing the correct date when I set variable equal to NOW, I thought Hubitat was doing the same as Excel & I got excited. It does appear that you & I can put the time variable into a dashboard in a Variable String tile. That's all I am really interested in; the last time & date my motion sensor changed states. However we can't use that date info in rules or do any mathematical actions on it.

Confusion cleared up and tragedy averted. @bravenel Thank you for this addition to Hubitat.

There should be an easy way to convert a time saved in a string variable to a time variable (assuming you format it correctly). Right now I am doing a log of extra steps to convert the string into 2 numerical variables, then convert hours to minutes and add the minutes back into a time variable.

Please show me the string format you have in mind.