We have moved at community.getvera.com

Author Topic: Watched Variables  (Read 11385 times)

Offline CudaNet

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1401
  • Karma: +42/-11
  • Chimichanga !
Re: Watched Variables
« Reply #60 on: February 04, 2016, 11:44:52 am »
Interesting, I actually just installed a storm door but currently don't have a sensor on it. As for these locks, I do have Schlages and if I setup a scene on Vera, they work perfectly (lock button and user pin entered). As for a bad pin, alarm (which these locks have) etc.. I've never tried to test that. So not sure if MCV fixed the issue with the lock button prior to me buying the locks as I've never had an issue, well - at least not on an actual Vera.

AFAIK it was previously established that a "Door Lock Button" event (driven by sl_LockButton?) is not functional, at least for Schlage.

I have scenes the need to know if the lock was secured from outside the house.
Don't know if this at all applies to your case, but where I'm at storm doors are very common. I detect directionality by having a sensor on both the front door and the storm door, based on timing. Perhaps combining that with a lock event in the same window is a reasonable indicator from which side of the door the event was triggered? (If that is truly what you are after.)
openLuup, AltUI, Zway and HomeWave, enough said...

Offline CudaNet

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1401
  • Karma: +42/-11
  • Chimichanga !
Re: Watched Variables
« Reply #61 on: February 04, 2016, 11:56:18 am »
@Amg0/Akbooer,

Attached are untouched logs (debug mode enabled) for both Vera and openLuup/AltUI.... Sending you both a separate email.
« Last Edit: February 04, 2016, 12:46:51 pm by CudaNet »
openLuup, AltUI, Zway and HomeWave, enough said...

Offline amg0

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3174
  • Karma: +210/-8
Re: Watched Variables
« Reply #62 on: February 04, 2016, 12:23:58 pm »
@Amg0/Akbooer,

Attached are untouched logs (debug mode enabled) for both Vera and openLuup/AltUI.... Sending you both a separate email.

First info, maybe unrelated but your VariablesToSend is corrupted. all watches with
Code: [Select]
undefined#undefined#undefined etc...  are corrupted you need to delete and recreate them

Then about the lua logs, what I observe is:

logs starts at 08:30
08:31 sl_UserCode changes,  watch expression is true,  Scene 12 is run
08:32 sl_UserCode changes, watch expression is true, Scene 12 is run
logs stops at 08:32


Code: [Select]
2016-02-04 08:30:41.702   luup_log:3: ALTUI: debug: _addWatch(urn:micasaverde-com:serviceId:DoorLock1,sl_UserCode,0-10237,12,(new ~= nil and old ~=nil),,,"")
2016-02-04 08:30:41.703   luup.variable_watch:3: callback=variableWatchCallback, watching=10237.urn:micasaverde-com:serviceId:DoorLock1.sl_UserCode
2016-02-04 08:30:41.703   luup_log:3: ALTUI: debug: _addWatch(urn:micasaverde-com:serviceId:DoorLock1,sl_LockButton,0-10237,16,(new=='1' and old == '1'),,,"")
2016-02-04 08:30:41.703   luup.variable_watch:3: callback=variableWatchCallback, watching=10237.urn:micasaverde-com:serviceId:DoorLock1.sl_LockButton

the Watch is properly declared in ALTUI
Code: [Select]
{
  "0-10237": {
    "urn:micasaverde-com:serviceId:DoorLock1": {
      "sl_UserCode": {
        "Expressions": {
          "(new ~= nil and old ~=nil)": [
            {
              "SceneID": 12
            }
          ]
        }
      },
      "sl_LockButton": {
        "Expressions": {
          "(new=='1' and old == '1')": [
            {
              "SceneID": 16
            }
          ]
        }
      }
    }
  }
}

But when looking at actually fired watch events:
Code: [Select]
2016-02-04 08:31:18.736   luup_log:3: ALTUI: debug: _internalVariableWatchCallback(0-10237,urn:micasaverde-com:serviceId:DoorLock1,sl_UserCode,old:'UserID="4" UserName="Monika Sapp"',new:'UserID="3" UserName="Andy Sapp"')
2016-02-04 08:31:42.912   luup_log:3: ALTUI: debug: _internalVariableWatchCallback(0-48,urn:micasaverde-com:serviceId:EnergyMetering1,Watts,old:'1682',new:'1671')
2016-02-04 08:32:07.989   luup_log:3: ALTUI: debug: _internalVariableWatchCallback(0-10237,urn:micasaverde-com:serviceId:DoorLock1,sl_UserCode,old:'UserID="3" UserName="Andy Sapp"',new:'UserID="4" UserName="Monika Sapp"')

Conclusion:
I do not see any watch being fired by VERA for sl_LockButton

now is this normal or not ?   is this because new & old have the same value ?
I do not see in the logs any luup variable set calls to set the value of sl_LockButton to be '1' anyhow.
so may that is the problem you were after ?

I suggest you debug with Lua code on UI5/UI7 just to eliminate openLuup & ALTUI from the problem.  register a watch on "sl_LockButton" and see if it is called

Offline CudaNet

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1401
  • Karma: +42/-11
  • Chimichanga !
Re: Watched Variables
« Reply #63 on: February 04, 2016, 04:05:47 pm »
Thank you Amg0,

Yes, the new and old values are the same for sl_LockButton - this being a constant of '1' each time the button is pressed. sl_UserCode 'may' also exhibit the same value only if the user enters the same pin from event 1 to event 2 and so on. The exception obviously being another user enters a different pin, this (as you've seen) triggers the scene.
Quote
Conclusion:
I do not see any watch being fired by VERA for sl_LockButton
now is this normal or not ?   is this because new & old have the same value ?

Yes, nor do I but is this attributed to the fact that the variable 'must' change in order for the event to appear within the log ? Might be a question for both you and Akbooer. I simply don't know enough about Watched Variables and the rules encompassing use.
Quote
I do not see in the logs any luup variable set calls to set the value of sl_LockButton to be '1' anyhow.
so may that is the problem you were after ?

Sorry, not sure I'm clear on how to do that as I've only ever used Watched variables within openLuup.
Quote
I suggest you debug with Lua code on UI5/UI7 just to eliminate openLuup & ALTUI from the problem.  register a watch on "sl_LockButton" and see if it is called
« Last Edit: February 04, 2016, 05:43:24 pm by CudaNet »
openLuup, AltUI, Zway and HomeWave, enough said...

Offline CudaNet

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1401
  • Karma: +42/-11
  • Chimichanga !
Re: Watched Variables
« Reply #64 on: February 05, 2016, 02:11:38 pm »
OK, so I created a work around now that I "think" I fully understand a Watch variable.

Execute the following on Vera.
Code: [Select]
luup.variable_set("urn:cuda-net:serviceId:DoorLock1", "ol_UserCode", os.time(), DevId)
luup.variable_set("urn:cuda-net:serviceId:DoorLock1", "ol_LockButton", os.time(), DevId)

Instruct Vera when either the lock button is pressed or a user's PIN code is supplied, simply update the variables (in this case use os.time()).
Here is the result of a lock button press now on Vera.
Code: [Select]
06      02/04/16 20:11:37.158   Device_Variable::m_szValue_set device: 237 service: urn:micasaverde-com:serviceId:DoorLock1 variable: Status was: 0 now: 1 #hooks: 0 upnp: 0 skip: 0 v:0xca97f0/NONE duplicate:0 <0x2b4b2680>
06      02/04/16 20:11:37.159   Device_Variable::m_szValue_set device: 237 service: urn:micasaverde-com:serviceId:DoorLock1 variable: sl_LockButton was: 1 now: 1 #hooks: 1 upnp: 0 skip: 0 v:0xec0e98/DL_LOCK_BUTTON duplicate:0 <0x2b4b2680>
06      02/04/16 20:11:37.161   Device_Variable::m_szValue_set device: 237 service: urn:cuda-net:serviceId:DoorLock1 variable: ol_LockButton was: 1454637314 now: 1454638297 #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:0 <0x2b4b2680>

And here is a user entering the house a second time (again on Vera).
Code: [Select]
06      02/04/16 20:13:15.548   Device_Variable::m_szValue_set device: 237 service: urn:micasaverde-com:serviceId:DoorLock1 variable: Status was: 1 now: 0 #hooks: 0 upnp: 0 skip: 0 v:0xca97f0/NONE duplicate:0 <0x2b4b2680>
06      02/04/16 20:13:15.550   Device_Variable::m_szValue_set device: 237 service: urn:micasaverde-com:serviceId:DoorLock1 variable: sl_UserCode was: UserID="4" UserName="Monika Sapp" now: UserID="4" UserName="Monika Sapp" #hooks: 1 upnp: 0 skip: 0 v:0xec0518/DL_USERCODE duplicate:0 <0x2b4b2680>
06      02/04/16 20:13:15.551   Device_Variable::m_szValue_set device: 237 service: urn:cuda-net:serviceId:DoorLock1 variable: ol_UserCode was: 1454637305 now: 1454638395 #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:0

And here are the openLuup/AltUI logs showing the WV firing.
Code: [Select]
2016-02-04 20:11:15.345   luup_log:3: ALTUI: debug: -----> evaluateExpression() {"(new~= old)":[{"SceneID":16}]}
2016-02-04 20:11:15.346   luup_log:3: ALTUI: debug: evaluateExpression(0-10237,urn:cuda-net:serviceId:DoorLock1,ol_LockButton,(new~= old),1454637314,1454638297,1454638275,1,16)
2016-02-04 20:11:15.346   luup_log:3: ALTUI: debug: _evaluateUserExpression(0-10237,urn:cuda-net:serviceId:DoorLock1,ol_LockButton,1454637314,1454638297,1454638275,(new~= old))
2016-02-04 20:11:15.346   luup_log:3: ALTUI: debug: Evaluation of user watch expression returned: [true]
2016-02-04 20:11:15.346   luup_log:3: ALTUI: debug: run_scene(16)
2016-02-04 20:11:15.346   luup.call_action:3: 0.urn:micasaverde-com:serviceId:HomeAutomationGateway1.RunScene
2016-02-04 20:11:15.347   luup_log:0: >>>>>>> Executing Scene [16] via remote action. <<<<<<<

--

2016-02-04 20:12:58.528   luup_log:3: ALTUI: debug: -----> evaluateExpression() {"(new ~= old)":[{"SceneID":12}]}
2016-02-04 20:12:58.528   luup_log:3: ALTUI: debug: evaluateExpression(0-10237,urn:cuda-net:serviceId:DoorLock1,ol_UserCode,(new ~= old),1454637305,1454638395,1454638378,1,12)
2016-02-04 20:12:58.529   luup_log:3: ALTUI: debug: _evaluateUserExpression(0-10237,urn:cuda-net:serviceId:DoorLock1,ol_UserCode,1454637305,1454638395,1454638378,(new ~= old))
2016-02-04 20:12:58.529   luup_log:3: ALTUI: debug: Evaluation of user watch expression returned: [true]
2016-02-04 20:12:58.529   luup_log:3: ALTUI: debug: run_scene(12)
2016-02-04 20:12:58.529   luup.call_action:3: 0.urn:micasaverde-com:serviceId:HomeAutomationGateway1.RunScene
2016-02-04 20:12:58.529   luup_log:0: >>>>>>> Executing Scene [12] via remote action. <<<<<<<

Thanks to everyone who contributed to this discussion. I realize reading thanks over and over has a numbing effect on some, but I actually really do appreciate everyone's commitment to helping others. For those that might ask why I didn't just do this earlier (yes, my wife asked me this), it was simply because I wanted to understand everything I could regarding Watched Variables and why I couldn't make this work. This might be common knowledge for some and obvious for others but I simply needed to understand and learn.

So this solution (I'm sure one of many) required me to use Vera ... Which, honestly, I'm trying to avoid at every and all costs, so I do hope that explains my persistence...
openLuup, AltUI, Zway and HomeWave, enough said...