UI7 modes

I am driving UI7 modes ( Home, Away etc ) from my plugin, however I noticed that the Get Mode action is taking quite some time and I am trying to optimize timings.

For instance getting the current mode , per the wiki page , is done via:

Get ?Mode? variable value http://IP:3480/data_request?id=variableget&Variable=Mode

However, when I do this, I notice it takes close to 300ms just for that.

50 01/08/15 11:51:21.923 luup_log:95: IPhoneLocator: HouseMode, getMode() <0x2b181000> 50 01/08/15 11:51:22.209 luup_log:95: IPhoneLocator: HouseMode, getMode() returns: 1, Home <0x2b18100

This is a little bit expensive for that it is. is there a more efficient way to get the current mode ?

Are you targeting the full IP address or using the local version?

If I run this code, it takes less than 5ms:

local res, mode = luup.inet.wget("http://127.0.0.1:3480/data_request?id=variableget&Variable=Mode",5) 

[quote=“RexBeckett, post:2, topic:185205”]Are you targeting the full IP address or using the local version?

If I run this code, it takes less than 5ms:

local res, mode = luup.inet.wget("http://127.0.0.1:3480/data_request?id=variableget&Variable=Mode",5) 

Thx ! yes I was using full IP but I definitely need to try this local loopback address.

With the latest release you can now get this as:

mode = luup.attr_get(“Mode”)

[quote=“RichardTSchaefer, post:4, topic:185205”]With the latest release you can now get this as:

mode = luup.attr_get(“Mode”)[/quote]

strange,this code produces this result

debug("calling getMode()...") local req_result = luup.attr_get("Mode") debug("getMode() = "..req_result)

50      01/08/15 16:59:42.051   luup_log:95: IPhoneLocator: debug: calling getMode()... <0x2dc1c680>
50      01/08/15 16:59:42.052   luup_log:95: IPhoneLocator: debug: getMode() =  <0x2dc1c680>

I am on vera lite UI7.0.3

You have to be in the Scene LUA or Startup LUA context to do this … you can’t do it from a plugin LUA context.

I consider that a bug … I use the following to copy to my state variable:

      luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunLua", 
                       {Code = 'luup.variable_set("' .. MyService .. '", "HouseMode", luup.attr_get("Mode"), ' .. MyDevice .. ') return true'}, 0)
      local CurrentMode = luup.variable_get(MyService, "HouseMode", MyDevice)

[quote=“RichardTSchaefer, post:6, topic:185205”]You have to be in the Scene LUA or Startup LUA context to do this … you can’t do it from a plugin LUA context.

I consider that a bug … I use the following to copy to my state variable:

luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1", "RunLua", {Code = 'luup.variable_set("' .. MyService .. '", "HouseMode", luup.attr_get("Mode"), ' .. MyDevice .. ') return true'}, 0) local CurrentMode = luup.variable_get(MyService, "HouseMode", MyDevice) [/quote]

Wow Thanks for the nice workaround ! @RexBeckett’s one with 127.0.0.1 runs quite fact so I may stick to this one, I wonder how fast the call_action( “RunLua”) is

local url_req = "http://127.0.0.1:3480/data_request?id=variableget&DeviceNum=0&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&Variable=Mode" local req_status, req_result = luup.inet.wget(url_req)

I wonder how fast the call_action( "RunLua") is

I make it about 2ms.

I think my version should be faster and use less memory. (i.e. there is NO network stack involved).