Trying to add variable watch to Lua startup for Sonos Volume

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

I think SceneNum needs to be a string. Try:luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = "69"}, 0)

No, not better :frowning:

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

Watch work but not the fonction

Okay, then try this from the test window:

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:

function doChange9() luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = "69"}, 0) end doChange9()

[quote=“jswim788, post:6, topic:196323”]Okay, then try this from the test window:

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:

function doChange9() luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = "69"}, 0) end doChange9()[/quote]

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

Strange. I put this in my (UI5) test window and it ran fine:

function doChange9() luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunScene", {SceneNum = "31"}, 0) luup.log("doChange9 just ran") end doChange9() return trueThis is what I see in the log file. Do you see anything like this?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 <0Do you see the test function in the log like this?

Do you acces the log by typing this in the browser?

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

Yes i see this:

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>

This looks great: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.