SmartThings Community

State Changes twice or X times?



So lately I have been getting a lot of triggers from my Vibration Sensor. Single triggers possibly caused by gusts of wind? Large truck? Or so…

I plan to setup a Piston in order to take care or it. Everythjng is set up however I cannot figure out how to set it to trigger if for example the state changes 2 times of 3 times.

I see that i can use IF “Active” for 1 minute. However the way the vibration sensor works is more like bursts.

(Jason "The Enabler" as deemed so by @Smart) #2

I would use a variable. Do a search here.


I am assuming but that you mean:

On state change X=X+1

If X = 2 then TRIGGER.

If after 5 minutes X is SAME then X=0.

I think its a bit of an overkill. Am i assuming wrong? Isn’t there perhaps an easier way of doing it?

(Jason "The Enabler" as deemed so by @Smart) #4

Yeah, something like that.

I don’t worry about ease of setup… What’s most reliable for the use case.

(Robin) #5

I haven’t tested it but I think something like the following would work:

If memory serves the THEN IF’s reset after about 10 seconds so should work nicely.

The above works for button presses when entering a pin code, don’t see why it won’t work for vibration.


Wonderful! Thanks. Will test it soon.


It didn’t work. Instead it waited until it hit 3 vibrations in a row and then it triggered. Regardless there was hours in between.

So I opted for this instead:

However I am unsure my if my logic is correct. Will it clear every 5 minutes? Or will it run every time and every time it will wait 5 minutes and clesr the variable, causing it to never trigger? Please advice. Is this the proper way to add a wait time?


I didn’t work. Whatam I doing wrong? Is that not the way to clear tge variable after 5 minutes?

(Robin) #9

When using expert mode you need to avoid using triggers and conditions in the same piston (dots and circles).

Also, as CoRE calculates conditions immediately upon trigger, it will not fire the notification on 3rd vibration as the counter will still be on 2 (for another half second).

Suggest you use a global variable (put an @ symbol in front of the variable name) and then do this in two Pistons, one for the counter and one for the notification.

Notification piston could be:

variable @X changes to 3
Door is not open
|> Send notification
|> Set variable @X to 0

You also need to initialise the variable to 0 as it defaults to ‘null’. Null+1=null.

You can watch the Pistons working and the variable changing in real time using the CoRE web dashboard… Dashboard view is also better for screenshots of your Pistons.


But what about restting it? I want to reset the variable IF there is no 3 consecutive motions in 5 minutes.

(Robin) #11

You should be able to do that as a seperate IF block in the counter piston.

motion IS active
® when variable @X is less than 3
|> set variable @X + 1

motion does not change for X minutes
|> set variable @X = 0

The reason it wasn’t working in your example above is because you mixed triggers and conditions whilst using when true (expert mode) options. Needs to be all black dots or all black circles, don’t mix.


How do i setup the does NOT change?

Also lost me abit with black circles and dots lol


How’s this?


Should it be in an AND or perhaps in a THEN IF? The not changes part.


This seems to make more sense: