Is there a way to have a rule for a specific sequence of triggers?


I’m trying to build logic for my gate but I can’t figure out how to make it work without having a rule that triggers a specific sequence of events. I cannot use union triggers because they mean completely different things.


Door Open > Motion Carpark > Car ON > Car OFF = Leaving home
Car OFF > Car ON > Motion Carpark > Door Open = Arriving home

Appreciate all suggestions!


Use ‘if’, ‘else if’ statements with ‘and’ conditions after the trigger.

To make it more readable sometimes I use boolean variables as the conditions
var Boolean carOn = true
var Boolean motion = true

Use triggers to set the boolean values

if (carOn == true && motion== true) {

some code


You could then use timers to reset the booleans automatically so that the sequence has to occur within a certain time range. This approach can help reduce false gate opening

Could be overkill in your case

For me, Car OFF and Car ON would be good enough for leaving and returning, but I’m lazy.

If you wanted to capture the sequence, in that specific order you will probably need rules which set a series of flags/variables/Items/whatever as the sequence continues (checking to see if the previous flags/variables/Items/whatever are correctly set), and once you get to the last trigger you can check if all your flags/variables/Items/whatever are set correctly, start your scene, and then reset all your flags/variables/Items/whatever. Too much faff for me though…

(This all assumes that the door is no longer open, and/or you don’t see motion in your car park when Car goes OFF. Similar to @m4rk suggestion…)

To make it even more robust don’t forget to think about what to do if an item state is null

I might have simplified the use case for the rule. Opening the gate is just one of the features. I would also like to infer action of the user for other rules (turn on porch lights when arriving vs turn off porch lights when leaving).

Car ON/OFF represents detection of the BLE in the car, does not allow me to determine the state of the human action. When a car approaches driveway from outside, Car ON is triggered. When someone starts the car from within the driveway, Car ON is triggered. But it also gets triggered when someone opens the door because low level power is supplied to the beacon. So just having Car ON offers nothing in automating the above scenario.

Regarding sequencing being complex, Xiaomi Home app has sequenced rules for everything so I just assumed it would be easy to implement in OH.

‘and’ is not useful because the same sensor states in different orders mean different things. Leaving and arriving triggers different automation responses and blind concatenation of the relevant states results in inability to distinguish between different actions.

Your case is simliar in many ways to my garage door operation. My garage door can be operated by key pad, key fob and toggle switch. What the door does depends on what sent the command, its current position and the last direction travel. I have some position information from sensors but not for everything and some is interpreted. eg If the door is opening for more than 30secs then it must be fully open even though I don’t have a sensor for that position.

So, the first step was to create some rules that track the door possible states and store this ‘state’ as a string item.

There can be other clues you can use to help more accuratly assess the situation. eg is the alarm on or off, is your phone connected to your network, time since any activity in the house, day of the week, time of the day, etc etc. It depends on how chaotic your gate useage is :slight_smile:

When the ‘state’ can be accurately tracked you can then proceeed to create more rules that translate a request into actions appropriate for the ‘state’ the door/gate is in

eg for close from Alexa voice command:

State = ‘stopped while closing’ >>> command from Alexa to close >>> translates to toggle switch command of ON (open), pause, ON (stop), pause, ON (close)

State = ‘stopped while opening’ >>> command from Alexa to close >>> translates to toggle switch command of ON (close)

An advantage of this approach is that you can use the phone app to reset the state to the correct value should the tracking get out of sync. debugging, reboot etc

I hope you get the idea.

1 Like

Here is one example. There are others.