Author Topic: Set & Get variable on remote Vera  (Read 4760 times)

Offline bthovda

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Set & Get variable on remote Vera
« on: July 11, 2012, 04:55:27 pm »
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!


Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1759
  • Karma: +11/-3
Re: Set & Get variable on remote Vera
« Reply #1 on: July 12, 2012, 11:25:23 am »
Hello,

If your Veras are in the same network then use the variableset request like this:
Code: [Select]
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:
Code: [Select]
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:
  • veraIp is the other Vera's IP address.
  • username is your MiOS username.
  • password is your MiOS password.
  • vera_serial is the other Vera's serial number.

Edit: Added code for when both Vera's are in the same network.
« Last Edit: July 12, 2012, 12:03:14 pm by mcvflorin »

Online Brientim

  • Beta Testers
  • Sr. Hero Member
  • *****
  • Posts: 2494
  • Karma: +77/-7
Re: Set & Get variable on remote Vera
« Reply #2 on: July 12, 2012, 11:51:02 am »
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!



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?

Offline bthovda

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Re: Set & Get variable on remote Vera
« Reply #3 on: July 12, 2012, 03:25:42 pm »
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. :-)

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"

Offline bthovda

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Re: Set & Get variable on remote Vera
« Reply #4 on: July 12, 2012, 04:25:22 pm »
Hello,

If your Veras are in the same network then use the variableset request like this:
Code: [Select]
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:
Code: [Select]
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:
  • veraIp is the other Vera's IP address.
  • username is your MiOS username.
  • password is your MiOS password.
  • vera_serial is the other Vera's serial number.

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

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!

Offline garrettwp

  • Beta Testers
  • Master Member
  • *****
  • Posts: 6376
  • Karma: +227/-128
  • Vera 3, Lite, ISY994
Re: Set & Get variable on remote Vera
« Reply #5 on: July 12, 2012, 04:52:59 pm »
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

Offline ppc36

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
Re: Set & Get variable on remote Vera
« Reply #6 on: January 10, 2015, 02:54:33 pm »
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.

Offline Marc Shenker

  • Sr. Manager of Community Relations and Development
  • Administrator
  • Hero Member
  • *****
  • Posts: 554
  • Karma: +91/-265
    • http://www.getvera.com
Re: Set & Get variable on remote Vera
« Reply #7 on: January 15, 2015, 01:07:03 pm »
@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
Marc Shenker ▾ Sr. Manager of Community Relations and Development
Vera Control, Ltd. ▾ Smarter Home Control ▾ www.getvera.commarc@getvera.com ▾ +1 (866) 966-2272 x814

Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 9572
  • Karma: +729/-136
    • RTS Services Plugins
Re: Set & Get variable on remote Vera
« Reply #8 on: January 15, 2015, 04:17:24 pm »
@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

Offline parkerc

  • Sr. Hero Member
  • ******
  • Posts: 2330
  • Karma: +32/-44
  • Life Moves Pretty Fast....
    • Node Central
Re: Set & Get variable on remote Vera
« Reply #9 on: August 19, 2017, 10:39:07 am »
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 )

Quote
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 ..

Quote
LuaTest 1.5.2

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 )
« Last Edit: August 19, 2017, 10:51:48 am by parkerc »

Online akbooer

  • Master Member
  • *******
  • Posts: 5131
  • Karma: +221/-67
  • "Less is more"
Re: Set & Get variable on remote Vera
« Reply #10 on: August 19, 2017, 11:08:05 am »
when wrapped in luup.inet.wget it always returns a 0 (zero) - what am I missing ?

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:

Code: [Select]
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")

3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P.
Razberry, MySensors Arduino, HomeWave, AltUI, DataYours, openLuup, ZWay, ZeroBrane Studio.

Offline parkerc

  • Sr. Hero Member
  • ******
  • Posts: 2330
  • Karma: +32/-44
  • Life Moves Pretty Fast....
    • Node Central
Re: Set & Get variable on remote Vera
« Reply #11 on: August 19, 2017, 01:04:50 pm »
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 ?

Quote
LuaTest 1.5.2

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

Offline jswim788

  • Sr. Member
  • ****
  • Posts: 483
  • Karma: +23/-2
Re: Set & Get variable on remote Vera
« Reply #12 on: August 19, 2017, 01:36:50 pm »
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.

Offline parkerc

  • Sr. Hero Member
  • ******
  • Posts: 2330
  • Karma: +32/-44
  • Life Moves Pretty Fast....
    • Node Central
Re: Set & Get variable on remote Vera
« Reply #13 on: August 19, 2017, 02:07:11 pm »
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.

Code: [Select]
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"))
Quote
Runtime error: Line 5: bad argument #2 to 'tonumber' (base out of range)
« Last Edit: August 19, 2017, 02:23:17 pm by parkerc »

Offline parkerc

  • Sr. Hero Member
  • ******
  • Posts: 2330
  • Karma: +32/-44
  • Life Moves Pretty Fast....
    • Node Central
Re: Set & Get variable on remote Vera
« Reply #14 on: August 19, 2017, 02:25:02 pm »
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"

Quote
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
« Last Edit: August 19, 2017, 02:49:36 pm by parkerc »