Reactor Variable as Condition

I am trying to set a Variable in a Reactor Sensor and perform an action when the variable changes to equal “1”. As a test case (posted logic below) I created an expression “TestVar” with an empty expression, a first group (TestVariableChange) with a condition to check if “TestVar” equals “1”, and a second group (ChangeTestVariable) that checks the state of a light. The activity of the second group sets “TestVar” to “1” when the light is on and to “0” when the light is off.

What I expect to happen is when the light turns on the TestVariableChange is True because TestVar is set to “1” when the light comes on and when the light turns off TestVariableChange is False because TestVar is set to “0”. What I also expect to happen is if I manually change TestVar to “1” or “0” the TestVariableChange becomes True or False accordingly.

What actually happens is TestVariableChange lags behind the light as in when the light is off TestVariableChange is True (while TestVar is “0”) and when the light is on TestVariableChange is False (while testVar is “1”). Also, nothing happens if I manually change TestVar.

What I think is happening is the Reactor Sensor is not re-evaluating conditions when the TestVar changes and sees the change when some other condition causes a re-evaluate, such as the light coming on/off. I believe it lags the light because when the light state changes, Reactor re-evaluates the conditions, sees the value of TestVar before the action changes TestVar (so it is the previous value).

Am I misunderstanding variables and how they work in Reactor or is there some other underlying issue?

*************************************************** REACTOR LOGIC SUMMARY REPORT ***************************************************
   Version: 3.0 config 301 cdata 19082 ui 19125 pluginDevice 342
    System: Vera version 1.7.4453 on Sercomm G450; loadtime 1557342194; systemReady 1557342218; Lua 5.1
Local time: 2019-05-08T16:02:47-0400; DST=1
House mode: plugin 1; system 1; tracking off
  Sun data: 
  Geofence: not running
====================================================================================================================================
Reactor Sensor 3 (#345)
    Version 19082.1557343620 05/08/19 15:27:00
    Message/status: Not tripped
    Variable/expressions
       0: TestVar                   [last "1"(string)] (exported)
    Condition group "Reactor Sensor 3" (AND) false as of 15:13:15 <root>
      &-F-group "TestVariableChange" (AND) false as of 16:02:27 <grpcvt7m9f>
      |     &-F-service Reactor Sensor 3 (345) urn:toggledbits-com:serviceId:ReactorValues/TestVar = 1 (match case) [1 => 0 at 16:02:27; F/F as of 16:02:27/16:02:27] <condcvsy514>
      &-T-group "ChangeTestVariable" (AND) TRUE as of 16:02:27 <grpcvt8jnz>
      |     &-T-service LampDimmer (189) urn:upnp-org:serviceId:SwitchPower1/Status = 1 (match case) [0 => 1 at 16:02:27; T/T as of 16:02:27/16:02:27] <condcvt8xaj>
    Activity grpcvt8jnz.true
        Device 345 (Reactor Sensor 3) action urn:toggledbits-com:serviceId:ReactorSensor/SetVariable( VariableName=TestVar, NewValue=1 )
    Activity grpcvt8jnz.false
        Device 345 (Reactor Sensor 3) action urn:toggledbits-com:serviceId:ReactorSensor/SetVariable( VariableName=TestVar, NewValue=0 )
    Events
        05/08/19 15:26:32 devicewatch: device=189, old="1", name=LampDimmer, var=urn:upnp-org:serviceId:SwitchPower1/Status, new="0"
        05/08/19 15:26:33 condchange: newState=true, cond=condcvsy514, oldState=false
        05/08/19 15:26:33 evalchange: newState=true, cond=condcvsy514, oldState=false
        05/08/19 15:26:33 condchange: newState=true, cond=grpcvt7m9f, oldState=false
        05/08/19 15:26:33 evalchange: newState=true, cond=grpcvt7m9f, oldState=false
        05/08/19 15:26:33 condchange: newState=false, cond=condcvt8xaj, oldState=true
        05/08/19 15:26:33 evalchange: newState=false, cond=condcvt8xaj, oldState=true
        05/08/19 15:26:33 condchange: newState=false, cond=grpcvt8jnz, oldState=true
        05/08/19 15:26:33 evalchange: newState=false, cond=grpcvt8jnz, oldState=true
        05/08/19 15:26:33 startscene: scene=grpcvt8jnz.false, sceneName=grpcvt8jnz.false
        05/08/19 15:26:33 runscene: scene=grpcvt8jnz.false, sceneName=grpcvt8jnz.false, group=1, notice=Starting scene group 1
        05/08/19 15:26:33 endscene: scene=grpcvt8jnz.false, sceneName=grpcvt8jnz.false
        05/08/19 15:27:00 configchange: 
        05/08/19 15:27:00 configchange: 
        05/08/19 15:27:01 condchange: newState=false, cond=condcvsy514, oldState=true
        05/08/19 15:27:01 evalchange: newState=false, cond=condcvsy514, oldState=true
        05/08/19 15:27:01 condchange: newState=false, cond=grpcvt7m9f, oldState=true
        05/08/19 15:27:01 evalchange: newState=false, cond=grpcvt7m9f, oldState=true
        05/08/19 15:27:11 devicewatch: device=189, old="0", name=LampDimmer, var=urn:upnp-org:serviceId:SwitchPower1/Status, new="1"
        05/08/19 15:27:12 condchange: newState=true, cond=condcvt8xaj, oldState=false
        05/08/19 15:27:12 evalchange: newState=true, cond=condcvt8xaj, oldState=false
        05/08/19 15:27:12 condchange: newState=true, cond=grpcvt8jnz, oldState=false
        05/08/19 15:27:12 evalchange: newState=true, cond=grpcvt8jnz, oldState=false
        05/08/19 15:27:12 startscene: scene=grpcvt8jnz.true, sceneName=grpcvt8jnz.true
        05/08/19 15:27:12 runscene: scene=grpcvt8jnz.true, sceneName=grpcvt8jnz.true, group=1, notice=Starting scene group 1
        05/08/19 15:27:12 endscene: scene=grpcvt8jnz.true, sceneName=grpcvt8jnz.true
        05/08/19 16:02:20 devicewatch: device=189, old="1", name=LampDimmer, var=urn:upnp-org:serviceId:SwitchPower1/Status, new="0"
        05/08/19 16:02:21 condchange: newState=true, cond=condcvsy514, oldState=false
        05/08/19 16:02:21 evalchange: newState=true, cond=condcvsy514, oldState=false
        05/08/19 16:02:21 condchange: newState=true, cond=grpcvt7m9f, oldState=false
        05/08/19 16:02:21 evalchange: newState=true, cond=grpcvt7m9f, oldState=false
        05/08/19 16:02:21 condchange: newState=false, cond=condcvt8xaj, oldState=true
        05/08/19 16:02:21 evalchange: newState=false, cond=condcvt8xaj, oldState=true
        05/08/19 16:02:21 condchange: newState=false, cond=grpcvt8jnz, oldState=true
        05/08/19 16:02:21 evalchange: newState=false, cond=grpcvt8jnz, oldState=true
        05/08/19 16:02:21 startscene: scene=grpcvt8jnz.false, sceneName=grpcvt8jnz.false
        05/08/19 16:02:21 runscene: scene=grpcvt8jnz.false, sceneName=grpcvt8jnz.false, group=1, notice=Starting scene group 1
        05/08/19 16:02:21 endscene: scene=grpcvt8jnz.false, sceneName=grpcvt8jnz.false
        05/08/19 16:02:26 devicewatch: device=189, old="0", name=LampDimmer, var=urn:upnp-org:serviceId:SwitchPower1/Status, new="1"
        05/08/19 16:02:27 condchange: newState=false, cond=condcvsy514, oldState=true
        05/08/19 16:02:27 evalchange: newState=false, cond=condcvsy514, oldState=true
        05/08/19 16:02:27 condchange: newState=false, cond=grpcvt7m9f, oldState=true
        05/08/19 16:02:27 evalchange: newState=false, cond=grpcvt7m9f, oldState=true
        05/08/19 16:02:27 condchange: newState=true, cond=condcvt8xaj, oldState=false
        05/08/19 16:02:27 evalchange: newState=true, cond=condcvt8xaj, oldState=false
        05/08/19 16:02:27 condchange: newState=true, cond=grpcvt8jnz, oldState=false
        05/08/19 16:02:27 evalchange: newState=true, cond=grpcvt8jnz, oldState=false
        05/08/19 16:02:27 startscene: scene=grpcvt8jnz.true, sceneName=grpcvt8jnz.true
        05/08/19 16:02:27 runscene: scene=grpcvt8jnz.true, sceneName=grpcvt8jnz.true, group=1, notice=Starting scene group 1
        05/08/19 16:02:27 endscene: scene=grpcvt8jnz.true, sceneName=grpcvt8jnz.true

Expression/Variables don’t drive evaluation unless they refer to device states (e.g. their expressions use the getstate() function).

But this kind of sounds like an X-Y Problem in the making. What is it you are actually trying to accomplish?

I am trying to do a repeating notification similar to this Repeat notification solution and thought maybe there was a easier solution. I like to get a notification every 5 minutes if my garage door is open. My idea was to set a variable to “1” when the garage door opens and to “0” when it closes. I would then have another group with two conditions 1) garage door open and 2) the variable = “1” for 300 secs. Then the True action would send the notification, change variable to something other then “1” and then change it back to “1” (or the current garage door state). My assumption was that this would temporarily make the group False and begin the condition variable = “1” for 300 seconds again to send the next notification if the garage door is still open (essentially restarting a timer). Now I know I can use a virtual switch instead of a variable but I thought it would be convenient if it was all done in the Reactor. I’m so use to PLEG and just trying to figure out how the logic works in Reactor. In PLEG for this problem I would simply start a timer when the garage door opens, and when the timer ends, send a notification and restart the timer.

I see. Yeah, the Interval condition performs the function of the timer in the solution you linked. That solution (the Reactor repeating notification) is two conditions; if someone can do it more simply than that, beer’s on me. :smiley: