Rule Machine Time Variables

Time Variables Available in 2.1.8

Rule Machine has been enhanced to support variables representing time. Like other Global or Local Variables, Time Variables can be created and deleted, their values set, and Connectors created for use in Dashboards. Hubitat Dashboard now has a Variable Time template to display and change Time Variable Connectors. Time Variables show time of day in either 12 hour or 24 hour display depending on the hub's setting for time displays, and show hours and minutes. If Action logging is enabled, changes to Time Variable Connectors are logged.

Note that Time Variables are for time of day use, not time duration. In many contexts of Rule Machine duration can be specified with a Number or Decimal Variable in the seconds field, specifying seconds of duration (e.g. in Delays).

A local Time Variable must have a Connector to be used for a triggering event, while global Time Variables do not have this requirement.

Time Variable as Certain Time Trigger

When defining a Certain Time trigger event, there is a new choice to use a Time Variable. The trigger will initially be scheduled at the current time of the Time Variable. Should that Time Variable time be changed by changing its Connector, the scheduled time will be updated.

Time Variables in Triggers

When defining a Variable trigger event with a Time Variable, comparison operators are available as with other variable triggers. These include =, !=, <, >, <=, >=, changed, increased and decreased. It is possible to compare a Time Variable to a selected time or to another Time Variable.

Setting Time Variables in Actions

Time Variables may be set in Rule Actions. Available options are set to a selected time, current time (Now), Sunrise, Sunset, an Offset to the current value (+ / -) in minutes, or to another Time Variable with an optional Offset in minutes. These Offsets can be a numeric value, or Number or Decimal variables using %variableName%.

It is possible to set a Number or Decimal Variable to the difference between two Time Variables. The resulting value is the first time subtracted from the second time, expressed in minutes.

Time Variables in Conditions

Time Variables may be used in the Time of Day Condition. This includes the condition of a specific minute of time, or Between Two Times.

Conditions involving Time Variable comparisons can be created, similar to those used for trigger events.

Time Variables in Wait for Events

A Time Variable may be used in the Certain Time event of Wait for Events Action. As with Time Variable trigger events. if the time value of a Time Variable used this way is changed by a Connector, the Wait for Event Certain Time is updated accordingly. When a local Time Variable is used in Wait for Event, it must have a connector, while this is not required for a global Time Variable.

7 Likes

I have tried to run this but fail to see the added menu option within certain time?
I've found with the dashboard there is a time variable option for the selected device, however my question is how would you assign a device that has 2 time adjustments from the dashboard as presently the only link (unless I'm missing something on the update) just assigns it to the device not the individual rule.

The dashboard is there to assign/modify the value of the variable. That is all. If you want to use that variable to do anything, you'll have to use it in a rule. What Bruce was saying is, if you select a time variable as a trigger (by selecting Certain Time and then selecting Variable from the next dropdown) and you then update this time in the dashboard via the connector, Rule Machine will automatically reschedule the triggered event for the rule. You don't have to go and do that manually. RM will do it for you.

If you want to do the difference between two times, you would have to write a rule to do that with the variables.

That is what is not appearing. I updated to 2.1.8.115 this morning and it is not there. Do I have to delete the rule and start again or should it by a dynamic update?

Screen shot of my options Dropbox - Screenshot_20200111_095918_com.android.chrome.jpg - Simplify your life

@bravenel I cannot seem to get the connector to work - it just shows "Invalid date" in the dashboard

@bravenel - Ive managed to get it to work but its created another problem. I fixed it by creating an additional time variable and making a connector for that - and that seems to have worked.

However, now the old connector is un-deletable - as in, it exists in my devices, it shows as being in use by the RM app in question, but it is not being used there anymore and I have deleted the old variable that it was connected to as well... so I'm left with a phantom device

Please show a screenshot of the variables in RM that you are referring to, and of the portion of your device page in question.

Did you define a time variable yet?

Got it, I assumed it set up a variable based on it's purpose automatically. I've set a global variable and now have the option - thanks

1 Like

OK, set up a rule machine variable as a "time" and mapped it to trigger event. Now in dashboard I've selected the device to control, thdn selected variable time the tile now shows as invalid, then when clicking on it, it says "Invalid date:undefined am"

What did you set the time to when you set up the variable? Can you show a screenshot of your RM global variables setup?

Tried variable with both % and without

First of all, you do not need to put % in front and behind your variable names. In fact, you shouldn't do that. It will just confuse you later. That is how you designate a variable when you want to type it in a field. So, you would have to type %%kettle-on-time%%.

Also, you have not created a GV connector for this variable yet. So, what device did you add to the dashboard? You have to create a GV connector is you want to manipulate a variable on the dashboard.

I would suggest reading through this post on GV connectors and how they work in general. This will be a big help.

Great thanks for that assistance. I've removed the % and the missing step was making a connector which I've now selected as dashboard device. I assumed it was an automatic link as once it was assigned to a trigger it showed up as being linked in the global variable.

The rule is linked to the global variable. Just out of curiosity, what device did you pick in the dashboard before adding the connector?

Bruce, you are freaking awesome! This is great. I've updated my RM color temp rules:

I have noticed a bug with interface when setting a time variable however. I'm using chrome on a mac and I get this:

obviously the update button is cut off, but I also can't really read or see what is in the hours or minutes boxes.

Once I hit done to get the variable created, it doesn't seem to create the variable, until I hit "add another global variable" again, and then the variable appears in the list. Also when I press "add new global variable" that second time, it doesn't allow me to add another global variable, it really just seems to update the interface.

something similar occurs with local variables, but if I just back out of the variable editing screen and then return it updates. Also local variables don't seem to give me a "done" button and I have to click on and off of things before I get the variable to be accepted.

1 Like

That's really crazy!! In Chrome on a PC, when I got to set variable, it comes up like this:

Also, do you have your system set for a 24 hour clock or a 12 hour one? Because I don't see the input for am/pm even though you're in the US.

This is what I get on a Mac running Chrome

Creating the global var (I set this to 12:00pm but took screen shot prior to that)

Updating the var

That is weird. I have my clock set to 24 hours.