Help with logic please

What I want to achieve is 'If the garage door been left open for over 10 minutes then run rules otherwise if closed before 10 minutes of being open then exit rule'. I also wanted to restrict the 'Notify' action to Day Mode only but I couldn't find an option for this (other than ' At Specific Time') let alone know where to include it in the logic.

I swear I've spent a couple of days trying to get this to work using my limited knowledge but I just couldn't.

About the logic:

  • The 'VS GarageSwitchClosed' is a virtual switch pointing to my eWelink garage door opener which I integrated throught IFTTT - I need to turn it off first then on so it closes the garage door hence I included this in my logic.

  • 'Wait for event: elapsed time: 0:00:16' I included this because 16 seconds is how long it takes for the garage door to fully close

What works:

  • Lights change to red, notification to my phone and sonos speaker are sent, garage door gets closed, lights state is restored per Mode in the end

What doesn't work:

  • Rules run despite the fact that the garage door was closed before 10 minutes of being opened. For instance, Actions for the 'ELSE-IF' condition are run first then actions for 'IF' are run even though I opened and closed the garage within 3 minutes.

If someone could assist it'd be great.

Thanks in advance

Add an "if" there after the 10 minutes and check if the garage door is still open. Right now that check is only happening when the garage door opens / closes and doesn't check again if it's been closed after less than 10 minutes.

Do you want to do the stuff in the else-if if it closes in say 5 minutes? If so, leave it where it is. If you're looking to only do that closing notification if it closes after 10 minutes you're gonna need some kind of global variable.

Thanks for the quick reply :slight_smile:

Would I need an 'END-IF' followed by the IF-THEN as well like so:

I'd like the whole rule to exit/cancel if the '10 minutes' condition isn't met therefore the ELSE-IF block would only run if all the logic above it were true. For instance, if I open and close the garage door within 9m59s then literally nothing happens.

@hpgurgel an option is to track the state of the door with a local Boolean variable DoorOpen set initially as false.
Add after 10 minute Wait for event: Set DoorOpen to true
Add second condition to ELSE-IF: AND Variable DoorOpen = true
Add in ELSE-IF actions: Set DoorOpen to false

I think you'll have to make it a second if in there.

else-if garage door is closed then
if DoorOpen then
... do stuff here ...
end-if
DoorOpen = false
end-if

@jcarreira I don't believe you do. If the door closes before the 10-minute wait is up the rule will retrigger and DoorOpen won't get set to true. The rule will fail the ELSE-IF condition and do nothing per the OP request.

Good call, I was thinking of setting the DoorOpen to true before the 10 minutes

Thanks heaps guys, much appreciated - I'll give this a shot tomorrow and let you know how it goes.

It appears to have done the trick:

Thank you so much again - Would you please be able to recommend some decent resource for learning logic? I want to be able to learn this properly so I am not having to be bothering the community every time. I've had a look a some rules examples from ' RM4 - List of example rules' but I struggled to get my head around them.

The other thing I wanted to achieve is to restrict the announcements between two times of the day - What would be the best logic for this please?

You'd have to add more conditional if...then logic around the notifications, but you're starting to get into complicated territory. Might be better to pull the notifications out and use the Notifications app where you can easily set restrictions like this. You could have a virtual switch instead of the variable and notify on that being turned on.

For learning how to do logic... not sure... look at some classes on basic coding?

Aristotle’s Syllogistic in the original Greek.

Edit: in all seriousness, @hpgurgel, it doesn’t seem that you really are asking about learning logic, but instead about using Rule Machine. Learning Rule Machine is not just about learning Boolean logic (AND, OR, NOT, XOR, etc) and conditional branching in code. Any basic book about computer programming can explain those things.

The difficulty, though, at least it was to me, is understanding the event nature of Rule Machine, and how WAIT and DELAY variants operate, and how triggers interact with your rule. It’s the concurrent events that are difficult to comprehend, especially if your experience is with single-threaded execution, in which only a single process is executing the code at a moment in time, as contrasted with Rule Machine’s design, in which a new process thread instance starts concurrently executing the rule each time the rule is triggered.

WAITs and DELAYs or END-REP (for a time-repeat) don’t spin or stop execution of the rule until their time condition or event condition is satisfied. Instead, they schedule an event on the particular condition, stop, then resume when the scheduled event occurs. A “Stop Repeating Actions” or “Cancel Delayed Actions” simply unschedules the scheduled event(s).

The Rule machine documentation seems to have recently been substantially updated. I believe you might find what you want by reading that revised documentation:

https://docs.hubitat.com/index.php?title=Rule-4.0

See if that doesn’t help.

Thanks for the comprehensive response @672southmain, that's much appreciated. I'll read through the documentation as advised along with some programming logic online resource as I feel like I need to become more familiar with those basic concepts and terminologies.

@jcarreira , I've just had try at the Notifyer app and it should help me achieve what I am after. Thanks again for your advice... I am slowly but surely getting there...

Have a great day guys (bed time for me now here in Australia).

1 Like

Hello again gents,

So I've realised that I needed to add a motion sensor to the mix as I found myself having to re-open the garage door when I am doing work there.

I had a read on the documentation for the RM and tried putting it into practice but it appears that I'll have to try harder.

I've spent a few hours now trying to get the logic to work but I still can't do it - RM skips some of the code and I don't get why.

This is literally the last bit I need to add to this rule to make it work nicely for me - Please can you assist? @jcarreira @pseudonym @672southmain

Here's the rule:

Here are the logs:

Thanks again in advance.

I really don’t understand what you are trying to do with this rule, but it appears that you misunderstand how IF .. THEN and ELSE-IF statements work. The way you have it set up doesn’t make sense.

An IF .. THEN followed by a series of ELSE-IF statements (as you have) is for mutually-exclusive situations.

So, just as an example, your first IF condition is executed if Spare - Motion Sensor is inactive.

If so, you are going to wait for 30 seconds (not sure why) and then, because the IF was satisfied, none of the remaining ELSE-IF in the rule will be tested. The rule will simply exit, which is what the logs show.

Instead, if that first IF had not been true, the sensor must have been active, so the next ELSE-IF will always be true, and the test for the sensor active is redundant. Regardless, you then cancel all delayed actions, which does nothing because you have no delays in your rule. Even if you did, the delays would have to be marked cancellable in order for the cancel all delayed actions to do anything.

Then, because you have exhausted the two possible tests for the sensor (inactive, active), there is no way that any of the following ELSE-IF will ever be tested or executed.

Perhaps it would help us to help you if you forgot about the rule and instead stated what you are trying to accomplish. Then someone may be able to suggest a solution.

1 Like

@672southmain here's some info on the rules as requested:

This is what I have and it's working as expected:

And these are the changes i am attempting to make.

Please can you assist? I'll also try and use some of the tips you gave above once I get a chance to.

Well, let's discuss general principles first.

I'm gonna say that I'm generally less of the mind to figure out every case and have the rules do everything for me and more of the mind of having it tell me what I need to know to make decisions for myself. I have rules around my garage door, too, and I sometimes use my garage as a workshop, so I also don't want it just closing on me because it's been open for a while. I've got mine alerting me if it's been open for 30 minutes. I've got rules that close the garage doors when the mode goes to away or night (and I think this is probably what you really want).

I also don't have any rules as long as the one you've got there.

My advice is to apply the KISS principle. Keep your rules simple and they will be simple to implement and understand. Don't try to code for every possibility.

If you still want to implement this rule, LMK and we'll try to figure it out.

Here's a pretty simple rule I use but it's the old 3.0 rule

have been using it for years (hence the 3.0) I use a virtual switch that I turn on via google if I'm going to be working out there or in the driveway. I use a lot of these virtual switches for things. You could easily convert that to a motion sensor or just have that motion sensor trigger a virtual switch. Then you could use both.

@hpgurgel Try this. To your previously working rule,
Add a trigger Spare - Motion Sensor active
Add as the very first line Wait for condition --> Spare - Motion Sensor inactive
I don't believe you need the 16 second wait, I don't see what it's doing.

The rule won't evaluate the condition of the garage door until motion is stopped and will take advantage of the 10 minute Wait for event if the door is open. I think this should work. Give it a try and report back.

1 Like

@pseudonym You must be sort of sniper when it comes to RM - You were absolutely precise with it again.

I tested it and it's now working like magic - I just added a Time-out for the sensor too.

The Wait: 16 seconds was removed as well.

Here's what it looks like now:

Here are the logs I captured( using the test rule):

@672southmain Thank you so much for giving me a comprehensive breaking-down of my mistakes on the original rule - This has definitely helped me with my learning.

@jcarreira Thanks a lot for offering help again, that's much appreciated. I shall keep in mind the KISS approach for future rules.

@jrfarrar I really appreciate you sharing your existing rule too - I would have attempted to implement it if I hadn't got mine working.

You are all absolute legends, thanks again for your efforts.

By the way, I've signed up for SkillShare as I am determined to explore the coding/logic space further & I hope I'll be able to help others in the future.

Cheers.

1 Like

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