Update Device/Node to show last tripped date/time

Hi

I’m looking to move my alarm system over from UI5 to UI7, and wanted to ask if anyone knew how to update the device .json/.xml file (for motion and door sensors ) in UI7 to show the date/time that particular device was last tripped (see UI5 & UI7 devices Screen shots below)

Big thank you to @akbooer for doing this many years ago, sadly my use of Vera has reduced drastically since then, so I’m no long as familiar with everything/Lua etc as I once was.

TripTimestamp.lua

module("TripTimestamp", package.seeall)

version = "2014.08.24  @akbooer"

local DEVICE_TYPE = "urn:schemas-micasaverde-com:device:MotionSensor:1"
local SERVICE_ID  = "urn:micasaverde-com:serviceId:SecuritySensor1"
local TIME_FORMAT = "%d/%m %H:%M"

-- watch callback
function _G.TripTimestampWatcher (dev, srv, var, old, new)
  local timestamp = os.date (TIME_FORMAT, new)
  luup.variable_set (srv, "Timestamp", timestamp, dev) 
end

-- initialisation 
for i,d in pairs (luup.devices) do
  if d.device_type == DEVICE_TYPE then 
    local lastTrip = luup.variable_get (SERVICE_ID, "LastTrip", i)
    if lastTrip then
      _G.TripTimestampWatcher (i, SERVICE_ID, nil, nil, lastTrip)               -- set latest value
      luup.variable_watch ('TripTimestampWatcher', SERVICE_ID, "LastTrip", i)   -- watch for future changes
    end
  end
end
1 Like