Rule Advice

Migration from ST is going well. 16 devices so far. I am starting to play with rule machine and would like some advice.

I have a boiler that i only allow to run when power is cheaper. So I need it to come on for a few hours then go off, then on again overnight then off in the morning. Then on weekends the times are different.

On ST i just used a bunch of individual smart lighting commands, I can do that again with hubitat simple lighting but was wondering if a type of rule may be better?

With a rule you can set multiple conditions. So you can add multiple time periods to a single rule.

Example...

Conditions:
Time between 6pm and 7pm
Time between 10pm and 11pm
Time between 4am and 5am

Rule:
Time between 6pm and 7pm
OR
Time between 10pm and 11pm
OR
Time between 4am and 5am

Actions when True:
Turn on switch

Actions when False:
Turn off switch

You can get more advanced with days of week too. If the 6-7 window was for weekdays only, 10-11 window was for weekends only, and 4-5am was for any day, it would look like the following:

Conditions:
Time between 6pm and 7pm
Time between 10pm and 11pm
Time between 4am and 5am
Day of week Saturday, Sunday

Rule:
(Time between 6pm and 7pm
AND
NOT(Day of week Saturday, Sunday))
OR
(Time between 10pm and 11pm
AND
Day of week Saturday, Sunday)
OR
Time between 4am and 5am

Actions when True:
Turn on switch

Actions when False:
Turn off switch

2 Likes

Thanks! I'm still figuring out the way this rule machine works, I will try this tonight after work. In the meantime I did it in simple lighting but will definitely try this.

I wish it was all ladder logic, thats what I'm used to LOL

1 Like

I was kind of put off at first too but once you play around with it then it's not too bad.

1 Like

This should work? If it does it's not as hard as I thought. Once you get your head wrapped around the conditions and wording.

What you have there is close but may not function as you are intending. You need to enable the complex input option when you define the rule so you can group conditions using parenthesis. The parenthesis matter a lot, and note the double-parenthesis in some places below, they are not a typo.

Looks like you are wanting 7am-12pm and 4pm-11pm on the weekends. Does 12:02pm - 3:58pm and 11:02pm - 6:58am apply only to weekdays or every day?

If the 02-58 time periods apply only to weekdays, set it up as follows.
((Time between 7:00am and 12:00pm
OR
Time between 4:00pm and 11:00pm)
AND
Day in [Saturday,Sunday])
OR
((Time between 12:02pm and 3:58pm
OR
Time between 11:02pm and 6:58am)
AND
NOT(Day in [Saturday,Sunday]))

If the 02-58 time periods apply to all days, set it up as follows.
((Time between 7:00am and 12:00pm
OR
Time between 4:00pm and 11:00pm)
AND
Day in [Saturday,Sunday])
OR
Time between 12:02pm and 3:58pm
OR
Time between 11:02pm and 6:58am

The intention:

7am-12pm and 4pm-11pm only on the weekends.

12:02pm - 3:58pm and 11:02pm - 6:58am seven days a week

Im pretty sure i enabled complex rule option.

Do you really want the switch to turn off for 2 minutes then turn back on, Saturday and Sunday? Or do you just want it on full time on the weekends?

And once you enable complex input, you have to specify "Enter sub-rule" left or right to get the parenthesis to show. At least I think that's what it's called...typing from memory here.

AAAHH take two

( ( Time between 7:00 AM AST and 12:00 PM AST
OR
Time between 4:00 PM AST and 11:00 PM AST )
AND
Day in [Saturday, Sunday] )
OR
Time between 12:02 PM AST and 3:58 PM AST
OR
Time between 11:02 PM AST and 6:58 AM AST

1 Like

Ideally it could run from Friday at 11:02PM until Monday at 6:58AM

The 2 minute offset is there just to buffer any error between my time and the power company's time

1 Like

That makes more sense. Then you don't really need specific time periods on the weekends, you can just say:

Day in [Saturday, Sunday]
OR
Time between 12:02 PM AST and 3:58 PM AST
OR
Time between 11:02 PM AST and 6:58 AM AST

For this rule, you don't even need complex rule input :slight_smile:

1 Like

OMG are you kidding me, you are right! I was so used to doing it with individual rules this escaped me!

1 Like

Yeah sorry about that, I should have realized a couple posts above that it might be your intention to run full-time on the weekends. I was thrown off by the gaps in time periods that made them non-continuous.

Thanks for the help, at least now I know about the parenthesis.

Cheers

PS: Another thing im trying to do is turn on my outside lights when me or my wife arrrive between sunrise and sunset but turn off 5 minutes after? I dont see arrival as an option in rule machine? Just presence.

Ill start a new topic

1 Like