Scheduling lights with more randomness

@dan.t In webcore, I was able to do something similar in one piston. I was just curious if I was missing something when using rule machine.

So it's safe to assume that Hubitat users will have a ton of rules? I currently have around 30, and it's only been 2 weeks since I started using it.

It all depends on needs but yes, some will end up with a ton of rules. I would always follow the KISS principle when it comes to rules. Quantity really makes no difference.

Yes, it takes some time to get used to RM when you come from WebCore. I did the same quite some time ago but I believe with RM3 and RM4 it became much easier. By now, I don't wish to go back.

And you can always write a "simple" App if you have a REALLY difficult use case. I had one of these and the app is running for months now...

You set it for whenever you want.

Set up different routines for different times of the day (morning, evening, weekends). Try to match what you would 'normally' do.

It will finish whatever is still in the que (not the entire routine) then turn the lights off as they finish. Not all at once, nor will it freeze.

@SmartHomePrimer I definitely agree with you. This is part of the reason why I wanted to create something easy out of rule machine but was confused that I'd need a number of rules to get this done.

A normal day is at 5 am, our main lights turn on. Turn off at around 10am. Turn back on around 4pm, then back off at around 10pm. Bedroom lights turn on at around 7am, turn off at around 8:30am. Then turn on again around 4pm, then back off around 10pm. The randomness I was seeking is when the lights initially turns on and when they finally turn off. I wanted to avoid the "Home Alone" situation.. 5am sharp, lights turn on. 10pm sharp, lights turn off. I don't remember the last time I turned off lights when I left a room! Probably since the advent of LED bulbs or CFLs. Who am I kidding, I never turned off lights when I left rooms. I was a bad kid.

I was able to create something with 4 rules with a number of delays and some random delays. I'm not quite sure if they work yet though.

See my PM for how to schedule various lights in a single rule.

@dan.t The trigger and action of RM did throw me for a loop since webcore can subscribe to multiple events within the same piston.

I got my Hubitat between the revision of RM4 when the restrictions were removed. I noticed some of my rules had restrictions dropdown and some didn't. I couldn't figure out how to get it back until I learned that they were removed. I thought I was going crazy. Now I'm getting brain lock when trying to figure out "If (NOT Mode in evening, night) then exit rule." Don't get me started when I try to add a second NOT condition.

It takes some time to get used to it, for sure. Think about one step at a time. Like this:

no need top combine them, the rule runs top to bottom.

This is an interesting screenshot. I didn't realize there was a specific IF (NOT blah) exit rule action. I now see that using the simple condition is what I need to use. I was using If (NOT blah) then exit. When I add a second IF statement, it nests it below the previous if statement. It probably should still work but kind of looks terrible.

The top to bottom threw me for a loop too!! When you create multiple actions in sequence with the delay option turned on. The rule does not wait until the delay completes before proceeding to the next action.

Thank you for all your help!

Yes, that is by design that way. If you specify a delay on an action only that action will be delayed. There is another action that is called "Delayed Actions"


that will delay all actions following this action. Basically makes the script "pause"

Just in case you are interested I have a rule that when we are away, and between certain time of the day, it turns on the Hall downstairs light, waits a few seconds then turns on a Loo light.
After a small amount of time the Loo light turns off and a few seconds later the hall light.
It's pretty straight forward and here it is.

image

Thank you for this. A little earlier, I was just thinking about how I could consolidate my different time scheduled rules by adding multiple time based triggers into one rule, then creating if/then statements checking the time like what you posted.

Just out of curiosity, I am wondering if the 2 endif's need to be there or is it not necessary in this rule. I thought one should be after END-REP and another at the very end. Still trying to get when and where they should be put in. thanks

I see what you are saying. :thinking: I think logically there probably should be another END-IF after the last END-IF.
It does seem to work though.

The last end if can be omitted if there is not following action. RM is forgiving when it comes to that

That is what is baffling about this. It is hard to tell if they are needed because like you said it runs OK. I dunno! The reason I asked about it being 2 endif's missing was the fact you have 2 IF's and a endif but only 1 endif at the end. Go figure! :grinning:

So you are saying the only endif can be eliminated? That makes it even more confusing! :smile:

Technically, you can also forget the END REP if it is the last entry for the rule. I for one, would recommend to always add them, no matter what. That takes all the confusion out.

Wow, another question would be that if you do add the proper number and placement of endif's could that cause the rule not to run correctly?

What exactly is the rule of thumb on this?

If you do NOT add the proper once, yes it can.

Here are some examples:

----START OF RULE
START REP
    DO REPEATED ACTION 1
	DO REPEATED ACTION 2
END-REP
----END OF RULE

Is the same as:

----START OF RULE
START REPEAT
	DO REPEATED ACTION 1
	DO REPEATED ACTION 2
----END OF RULE

However, let's say you want to execute one more thing AFTER the repeat finished, that would correctly look like this:

----START OF RULE
START REP
	DO REPEATED ACTION 1
	DO REPEATED ACTION 2
END-REP
DO ACTION THAT IS NOT REPEATED
----END OF RULE

Here, the END-REP is very important. If the END-REP wouldn't be there that last entry would become part of the repeat and would be executed with the repeat over and over again.

It would be executed as this:

----START OF RULE
START REPEAT
	DO REPEATED ACTION 1
	DO REPEATED ACTION 2
	DO ACTION THAT IS NOT REPEATED BUT I AM DOING IT REPEATED SINCE I FORGOT THE END REP
----END OF RULE

Which is not what you wanted. It is literally limited to what is the last entry of the rule, not just of the repeat or the if. Bottom line, get into the habit of adding the END-IF and END-REP and you will protect yourself of the rule doing something that you didn't want it to do

Add the proper END-... and your thumbs stay intact

Nice. Thanks. I will continue to add them just in case. So far I have all working correctly. I do see the differences in what you are saying. Knowing about the last entry helps.