Datetime data type mismatch?


#1

I have a piston that is designed to take input from a motion sensor near my driveway (connected via a z-wave contact closure) and, when it’s activated, send a push notification and activate a chime in the house. I also would like to receive only one push/chime event per 5 minutes, since this motion sensor can be repeatedly triggered by people walking around, etc.

The code I’ve written for this does not successfully inhibit multiple notifications. I will get as many notifications as there are contact closure events. It appears that there’s an evaluation error when I attempt to compare the value of the previous alert DateTime value with the $now - 5 minutes value. Please see the below code and log entry, paying particular attention to the time values in the comparison at +565ms in the log.

I’ve also tried changing my LastNotification variable data type to an integer and a long, with similar results.


#2

Try wrapping LastNotification in datetime().


#3

Looks like the same behavior with that change :frowning:


#4

Will have to play with it some.

In the mean time, you can just set a boolean variable to true for the 5 minute cooldown period then reset it to false after.


#5

I actually was using that method (set to true, wait 5 minutes, reset to false) for a few years, but for some reason every now and then the task must have died before resetting to false, because the variable would be stuck in the true state and the piston would never send the notification until the variable was manually reset to false.


#6

Ah, there were some problems with ST a week or two back when pistons that were running fine suddenly started skipping events.

I still am curious about your piston though, hope to play with it some when things settle down at work.


#7

Sounds good. Thanks for taking a look here.


#8

For whatever reason, this is working now. I haven’t changed anything in the code…

Comparison (datetime) 1571230463380 is_before (datetime) 1571230333815 = false (2ms)