Author Topic: setWatch() function is not working with some variables  (Read 334 times)

Offline kwieto

  • Hero Member
  • *****
  • Posts: 579
  • Karma: +27/-14
setWatch() function is not working with some variables
« on: November 22, 2017, 09:59:13 am »
I want to trigger some scenes based on the variable change.
In general, I use the solution provided here: http://forum.micasaverde.com/index.php/topic,18679.msg217315.html#msg217315  with the watchTable defined as it is described there.

It works for variables like temperature, humidity level, or on/off status.

But recently I was in need to add variables like "CommFailure" (to run a scene if device reports communication issues) or "CurrentSetpoint".
None of these seem to work for me, scenes are not triggered even if watched variables change.

Any Idea how to make it work?
My code is build as below and put into the startup LUA:

Code: [Select]
-- Table entries { "ServiceID", "VariableName", DeviceNo, SceneNo }
--
watchTable = {
               {"urn:micasaverde-com:serviceId:HaDevice1","CommFailure",7,11},
               {""urn:upnp-org:serviceId:TemperatureSetpoint1","CurrentSetpoint",7,5}
                         }
--
-- Setup Variable Watch for each entry in watchTable
--
function setWatch()
      for n,t in ipairs(watchTable) do
          luup.variable_watch("catchWatch",t[1],t[2],t[3])
      end
end
--
-- When a watched variable changes, call the specified scene
--
function catchWatch(lul_device, lul_service, lul_variable, lul_value_old, lul_value_new)
      for n,t in ipairs(watchTable) do
          if ( (t[3] == lul_device) and (t[1] == lul_service) and (t[2] == lul_variable) ) then
              luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = t[4]}, 0)
          end
      end
end
--
-- Wait for 30 seconds after restart then run setWatch
--
luup.call_delay("setWatch",30)
« Last Edit: November 22, 2017, 10:01:40 am by kwieto »