Set & Get variable on remote Vera

Hello,

newbie lua question…

Im having two vera 3.
I want these veras to talk to each other…
For instance, setting a variable in a variable container in the other vera

is there a simple command for such?

Thank you!

Hello,

If your Veras are in the same network then use the variableset request like this:

local veraIp = "192.168.81.81"
luup.inet.wget("http://".. veraIp ..":3480/data_request?id=variableset&DeviceNum=6&serviceId=urn:micasaverde-com:serviceId:DoorLock1&Variable=Status&Value=1")

If the Veras are in different network and can’t communicate directly use this code instead:

local username = "username" -- Your MiOS username.
local password = "password" -- Your MiOS password.
local vera_serial = "vera_serial" -- The serial # of Vera.

luup.inet.wget("https://".. luup.ra_server .."/".. username .."/".. password .."/".. vera_serial .."/data_request?id=variableset&DeviceNum=6&serviceId=urn:micasaverde-com:serviceId:DoorLock1&Variable=Status&Value=1")

In this code:

[ul][li]veraIp is the other Vera’s IP address.[/li]
[li]username is your MiOS username.[/li]
[li]password is your MiOS password.[/li]
[li]vera_serial is the other Vera’s serial number.[/li][/ul]

Edit: Added code for when both Vera’s are in the same network.

[quote=“bthovda, post:1, topic:172025”]Hello,

newbie lua question…

Im having two vera 3.
I want these veras to talk to each other…
For instance, setting a variable in a variable container in the other vera

is there a simple command for such?

Thank you![/quote]

Can you please provide the scenario in which you employ the two Vera’s?
Are they in the same house or totally idependant of each other?
If they are in the same house have you looked st bridging the two units?

Thank you to both of you!

I forgot to say that they are not in the same network. One in norway and one in Thailand , and soon one more up in a remote corner of the norwegian mountains. :slight_smile:

Im working on a watchdog function. Let the veras check if their sisters are still a live.

Regarding this question:
I need this function when a disconnected vera return to online state.
it could then tell the other veras “im online”

[quote=“mcvflorin, post:2, topic:172025”]Hello,

If your Veras are in the same network then use the variableset request like this:

local veraIp = "192.168.81.81"
luup.inet.wget("http://".. veraIp ..":3480/data_request?id=variableset&DeviceNum=6&serviceId=urn:micasaverde-com:serviceId:DoorLock1&Variable=Status&Value=1")

If the Veras are in different network and can’t communicate directly use this code instead:

local username = "username" -- Your MiOS username.
local password = "password" -- Your MiOS password.
local vera_serial = "vera_serial" -- The serial # of Vera.

luup.inet.wget("https://".. luup.ra_server .."/".. username .."/".. password .."/".. vera_serial .."/data_request?id=variableset&DeviceNum=6&serviceId=urn:micasaverde-com:serviceId:DoorLock1&Variable=Status&Value=1")

In this code:

[ul][li]veraIp is the other Vera’s IP address.[/li]
[li]username is your MiOS username.[/li]
[li]password is your MiOS password.[/li]
[li]vera_serial is the other Vera’s serial number.[/li][/ul]

Edit: Added code for when both Vera’s are in the same network.[/quote]

Hmm… using your code:
luup.inet.wget(“https://fwd2.mios.com/***/***/***/data_request?id=variableset&DeviceNum=13&serviceId=urn:micasaverde-com:VSwitch1&Variable=Status&value=0”)

It dosent change the already existing variable “Status”, but creates a duplicate and set this to 0…

Any clues why?

Thank you!

Because you are using the wrong syntax:

Try:

luup.inet.wget(“https://fwd2.mios.com/***/***/***/data_request?id=variableset&DeviceNum=13&serviceId=urn:upnp-org:serviceId:VSwitch1&Variable=Status&value=0”)

  • Garrett

Sorry for the noob question … I have a fully setup VeraEdge, with an account on home.getvera.com.

When accessing: https://fwd2.mios.com/{username}/{password}/{vera_serial}/data_request?id=variabledet&DeviceNum={dev_id}&serviceId={dev_service_id}&Variable={var_name} it responds with: Invalid user/pass, and then forwards me to cp.mios.com.

{username}/{password} are my credentials for the home.getvera.com website, {vera_serial} the number that gets displayed on home.getvera.com when chosing device to connect.

Is fwd2.mios.com not the right ra_server for VeraEdge? If not, what is the correct URL for ra_server? Or how can I get this information from UI7?
Do I need to create a user account on cp.mios.com and indicate credentials to this account instead of the home.getvera.com? If so, can I connect my VeraEdge from both the home.getvera.com and co.mios.com gateways?

FYI - I do want to make temp/power consumption graphs with Cacti or another rrd-based tool that is NOT on the local network by remotely reading the values from my Vera. Appreciate any pointers to similar work/projects as well.

Thanks.

@ppc36

If you haven’t gotten this sorted yet, fill out a tech support ticket and they should be able to help you.

http://support.getvera.com/customer/portal/emails/new

@ppc36
The answer to your question is you CAN’T do what you are trying to do on UI6 or UI7 (i.e. credentials from GetVera.com)

The comments on the Wiki for remote access are only valid for UI5 using accounts from cp.mios.com

Remote access is much more complicated since UI6 to address security concerns.

See:
http://forum.micasaverde.com/index.php/topic,24942.0.html

as well as the update:

http://forum.micasaverde.com/index.php/topic,24942.msg191084.html#msg191084

Hi

I have two vera on the same network a UI5 and a UI7 and I’m trying to retrieve a variable from the UI7 one , but anything I try always returns a 0 (zero).

BUT If I do the http request directly into the browser then it works , but when wrapped in luup.inet.wget it always returns a 0 (zero) - what am I missing ?

FYI - The light is switched on so is should return 1 and the temp is 21.4c )

local power = luup.inet.wget("http://192.168.1.234:3480/data_request?id=variableget&DeviceNum=237&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature") print( "Show 1 if powered on = " .. power )

local temp = luup.inet.wget(“http://192.168.1.183:3480/data_request?id=variableget&DeviceNum=103&serviceId=urn:upnp-org:serviceId:SwitchPower1&Variable=Status”)
print( "Show the temp = " … temp )

Lua test results …

[u][b]LuaTest 1.5.2[/b][/u]

Lua file: /etc/cmh-ludl/luatest.lua

Results
No errors
Runtime: 13.2 ms
Code returned: nil

Print output
Show 1 if powered on = 0
Show the temp = 0

Code
1 local power = luup.inet.wget(“http://192.168.1.234:3480/data_request?id=variableget&DeviceNum=237&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature”)
2 print( "Show 1 if powered on = " … power )
3
4 local temp = luup.inet.wget(“http://192.168.1.183:3480/data_request?id=variableget&DeviceNum=103&serviceId=urn:upnp-org:serviceId:SwitchPower1&Variable=Status”)
5 print( "Show the temp = " … temp )

You are missing the fact that the first returned variable from luup.inet.wget() is, in fact, the status, not the returned string.

Try instead:

local status, power =  luup.inet.wget("http://192.168.1.234:3480/data_request?id=variableget&DeviceNum=237&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature")

Thanks @akbooer.

The fact it was returning 0 initially for switchpower threw me. That gets me over the first hurdle as I’m trying to code something that looks at light levels, and also if it’s night time before turning on a light .

I thought my logic was sound but it does not work, can you (or anyone else) see why ?

[u][b]LuaTest 1.5.2[/b][/u]

Lua file: /etc/cmh-ludl/luatest.lua

Results
No errors
Runtime: 5.7 ms
Code returned: nil

Print output
If it is day time show 1 = 1
Show light sensor level = 34
If power is on show 1 = 0
failed

Code

1 local daynight = tonumber((luup.variable_get(“urn:rts-services-com:serviceId:DayTime”,“Status”,204)))
2 print( "If it is day time show 1 = " … daynight )
3 local light = tonumber((luup.variable_get(“urn:micasaverde-com:serviceId:LightSensor1”,“CurrentLevel”,178)))
4 print( "Show light sensor level = " … light )
5 local status1, power = luup.inet.wget(“http://192.168.1.183:3480/data_request?id=variableget&DeviceNum=103&serviceId=urn:upnp-org:serviceId:SwitchPower1&Variable=Status”)
6 print( "If power is on show 1 = " … power )
7
8 if (power == 1) then
9 return
10 – false
11 print(“Light does not need to be turned on”)
12 end
13 if ((power == 0) and ((light < 20) or daynight == 1)) then
14 return
15 – true
16 print(“Light Can Be Turned On”)
17 else
18 print(“failed”)
19 end

Your variable ‘power’ is a string as returned by luup.inet.wget, so it will match neither 0 or 1. You can either make the comparison to the strings “0” and “1”, or you can convert it to a number.

As always - many thanks jswim788

I had tried the "tonumber’ route with the luup.inet.wget earlier as I thought I should look to get all of them as numbers - but for that particular one it always gave me an error - (see below), so assumed I could not do that.

local status1, power = tonumber(luup.inet.wget("http://192.168.1.183:3480/data_request?id=variableget&DeviceNum=103&serviceId=urn:upnp-org:serviceId:SwitchPower1&Variable=Status"))
Runtime error: Line 5: bad argument #2 to 'tonumber' (base out of range)

For some reason the logic is still not flowing as I expected it to. It now can see if the light is on which is great but I’m trying various combinations with the key ‘And and Or’ logic in the middle - but it just does not seem to want to work.

As I see it, the following logic should return the print request. “Light Should Be Turned On” but instead it prints. “Failed”

LuaTest 1.5.2

Lua file: /etc/cmh-ludl/luatest.lua

Results
No errors
Runtime: 6.4 ms
Code returned: nil

Print output
If it is day time show 1 = 1
Show light sensor level = 61
If power is on show 1 = 0
failed

Code
1 local daynight = tonumber((luup.variable_get(“urn:rts-services-com:serviceId:DayTime”,“Status”,204)))
2 print( "If it is day time show 1 = " … daynight )
3 local light = tonumber((luup.variable_get(“urn:micasaverde-com:serviceId:LightSensor1”,“CurrentLevel”,178)))
4 print( "Show light sensor level = " … light )
5 local status1, power = luup.inet.wget(“http://192.168.1.183:3480/data_request?id=variableget&DeviceNum=103&serviceId=urn:upnp-org:serviceId:SwitchPower1&Variable=Status”)
6 print( "If power is on show 1 = " … power )
7
8 if (power == “1”) then
9 return
10 – false
11 print(“Light does not need to be turned on”)
12 end
13 if ((power == 0) and ((light < 20) or daynight == 1)) then
14 return
15 – true
16 print(“Light Should Be Turned On”)
17 else
18 print(“failed”)
19 end

Doh !!

I forgot to set the other power entry as a string “0” too !!!

Working now I think…

 if ((power == 0) and ((light < 20) or daynight == 1)) then

you need to check for power equal to “0”. But why not make it an ‘else’ instead of checking again?

if (power == "1") then print("Light does not need to be turned on") return false elseif (light < 20) or daynight == 1 then print("Light Should Be Turned On") return true else print("failed") return false -- need to return false end

Also, tonumber() didn’t work for you because it can take 2 parameters, the second one is the base. A straightforward way to do get the number would be to get the power variable as a string first, then convert it to a number afterwards.

local status1, powerString = luup.inet.wget("http://192.168.1.183:3480/data_request?id=variableget&DeviceNum=103&serviceId=urn:upnp-org:serviceId:SwitchPower1&Variable=Status") local power = tonumber(powerString)

This, in fact, is not the case here, since the luup.variable_get() parameter has been surrounded with (double) parentheses within the function call, turning it into an evaluation which returns only one value.

For example:

local function test(...) return ... end

print (test(1,2))
print ((test(1,2)))

prints the results:

1       2
1

However, there are certainly clearer ways to write the code!

[quote=“akbooer, post:18, topic:172025”]

Also, tonumber() didn’t work for you because it can take 2 parameters…

This, in fact, is not the case here, since the luup.variable_get() parameter has been surrounded with (double) parentheses within the function call, turning it into an evaluation which returns only one value.[/quote]

Agree with you regarding the luup.variable_get, but the problematic statement was the inet.get which would be a problem, correct? I believe @parkerc was asking about this line:

local status1, power = tonumber(luup.inet.wget("http://192.168.1.183:3480/data_request?id=variableget&DeviceNum=103&serviceId=urn:upnp-org:serviceId:SwitchPower1&Variable=Status"))  

to_number() wouldn’t work even with extra parentheses, true?

Ah yes, I’m with you now. Indeed, that will always just return the status!

Always better to split things into separate lines rather than composing functions. Much clearer, much easier to debug, fewer errors in the first place!