Expression for current time not refreshing

Hi Patrick et all!

Not sure what I’m doing wrong here (I’ll include my logic summary). But I have 2 reactor sensors, each that trip whenever I or the wife are at home, (one for each of us). They seem to be working fine… They stay tripped when we enter the geofence, and untrip when we exit.

So… I’ve setup a 3rd reactor sensor that is designed to “trip” for 30 seconds based on the state of the 2 sensors above. I do this by setting up 4 expressions… two of the expressions check the “lasttrip” time of the sensors above that determine if we’re home or not.

The 3rd expression checks the current time,
the 4th expression calculates the time that has lasped between “now” and the “lasttrip” time.

I use this 4th expression as a condition, so that my reactor sensor only stays “tripped” for the 30 seconds past lasttrip time.

Problem is, I’ve noticed the expression that calculates the current time “tnow” doesn’t seem to refresh. If I hit the “reset” button on the reactor sensor, it refreshes, but otherwise it just displays static number.

Is there a prescribed time interval that expressions are evaluated? or how can I get the tnow variable to refresh properly so my condition goes false (and the sensor untrips) after 30 seconds has lapsed?

logic summary for 3rd sensor

*************************************************** REACTOR LOGIC SUMMARY REPORT ***************************************************
   Version: 3.2 config 301 cdata 19082 ui 19143 pluginDevice 23
    System: Vera version 1.7.4453 on Sercomm G450; loadtime 1560218556; systemReady 1560218572; ALTUI v2.43; Lua 5.1
Local time: 2019-06-11T07:18:08-0600; DST=1
House mode: plugin 1; system 1; tracking off
  Sun data: { "stamp": 2019162, "civdawn": 1560249419, "nautdawn": 1560245325, "sunset": 1560311300, "nautdusk": 1560318136, "latitude": 50.80855, "astrodusk": null, "longitude": -113.9485, "civdusk": 1560314042, "astrodawn": null, "sunrise": 1560252161 }
  Geofence: running in quick mode, last update 05:48:00, data version 2
            User 2342071 ishome=1 inlist= since=20:04:00
            |    1 "40 Norris Coulee Trail, De Winton, AB T0L 0X0, Canada De Winton" type="home" status="" since=05-14.06:35:00
            User 2338371 ishome=0 inlist= since=05:48:00
            |    4 "40 Norris Coulee Trail, De Winton, AB T0L 0X0, Canada De Winton" type="home" status="out" since=05-15.19:34:00
            Raw: { "updated": 1560259080, "users_settings": [ { "id": 2338371, "ishome": 0 }, { "id": 2342071, "ishome": 1 } ], "mode": 1 }
GeoTrigger Entry (#88)
    Version 19082.39 06/11/19 07:02:41
    Message/status: Not tripped
       0: ConnorLastTrip           getstate( 42, "urn:micasaverde-com:serviceId:SecuritySensor1", "LastTrip" )*1 [last 1560253681(number)] (exported)
       1: PookyLastTrip            getstate( 87, "urn:micasaverde-com:serviceId:SecuritySensor1", "LastTrip" )*1 [last 1560218641(number)] (exported)
       2: tnow                     time() [last 1560258191(number)] (exported)
       3: SeondsSinceTrip          tnow - max(ConnorLastTrip, PookyLastTrip) [last 4510(number)] (exported)
    Condition group "Reactor Sensor 13" (AND) false as of 05:48:02 <root>
      &-F-service GeoTrigger Entry (88) urn:toggledbits-com:serviceId:ReactorValues/SeondsSinceTrip <= 30; delay reset for 1s [4504 => 4510 at 07:03:11; F/F as of 07:00:44/07:00:45] <conde7e5kt7>
      &-T-group "grpe80unq0" (OR) TRUE as of 07:02:43 <grpe80unq0>
      |     |-F-service Connor is Home? (42) urn:toggledbits-com:serviceId:ReactorGroup/GroupStatus_root istrue  [1 => 0 at 05:48:02; F/F as of 05:48:02/05:48:02] <conde7e6ew2>
      |     |-T-service Pooky is Home ? (87) urn:toggledbits-com:serviceId:ReactorGroup/GroupStatus_root istrue  [1 at 07:02:43; T/T as of 07:02:43/07:02:43] <conde80v3hz>
    Activity grpe788u5q.true
        Device 88 (GeoTrigger Entry) action urn:toggledbits-com:serviceId:ReactorSensor/Reset(  )
        Device 88 (GeoTrigger Entry) action urn:toggledbits-com:serviceId:ReactorSensor/Reset(  )
        Device 88 (GeoTrigger Entry) action urn:toggledbits-com:serviceId:ReactorSensor/Restart(  )
        06/10/19 22:18:02 condchange: newState=true, cond=conde7e6ew2, oldState=false
        06/10/19 22:18:02 evalchange: newState=true, cond=conde7e6ew2, oldState=false
        06/10/19 22:18:02 condchange: newState=true, cond=root, oldState=false
        06/10/19 22:18:02 evalchange: newState=true, cond=root, oldState=false
        06/10/19 22:18:02 devicewatch: device=88, old="0", name=GeoTrigger Entry, var=urn:toggledbits-com:serviceId:ReactorGroup/GroupStatus_root, new="1"
        06/10/19 22:18:02 devicewatch: device=88, old="1560223552", name=GeoTrigger Entry, var=urn:micasaverde-com:serviceId:SecuritySensor1/LastTrip, new="1560226682"
        06/10/19 22:18:02 sensorstate: state=true
        06/10/19 22:18:03 variable: oldval=1560226682, variable=tnow, newval=1560226683
        06/10/19 22:18:03 variable: oldval=1, variable=SeondsSinceTrip, newval=2
        06/11/19 05:48:01 devicewatch: device=42, old="1", name=Connor is Home?, var=urn:toggledbits-com:serviceId:ReactorGroup/GroupStatus_root, new="0"
        06/11/19 05:48:01 devicewatch: device=42, old="1560226681", name=Connor is Home?, var=urn:micasaverde-com:serviceId:SecuritySensor1/LastTrip, new="1560253681"
        06/11/19 05:48:01 devicewatch: device=42, old="1", name=Connor is Home?, var=urn:micasaverde-com:serviceId:SecuritySensor1/Tripped, new="0"
        06/11/19 05:48:02 variable: oldval=1560226681, variable=ConnorLastTrip, newval=1560253681
        06/11/19 05:48:02 variable: oldval=1560226683, variable=tnow, newval=1560253682
        06/11/19 05:48:02 variable: oldval=2, variable=SeondsSinceTrip, newval=1
        06/11/19 05:48:02 condchange: newState=false, cond=conde7e6ew2, oldState=true
        06/11/19 05:48:02 evalchange: newState=false, cond=conde7e6ew2, oldState=true
        06/11/19 05:48:02 condchange: newState=false, cond=root, oldState=true
        06/11/19 05:48:02 evalchange: newState=false, cond=root, oldState=true
        06/11/19 05:48:02 devicewatch: device=88, old="1", name=GeoTrigger Entry, var=urn:toggledbits-com:serviceId:ReactorGroup/GroupStatus_root, new="0"
        06/11/19 05:48:02 devicewatch: device=88, old="1560226682", name=GeoTrigger Entry, var=urn:micasaverde-com:serviceId:SecuritySensor1/LastTrip, new="1560253682"
        06/11/19 05:48:02 sensorstate: state=false
        06/11/19 05:48:03 variable: oldval=1560253682, variable=tnow, newval=1560253683
        06/11/19 05:48:03 variable: oldval=1, variable=SeondsSinceTrip, newval=2
        06/11/19 07:00:43 action: action=Reset
        06/11/19 07:00:43 devicewatch: device=88, old="1560253682", name=GeoTrigger Entry, var=urn:micasaverde-com:serviceId:SecuritySensor1/LastTrip, new="1560258043"
        06/11/19 07:00:43 sensorstate: state=false
        06/11/19 07:00:44 variable: oldval=1560253683, variable=tnow, newval=1560258044
        06/11/19 07:00:44 variable: oldval=2, variable=SeondsSinceTrip, newval=4363
        06/11/19 07:00:44 condchange: newState=false, cond=conde7e5kt7, oldState=true
        06/11/19 07:00:45 variable: oldval=1560258044, variable=tnow, newval=1560258045
        06/11/19 07:00:45 variable: oldval=4363, variable=SeondsSinceTrip, newval=4364
        06/11/19 07:00:45 evalchange: newState=false, cond=conde7e5kt7, oldState=true
        06/11/19 07:02:42 configchange: 
        06/11/19 07:02:43 variable: oldval=1560258045, variable=tnow, newval=1560258163
        06/11/19 07:02:43 variable: oldval=4364, variable=SeondsSinceTrip, newval=4482
        06/11/19 07:02:43 condchange: newState=true, cond=conde80v3hz
        06/11/19 07:02:43 evalchange: newState=true, cond=conde80v3hz
        06/11/19 07:02:43 condchange: newState=true, cond=grpe80unq0
        06/11/19 07:02:43 evalchange: newState=true, cond=grpe80unq0
        06/11/19 07:03:04 action: action=Reset
        06/11/19 07:03:04 devicewatch: device=88, old="1560258043", name=GeoTrigger Entry, var=urn:micasaverde-com:serviceId:SecuritySensor1/LastTrip, new="1560258184"
        06/11/19 07:03:04 sensorstate: state=false
        06/11/19 07:03:05 variable: oldval=1560258163, variable=tnow, newval=1560258185
        06/11/19 07:03:05 variable: oldval=4482, variable=SeondsSinceTrip, newval=4504
        06/11/19 07:03:10 action: action=Reset
        06/11/19 07:03:10 devicewatch: device=88, old="1560258184", name=GeoTrigger Entry, var=urn:micasaverde-com:serviceId:SecuritySensor1/LastTrip, new="1560258190"
        06/11/19 07:03:10 sensorstate: state=false
        06/11/19 07:03:11 variable: oldval=1560258185, variable=tnow, newval=1560258191
        06/11/19 07:03:11 variable: oldval=4504, variable=SeondsSinceTrip, newval=4510

That’s operating correctly. Expressions are only evaluated when conditions are evaluated (the getstate() function also places a watch on its subject device and will force a re-evaluation, so it is the lone exception). Time functions in expressions do not cause free-running evaluation; that would actually be really, really bad.

There are other ways to create and enforce delays, notably the “sustained for” and “delay reset” options on a condition.

The bigger question is, why do you need a sensor to untrip after a delay? You don’t explain that, so I can’t really guide you.

Ahh ok, so that’s why the expressions containing getstate seem to refresh fine ! I was wondering.

Ok, let me backup…

My external house lights are on till 10pm every night according to a schedule (this is working fine). Lights turn off at 10PM as planned.

After 10:15PM, I have delay light setup to turn the external lights on for 20 mins only if someone “enters the geofence” (active period between 10:15 - 6 am)

I WAS using the 2 geofence sensors “connor is home” and “pooky is home” as triggers for the delay light previously.

Problem… because the 2 sensors “pooky is home” and “connor is home” stay tripped, we can be sitting there watching TV and at 10PM the lights turn off as per the schedule , but then the delaylight turns all the lights on again at 10:15 because it’s active period has kicked in and it see’s the 2 tripped sensors “connor is home” and “pooky is home”

So it works fine as intended if we’re both away and come home late. But otherwise, the lights turn on at 10:15 every night for 20 mins according to the delaylight schedule, even if we’re just sitting there. ha ha

So I guess I’m trying to create a sensor that will feed as a trigger for delaylight, and I wanted it to only trip if there was indeed someone “entering the geofence”. Hence why I want the sensor to “untrip” if it’s been more than than 30sec (or a minute?), since someone last entered the geofence.

I’m gathering maybe you have a a better idea for how to accomplish this vs my over complciation lol ?

OK. We can take advantage of a behavior of the changes operator here–when no “from-to” values are specified, a condition that uses changes will pulse briefly true when the subject value is modified (from any value to any other value). The changes operator is available for group state conditions, so…

Root group - OR operator

  • Pooky Group - AND operator
    • Group State “Pooky is Home?” changes
    • Group State “Pooky is Home?” is TRUE
  • Connor Group - AND operator
    • Group State “Connor is Home?” changes
    • Group State “Connor is Home?” is TRUE

This will cause a brief pulse of the ReactorSensor’s tripped state when either geofence state changes and changes to true. The changes test provides the pulse, but will also pulse going off (group changes from true to false), which we don’t want, so the additional group test that seems redundant is actually making sure the pulse only gets through when the new group state is true.

This will happen very fast–the default pulse is just two seconds, but that’s plenty of time for DelayLight to pick it up. But it may not always show on the UI (misses its refresh). If you want to stretch out the pulse so you can see it in the UI consistently, on each of the changes conditions, set the “delay reset” option to some number of seconds, say 15, and your pulses will be stretched that long.


OMG that seems so simple now that you explain it in this fashion !!

Yes, I was going to use the changes property, but I noticed that it pulsed both on entry and exit as well, never thought about marrying it with the conditions to check Connor is Home? / Pooky is Home? are evaluating to true to accomplish the “on entry” exclusively. Nicely done!

So basically, I won’t need the expressions at all, that simplifies big time!

I appreciate you explaining the time duration for the pulse, and clarifying that it might not show up in the UI (cause I always watch it and then get frustrated if I don’t see it change LOL), but it’s good to know delay light will still pick it up and trip.

Can’t wait to try this, thanks Patrick, I’ll report back after I give this a good test run.

1 Like

You sir are a genius. works like a charm, and way less complicated than I was trying to make it. !!!

Working perfectly now, the new sensor is happily tripping (I used the 15sec delay reset just so I could see it!), and then untripping. This will be perfect to feed as a trigger for delaylight

Thanks Patrick

1 Like