Variable Help: If event occurs X number of times do Y


#1

1) Give a description of the problem
I would like to make a piston that is capable of turning on a variable based on a motion sensor changing from inactive -> active a set number of times.

2) What is the expected behavior?
Example: If Motion sensor is changed to active X number of times then set variable to true. This variable in turn would be used to control other functions.

3) What is happening/not happening?
I do not see a way of writing a piston to count motion events. I would think this could be accomplished with some variable, but I am still new to webcore and was wondering if anyone had any tips they could provide!


#2

Actually, you could just do something like this. So every time the motion sensor changes to active it will add to the counter. (Note that the counter starts at 0). The reset value that you have configured on your motion sensor will determine how frequently this gets triggered. Then you’d just have to add what you want to do and whether or not you want to reset the counter back to 0 at some point.


#3

I think that is exactly what I was looking for. I will have to take that example you provided and try it out!

I greatly appreciate the assistance with this! I was not even aware of that counter function.


#4

So here is an an example of what I am trying to do. I am new to the use of variables. I have defined Light, Medium and Heavy Traffic as simple Boolean (True/False) variables. But I also want light, medium and heavy traffic to initiate a setting which then keeps the light on. Would it be better to use a different variable other than Boolean for those or do I simply have to ensure light, medium and heavy turn on something else (like a switch)?


#5

Here is another example of what I am trying to do. Just do not quite know how to do it yet.


#6

Was able to make this without the use of any variables. This would be for a single room. My intent is to define the light, medium and heavy as variables that could be used in different pistons for all of the rooms in the house. The keypad acts as a switch to keep the light on regardless of motion detection and is set to turn off after a set period of time regardless of activity in the room. The other keypads are for checking the occupancy in another room (If you moved to a new room and triggered the count variable), which if activated turns of the original’s room lights.


#7

Technically it’s not a function, it’s just using an integer variable and adding 1 to it… You could name the variable whatever you like. I just happened to use the word “Counter” for the variable name.

I’m still not certain I understand what you’e ultimately doing…but don’t forget that at some point you need to reset the Counter back to 0 otherwise it’s useless. Especially since you are testing for = 3 and not >= 3.

Also, it’s a local variable, so it only have value in this piston. But you could make it a global if you wanted it to retain its value across all pistons. Read this for assistance on the differences:

https://wiki.webcore.co/Variable