We have moved at community.getvera.com

Author Topic: Trying to add variable watch to Lua startup for Sonos Volume  (Read 1453 times)

Offline michelhamelin

  • Full Member
  • ***
  • Posts: 162
  • Karma: +3/-1
Trying to add variable watch to Lua startup for sonos volume but is not working
Why?

-- Set up variable-watch for device 9
luup.variable_watch("doChange9","urn:upnp-org-com:serviceId:RenderingControl","Volume",9)

-- Process variable-watch callback for device 9. Chamge Sonos Cuisine Volume
function doChange9()
   luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = 69}, 0)
end

Offline jswim788

  • Hero Member
  • *****
  • Posts: 809
  • Karma: +58/-2
Re: Trying to add variable watch to Lua startup for Sonos Volume
« Reply #1 on: May 20, 2017, 01:40:10 pm »
   luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = 69}, 0)
I think SceneNum needs to be a string.  Try:
Code: [Select]
luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = "69"}, 0)

Offline michelhamelin

  • Full Member
  • ***
  • Posts: 162
  • Karma: +3/-1
Re: Trying to add variable watch to Lua startup for Sonos Volume
« Reply #2 on: May 20, 2017, 02:20:35 pm »
No, not better :(

Offline jswim788

  • Hero Member
  • *****
  • Posts: 809
  • Karma: +58/-2
Re: Trying to add variable watch to Lua startup for Sonos Volume
« Reply #3 on: May 20, 2017, 02:38:33 pm »
Do you know if the watch is not working or if the function call is not working?  Try the function (or even just the luup.call_action) in the test window.  If it works, likely there is something wrong with the variable watch itself.  Rex says that you have to restart Vera in order to make this take effect.  Are you doing that?  This code is in the startup lua, right?

http://forum.micasaverde.com/index.php/topic,18679.msg217315.html#msg217315

Offline michelhamelin

  • Full Member
  • ***
  • Posts: 162
  • Karma: +3/-1
Re: Trying to add variable watch to Lua startup for Sonos Volume
« Reply #4 on: May 21, 2017, 11:43:19 am »
Watch work but not the fonction

Offline jswim788

  • Hero Member
  • *****
  • Posts: 809
  • Karma: +58/-2
Re: Trying to add variable watch to Lua startup for Sonos Volume
« Reply #5 on: May 21, 2017, 02:04:41 pm »
Okay, then try this from the test window:
Code: [Select]
luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = "69"}, 0)If that doesn't work, then it needs to be debugged further.  If it does work, then try this in the test code window:
Code: [Select]
function doChange9()
   luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = "69"}, 0)
end
doChange9()

Offline michelhamelin

  • Full Member
  • ***
  • Posts: 162
  • Karma: +3/-1
Re: Trying to add variable watch to Lua startup for Sonos Volume
« Reply #6 on: May 21, 2017, 09:48:30 pm »
Okay, then try this from the test window:
Code: [Select]
luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = "69"}, 0)If that doesn't work, then it needs to be debugged further.  If it does work, then try this in the test code window:
Code: [Select]
function doChange9()
   luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = "69"}, 0)
end
doChange9()

luup.call action...      Works but,
function doChange... does not work

just checked again in log and Watch fonction in Lua startup not seem to appear there

Offline jswim788

  • Hero Member
  • *****
  • Posts: 809
  • Karma: +58/-2
Re: Trying to add variable watch to Lua startup for Sonos Volume
« Reply #7 on: May 21, 2017, 10:01:42 pm »
Strange.  I put this in my (UI5) test window and it ran fine:
Code: [Select]
function doChange9()
   luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = "31"}, 0)
   luup.log("doChange9 just ran")
end
doChange9()
return true
This is what I see in the log file.  Do you see anything like this?
Code: [Select]
08      05/21/17 18:56:50.799   JobHandler_LuaUPnP::HandleActionRequest device: 0 service: urn:micasaverde-com:serviceId:HomeAutomationGateway1 action: RunLua <0x2f9e3680>
08      05/21/17 18:56:50.799   JobHandler_LuaUPnP::HandleActionRequest argument Code=function doChange9()
   luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = "31"}, 0)
   luup.log("doChange9 just ran")
end
doChange9()
return true <0x2f9e3680>
08      05/21/17 18:56:50.800   JobHandler_LuaUPnP::HandleActionRequest device: 0 service: urn:micasaverde-com:serviceId:HomeAutomationGateway1 action: RunScene <0x2f9e3680>
08      05/21/17 18:56:50.801   JobHandler_LuaUPnP::HandleActionRequest argument SceneNum=31 <0
Do you see the test function in the log like this?

Offline michelhamelin

  • Full Member
  • ***
  • Posts: 162
  • Karma: +3/-1
Re: Trying to add variable watch to Lua startup for Sonos Volume
« Reply #8 on: May 21, 2017, 10:06:12 pm »
Do you acces the log by typing this in the browser?

http://192.168.0.156/cgi-bin/cmh/log.sh?Device=LuaUPnP

Offline michelhamelin

  • Full Member
  • ***
  • Posts: 162
  • Karma: +3/-1
Re: Trying to add variable watch to Lua startup for Sonos Volume
« Reply #9 on: May 21, 2017, 10:25:39 pm »
Yes i see this:

Code: [Select]
05/21/17 22:22:02.352 JobHandler_LuaUPnP::HandleActionRequest device: 0 service: urn:micasaverde-com:serviceId:HomeAutomationGateway1 action: RunLua <0x700f0520>
08 05/21/17 22:22:02.352 JobHandler_LuaUPnP::HandleActionRequest argument id=lu_action <0x700f0520>
08 05/21/17 22:22:02.352 JobHandler_LuaUPnP::HandleActionRequest argument serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1 <0x700f0520>
08 05/21/17 22:22:02.352 JobHandler_LuaUPnP::HandleActionRequest argument action=RunLua <0x700f0520>
08 05/21/17 22:22:02.353 JobHandler_LuaUPnP::HandleActionRequest argument Code=function doChange9()
   luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = "69"}, 0)
   luup.log("doChange9 just ran")
end
doChange9()
return true <0x700f0520>
08 05/21/17 22:22:02.353 JobHandler_LuaUPnP::HandleActionRequest device: 0 service: urn:micasaverde-com:serviceId:HomeAutomationGateway1 action: RunScene <0x700f0520>
08 05/21/17 22:22:02.354 JobHandler_LuaUPnP::HandleActionRequest argument SceneNum=69 <0x700f0520>
08 05/21/17 22:22:02.354 Scene::RunScene running 69 test adjust volume <0x700f0520>
08 05/21/17 22:22:02.354 JobHandler_LuaUPnP::HandleActionRequest device: 8 service: urn:upnp-org:serviceId:RenderingControl action: SetVolume <0x700f0520>
08 05/21/17 22:22:02.355 JobHandler_LuaUPnP::HandleActionRequest argument InstanceID= <0x700f0520>
08 05/21/17 22:22:02.355 JobHandler_LuaUPnP::HandleActionRequest argument Channel= <0x700f0520>
08 05/21/17 22:22:02.355 JobHandler_LuaUPnP::HandleActionRequest argument DesiredVolume=10 <0x700f0520>
06 05/21/17 22:22:02.399 Device_Variable::m_szValue_set device: 8 service: urn:upnp-org:serviceId:RenderingControl variable: Volume was: 75 now: 10 #hooks: 0 upnp: 0 skip: 0 v:0x12f5788/NONE duplicate:0 <0x700f0520>
06 05/21/17 22:22:02.400 Device_Variable::m_szValue_set device: 8 service: urn:micasaverde-com:serviceId:HaDevice1 variable: LastUpdate was: 1495418421 now: 1495419722 #hooks: 0 upnp: 0 skip: 0 v:(nil)/NONE duplicate:0 <0x700f0520>
50 05/21/17 22:22:02.401 luup_log:0: doChange9 just ran <0x700f0520>
04 05/21/17 22:22:14.207 <0x772a5520>

Offline jswim788

  • Hero Member
  • *****
  • Posts: 809
  • Karma: +58/-2
Re: Trying to add variable watch to Lua startup for Sonos Volume
« Reply #10 on: May 21, 2017, 11:31:17 pm »
This looks great:
Code: [Select]
Device_Variable::m_szValue_set device: 8 service: urn:upnp-org:serviceId:RenderingControl variable: Volume was: 75 now: 10  Your action and function are working fine.

Did you restart after adding this to the startup lua and saving?  Note that a reload may not work - I don't know if the lua startup is read on reload.  Saving the startup lua is not enough since it is only read at startup.  Try a reboot.

You said you did not see the watch in the log?  Either the watch and the function are not getting saved in the startup lua, or the startup lua didn't run.