Vera Daily Check For Offline Device

I have a battery-powered thermostat in a deep freeze that I want to check for being offline on a daily basis. I know that I get an alert when it goes offline the first time, but unfortunately, I’ve learned that depending on what’s going on, that can get forgotten.

My best guess to achieve this is to have Luup routine that runs daily and checks the device’s status. What variable do I check? I see “PollOK” and “CommFailure”, but I have no idea what values are stored there. Any help would be appreciated.

Hello @geoffschultz

To perform a daily check on your battery-powered thermostat’s status, you can use a Lua script in a scene. The key variable to monitor is:

  • CommFailure: Indicates communication failure.
    • 0: Device is online.
    • 1: Device is offline.

Here’s a Lua script you can include in your daily scene to check the status and send a notification if the thermostat is offline:

local device_id = [Your_Device_ID_Here]
local user_id = [Your_User_ID_Here]
local comm_failure = luup.variable_get("urn:micasaverde-com:serviceId:HaDevice1", "CommFailure", device_id)

if comm_failure == "1" then
    local description = "Thermostat is offline. Please check the device."
    local url = string.format("http://127.0.0.1:3480/data_request?id=add_alert&device=%d&type=3&source=3&description=%s&users=%s", device_id, luup.url_encode(description), user_id)
    luup.inet.wget(url)
end

What to do:

  1. Replace [Your_Device_ID_Here] with your thermostat’s device ID.
  2. Replace [Your_User_ID_Here] with your Vera user ID.
  3. Add this script to a scene set to run daily.

This script checks if CommFailure equals 1 (device offline). If it is, it sends a notification to your Vera account using the add_alert API.

Let us know if you need further assistance!

1 Like

Thank you very much for the concise answer!

I finally have some time to do this. Where do I get the “User ID” from? Is that an email address or a numerical value? I can’t see a User ID in any of the settings.

How do I obtain the “User ID” field?

Hello @geoffschultz ,

  • Access the following URL in your browser (replace <VeraIP> with your Vera controller’s IP address)
http://<VeraIP>/port_3480/data_request?id=user_data&output_format=json
  • Look through the JSON output for the “users” section:
  • You’ll find entries that look like this:
"users": [
  {
    "id": "123456",  
    "Name": "YourUsername"
  }
]
  • The “id” is your User ID.

I was getting an error that luup.url_encode(description) was returning nil, so I simplified this to return true or false and then had the scene notify me (which it only does if the luup code returns true). Works fine.

1 Like

Hello @geoffschultz

We’re really glad to hear that it worked for you! :tada: If possible, could you share the full solution here? It would be incredibly helpful for other users who might encounter the same requeriment in the future.

Your contribution could make a big difference for the community. :blush:

Thank you, and let us know if there’s anything else we can assist you with!