Can't figure out how to get a days between events


#1

**1) GivI am trying to get a result of how many days hours minutes since the last rain
(PUT YOUR INFO HERE)

2) What is the expected behaviour?
(Just want a result of days hours and minutes since the last rain

3) What is happening/not happening?
(I get an error message in the log

4)

Post a Green Snapshot of the pistonimage

**5) 9/18/2020, 7:21:01 PM +612ms
+2ms ╔Received event [Home].test = 1600474861609 with a delay of 2ms
+156ms ║Error while getting runtime data: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
+158ms ║RunTime Analysis CS > 43ms > PS > 64ms > PE > 51ms > CE
+166ms ║Runtime (41078 bytes) successfully initialized in 64ms (v0.3.10a.20190223) (159ms)
+168ms ║╔Execution stage started
+184ms ║║Comparison (integer) 70 stays_greater_than (integer) 0 = true (2ms)
+193ms ║║Adding a timed trigger schedule for condition 8
+202ms ║║Cancelling condition #8’s schedules…
+203ms ║║Condition #8 evaluated false (29ms)
+205ms ║║Cancelling condition #1’s schedules…
+206ms ║║Condition group #1 evaluated false (state changed) (32ms)
+235ms ║╚Execution stage complete. (66ms)
+251ms ║Setting up scheduled job for Fri, Sep 18 2020 @ 7:21:21 PM CDT (in 19.944s)
+258ms ╚Event processed successfully (258ms)

What do I need to change?


#2

OOps I forgot to define what last rain was. It is a data from my weather station.


#3


The field Last RainDate is a device that is a string


#4

Well, my first thought is that you have two triggers tied together with “AND”…
(normally, only one trigger can be true at any given moment)

After reducing your triggers to one, then you can capture the current time into an integer.

Set integer variable {lastRain} = $now

Then (in the future), you can set the current time with:

Set integer variable {currentTime} = $now

… and then do math based on those integers.

Log to console = "It has been "round(((currentTime - lastRain) / 3600000),1)" hours."
(IE: It has been 2.5 hours.)


The trick though is, the piston will only update the duration when it is actually running.


Pro Tip:

I kind of mentioned this above, but just to emphasize…
Pistons with a STAY trigger, should only have a single trigger.
(otherwise, other unrelated triggers can break the timer)


Alternatively, you can ditch both triggers, and simply make this a time-based piston.

Every 30 minutes       <-- Trigger
    Check humidity      (set variable etc)
    Check wind speed    (set variable etc)
        IF both are X  <-- Condition
            Then do Y
        END IF
END EVERY

For inspiration, here is a sample log from my time based “Rain Notification” piston:

pic

  • Mine does the math on every run…
  • Writes to the log on every change…
  • but it only alerts me when going from dry to wet (or visa versa).

In the example above, the piston ran 8 times, the log 5 times, and my voice alert came in thrice:

  • 3:47 (beginning to rain)
  • 4:02 (rain stopped)
  • 4:47 (beginning to rain)