Condition: <when home isn't occupied>
Script:
Code: Select all
Sub Main(ByVal Params as String)
Dim device_value, device_name, device_id, dv, device_location, en, ldt, ld, deviceObj, device_type, device_status, msgSubject, msgBody
en = hs.GetDeviceEnumerator
ldt = "01/01/2009"
Do while not en.Finished
dv = en.GetNext
if not dv is nothing then
if DateDiff("s", hs.DeviceLastChange(dv.hc & dv.dc), ldt) < 0 then
ldt = hs.DeviceLastChange(dv.hc & dv.dc)
ld = dv.hc & dv.dc
end if
end if
Loop
Device_id = hs.GetDeviceRef(ld)
deviceObj = hs.GetDeviceByRef(device_id)
device_value = hs.DeviceValue(ld)
device_name = deviceObj.name
device_location = deviceObj.location
device_type = deviceObj.dev_type_string
device_status = hs.DeviceStatus(ld)
if instr(device_type, "Xanura") or instr(device_type, "Plugwise") then
msgSubject = "There was an unusual change of a device " & device_name & ". "
msgBody = msgSubject
if not isDBnull(device_location) then
msgBody = msgBody & "The location of the device is " & device_location & ". "
end if
if not device_value = 0 then
msgBody = msgBody & "The value of the device is " & device_value & ". "
end if
select case device_status
case 2
msgBody = msgBody & "The status of the device is ON."
case 3
msgBody = msgBody & "The status of the device is OFF."
case 4
msgBody = msgBody & "The status of the device is DIM."
end select
hs.SendEmail("<to emailaddress>","<from emailaddress>",msgSubject,msgBody)
end if
End Sub