Hello,
I have a magnetometer in my driveway which is utilized to detect the presence of a vehicle entering or exiting. I wired the receiver for the magnetometer to a simple z-wave contact sensor. This way whenever a vehicle crosses the sensor, hubitat sees this contact open and close. I use it to turn the lights in the garage on when a vehicle is approaching, trigger security cameras, and send a notification to my phone.
When the magnetometer sensor has a low battery, it reports twice in a row. This means my contact sensor reports open-close-open-close for each 'trigger' from a vehicle. I am trying to create a rule machine rule that sends me a notification if it sees the sensor report "open" twice within 3 seconds, but more than one time in a day. The reason for this is because in rare events it will report twice quickly even if it isn't trying to communicate that it has a low battery - so I don't want false 'low battery' alerts. I imagine this requires a variable or two? Appreciate anyone who wants to help. Thanks!
I was latly in a need for a double pulse sensor trigger. Meaning, a sensor will turn active only if it an alarm sensor was active twice within a short period.
I got help from the comunity and ended up with creating a virtual sensor that is changed to ACTIVE (and then auto INACTIVE within 5 seconds - defined in the virtual sensor itself) only if the real sensor reported ACTIVE twice in 7 seconds.
If you follow this logic and create 2 virtual sensors (VS).
VS1 - turns ACTIVE only if your real contact sensor reports open twice in 3 seconds.
VS2 -turns ACTIVE only if VS1 reports ACTIVE twice in say in 24 hours.
This is how the rule looks in my system for what would be your VS1 rule.
VS2 rule would be using the same logic.
Here's an option to try using a local string variable (LastEvent) and a local number variable (count).
Required Expression
Private Boolean is true
Local Variables
LastEvent
count
Trigger Events
Contact Sensor is closed
Actions to Run
Set Private Boolean false
Wait for event: Contact Sensor is closed --> timeout: 0:00:03
Set LastEvent to %device%
IF (Variable LastEvent <> 'timeout') THEN
Add 1 to count
IF (Variable count > 1) Notify...
END-IF
Set Private Boolean true
Wait for event: When time is 12:00 AM
Set count to 0
Note that the second IF is a simple condition so no THEN or END-IF. The last Wait will reset the counter to 0 for the next day.