Two vera3 to watch each other

Im having two vera 3. One in norway and one in Thailand. Is it possible to have them Ping each other to check if the other one is online/alive and then notify if not. Anyone done this?

You can do this with a scene and a virtual switch.

  1. Install the Virtual Switch plugin from the MiOS Marketplace.
  2. Set the virtual switch to send you a notification if it’s turned on.
  3. Create a scene and set it to run every 15 minutes (or whatever time interval you want to ping your Vera).
  4. Set the scene to turn on the Virtual Switch and to turn it off 1 minute later.
  5. Add this code in the scene, which will allow the scene to run only if the other Vera is not responding.

In this code:

[ul][li]fwd is the fwd server number. If the Vera you want to ping has an even serial number, fwd is 2, otherwise it’s 1.[/li]
[li]username is your MiOS username.[/li]
[li]password is your MiOS password.[/li]
[li]vera_serial is the serial number of the Vera you want to ping.[/li][/ul]

[code]local fwd = “2” – The fwd server number. Can be ‘1’ or ‘2’.
local username = “username” – Your MiOS username.
local password = “password” – Your MiOS password.
local vera_serial = “vera_serial” – The serial # of Vera.

local status, content = luup.inet.wget(“https://fwd”…fwd…“.mios.com/”…username…“/”…password…“/”…vera_serial…“/data_request?id=alive”)
if (content ~= “OK”) then
return true
end

return false[/code]

[quote=“mcvflorin, post:2, topic:171530”]You can do this with a scene and a virtual switch.

  1. Install the Virtual Switch plugin from the MiOS Marketplace.
  2. Set the virtual switch to send you a notification if it’s turned on.
  3. Create a scene and set it to run every 15 minutes (or whatever time interval you want to ping your Vera).
  4. Set the scene to turn on the Virtual Switch and to turn it off 1 minute later.
  5. Add this code in the scene, which will allow the scene to run only if the other Vera is not responding.

In this code:

[ul][li]fwd is the fwd server number. If the Vera you want to ping has an even serial number, fwd is 2, otherwise it’s 1.[/li]
[li]username is your MiOS username.[/li]
[li]password is your MiOS password.[/li]
[li]vera_serial is the serial number of the Vera you want to ping.[/li][/ul]

[code]local fwd = “2” – The fwd server number. Can be ‘1’ or ‘2’.
local username = “username” – Your MiOS username.
local password = “password” – Your MiOS password.
local vera_serial = “vera_serial” – The serial # of Vera.

local status, content = luup.inet.wget(“https://fwd”…fwd…“.mios.com/”…username…“/”…password…“/”…vera_serial…“/data_request?id=alive”)
if (content ~= “OK”) then
return true
end

return false[/code][/quote]

Thank you!

I have a few more question regarding this topic.

Is there a way to add some code in the startup script to send a notification like: “Im online”

Its handy in a case on black out /power loss… i would like to know when my Vera3 abroad wakes up.
To make it perfect it would be cool if it could log the shutdown time.
e.g ("Restart after shutdown (3h 20 min))
Possible?

My goal down the road is to have a custom notification with a kind of shutdown report…
Giving me data on critical sensors just after a shutdown… e.g freezer temp.
Any ideas where to start?

Thank you all for helping me out!

Put the following code in Startup Lua. You must replace:

USER = 0

… with your user ID. You can get the user ID from user_data. Use this request to get the user_data:

http://Vera_IP:3480/data_request?id=user_data&output_format=xml

Search in the user_data for a scene with notifications and look for the users attribute (see attached image).

local function urlEncode (s)
    if (s ~= nil) then
        s = s:gsub("\n", "\r\n")
        s = s:gsub("([^%w ])", function (c)
                                    return string.format("%%%02X", string.byte(c))
                               end)
        s = s:gsub(" ", "%%20")
    end
    return (s or "nil")
end

local USER = 0

local url = "https://".. luup.event_server .."/alert?"..
            "PK_AccessPoint=".. string.format("%d", luup.pk_accesspoint) ..
            "&HW_Key=".. tostring(luup.hw_key) ..
            "&DeviceID=0"..
            "&LocalDate=".. os.date("%Y-%m-%d%%20%H:%M:%S") ..
            "&LocalTimestamp=".. tostring(os.time()) ..
            "&AlertType=3&SourceType=3&Argument=1&Format=&Code=&Value=" ..
            "&Description="..urlEncode("I'm online") ..
            "&Users=".. USER

luup.inet.wget(url, 5)