Time variable in a restriction?

I have a towel warmer controlled by a switch, and I created a basic rule (call it Rule 1) to turn it on and off each day. The times are set by two Time variables, which I'm hoping will act like time-of-day variables, since I have left the date fields blank (see https://community.hubitat.com/c/rm/about-rm/39.
I would like to have a second automation (Rule 2) for this switch that turns it OFF after a 1 hour delay from a manual turn ON of the switch, but only if it is turned on outside of the ON period of Rule 1. I tried to use a "Restictions" clause on Rule 2, but it doesn't accept time variables for setting the restriction time range. Easy to just enter the required times, but is there a better way?

1 Like

Use a local Boolean. In your rule 1, add an action to set local Boolean for rule 2.

Then in rule 2, add a restriction base on local Boolean

1 Like

So, as a newbie, I took the following actions:
(1) In Settings>>Hub Variables, I created a boolean variable "Towel Timer is timing"
(2) After a lot of frustration, I discovered I needed to install "Rule Machine" to get the kind of logic capability I needed (I had only Basic Rules and Simple Automation Rules installed),
(3) I created a Rule triggered by time = 5:00 AM with two actions: Turn on the Towel Warmer and set my boolean to true. I created a second rule to reverse those actions at 11:00 AM.
(4) I created a third rule with a precondition that my boolean must be false, with the subsequent trigger Towel Warmer turns on, and an action to delay 1 hour then command Towel Warmer off. But then I got this confusing line:
"Variable Towel Timer is timing(false) = false(T) [TRUE]"
Huh? There's two falses, a T and a TRUE in this line and I don't have a clue what it means. My goal here is to be able to turn on the towel warmer for an hour as long as I'm not in the morning timing cycle. Have I accomplished that?

The first (false) is just there to help confirm that your variable statement is currently not timing.

The (T) at the end is just there to tell you that this entire line is currently true.

Without the items in the parentheses you’d simply have the condition as you wrote it:
Variable Towel Timer is timing = false

I believe you can toggle on/off the current state parentheses near the bottom of the page however once you get used to them I find they are quite useful just to help keep track of everything

1 Like

My apologies for not pointing out rule machine. That’s all I have ever used, so I did not know the limitations of Basic Rules.

A few tips:

If you do not need to have the state available to other rules, you do not need a global variable. Every rule in rule machine has a variable called Private Boolean. There is an action called « Set Private Boolean », and you can set those for the current rule, but also any other rule. You can use that to have one rule disable or enable another rule.

If you do need some global state, I found that using Virtual Switches is a lot more convenient than using global Boolean variables. Switches can be added to dashboards, and you can easily toggle them manually if needed.

You do not need to have 2 rules for your main automation. You can start your action at the desired time, start the towel warmer, set the private Boolean, then add a Delay, Wait or Exit command, and either wait for the desired duration or desired event, then stop the towel warmer and change back the private Boolean of that other rule.

As an example, below I have a rule that starts at 1h00 or 12h00, and will trigger different virtual switches after 3, 5, 9 and 10 hours.

You do not need to have 2 rules for your main automation.

Figured there must be a way, so I created a Basic Rule that was close, then converted it to Rule Machine one and modified it from there:

As for my Rule #2, I have:

Still learning to love how Required Expressions look, and I didn't see a way to simplify them. Also, I find myself in screens with no "back" button, nor anyway to even get out of them, so I'm forced to use the browser back button, warning or not.

And I want to thank both of you for helping a newbie who has near-perfect ignorance of how Hubitat creates programs. Frankly I was hoping to see logic created with a simple IF (boolean expression) THEN (actions) ELSE.... with perhaps an ELSE IF and parentheses thrown in. I'm a refugee from Insteon/ISY944i home automation, and that's the paradigm for state machines they used, and I'm just used to it. But I'll get with the program and work on become more proficient with the app creation process, and hopefully become more valuable to the community.

So I made a little progress on my learning curve for formulating Rules, and I have a much simpler solution using two global booleans:
Rule #1:

Rule #2:

I have those global booleans displayed on my dashboard, thanks to this thread:
https://community.hubitat.com/t/authorizing-a-variable/106677

Note that when Rule 1 triggers, it also triggers Rule 2, but Rule 2 doesn't prematurely turn off the towel warmer because of the conditional clause.

And Rule 1 really needed to be:

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.