Hi All,
I finally made the switch to HS2 and need some help fixing an error in an old motion sensor script. I have 0 ability to script so any help is welcome. Although the script appears to be working fine, I get the following error:
- Warning - GetDevice is not reliable for device enumeration. Please use the new GetDeviceEnumerator method.
Can ne1 make the required change in the sript that follows:
sub main()
dim p, device_count, device, un, ty, tim, hour, t, nam, loc, fl, fs, day, tru, ss
' Set Fail-Safe = 3 mintues
fs=3
'Determine the number of devices in HomeSeer
device_count=hs.devicecount
' Start the checking process
for p = 1 to device_count
' Set variables
set device = hs.getdevice(p)
ty=device.dev_type_string
' Determine if device is a Motion Sensor
tru = 0
if ty = "Motion Sensor" then tru=1
if ty = "MS13A (Hawkeye II)" then tru=1
if tru = 1 then
' Set variables
un=device.hc+device.dc
nam=device.name
loc=device.location
fl=hs.devicestring(un)
' Fail-Safe Turn Off
if fs<>0 then
if hs.ison(un) and hs.devicetime(un)=fs then
hs.setdevicestatus un,"3"
' hs.writelog "MOTION","><><><>< Fail-safe was invoked - " &loc &" " &nam
t="<table bgcolor="#460000" border="0" cellpadding="2" cellspacing="0" width="100%"><tbody><tr><td width="100%"> No Motion (00:00)</td></tr></tbody></table>"
hs.SetDeviceString un,t
fl="<"
end if
end if
' If the sensor is on then the following takes place
if hs.ison(un) then
if mid(fl,113,14)<>"motiondetected" then
'if fl<>"Motion Detected" then
ss="<table bgcolor="#ffff00" border="0" cellpadding="2" cellspacing="0" width="100%"><tbody><tr><td width="100%"> Motion Detected</td></tr></tbody></table>"
hs.setdevicestring un,ss
fl=mid(fl,204,6)
if right(fl,1)=")" then fl=left(fl,5)
' hs.writelog "MOTION",">>>>>>>> Motion Detected - "+nam+" "+loc+" - No Motion ("+fl+")"
end if
end if
' If the sensor is off then the following takes place
if hs.isoff(un) then
tim=hs.devicetime(un)
hour=int(tim/60)
tim=tim-(hour*60)
if len(tim)<2 then tim="0"+(cstr(tim))
tim=hour&":"&tim
if len(tim)<5 then tim="0"+tim
t="<table bgcolor="#460000" border="0" cellpadding="2" cellspacing="0" width="100%"><tbody><tr><td width="100%"> No Motion ("+tim+")</td></tr></tbody></table>"
hs.SetDeviceString un,t
' if mid(fl,199,1)="M" then hs.writelog "MOTION","<<<<<<<< No Motion Detected - "+nam+" "+loc
end if
end if
next
' This section determines how long HomeSeer has been active
tim=hs.devicetime("y2")
hour=int(tim/60)
day=int(hour/24)
tim=tim-(hour*60)
hour=hour-(day*24)
if len(tim)<2 then tim="0"+(cstr(tim))
tim=hour&" : "&tim
if len(tim)<7 then tim="0"+tim
tim=day&" : "&tim
if len(tim)<12 then tim="0"+tim
tim="<table border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr><td width="100%">"+" "+tim+"</td></tr></tbody></table>"
hs.setdevicestring ("y1"),tim
end sub
Many thanks
I finally made the switch to HS2 and need some help fixing an error in an old motion sensor script. I have 0 ability to script so any help is welcome. Although the script appears to be working fine, I get the following error:
- Warning - GetDevice is not reliable for device enumeration. Please use the new GetDeviceEnumerator method.
Can ne1 make the required change in the sript that follows:
sub main()
dim p, device_count, device, un, ty, tim, hour, t, nam, loc, fl, fs, day, tru, ss
' Set Fail-Safe = 3 mintues
fs=3
'Determine the number of devices in HomeSeer
device_count=hs.devicecount
' Start the checking process
for p = 1 to device_count
' Set variables
set device = hs.getdevice(p)
ty=device.dev_type_string
' Determine if device is a Motion Sensor
tru = 0
if ty = "Motion Sensor" then tru=1
if ty = "MS13A (Hawkeye II)" then tru=1
if tru = 1 then
' Set variables
un=device.hc+device.dc
nam=device.name
loc=device.location
fl=hs.devicestring(un)
' Fail-Safe Turn Off
if fs<>0 then
if hs.ison(un) and hs.devicetime(un)=fs then
hs.setdevicestatus un,"3"
' hs.writelog "MOTION","><><><>< Fail-safe was invoked - " &loc &" " &nam
t="<table bgcolor="#460000" border="0" cellpadding="2" cellspacing="0" width="100%"><tbody><tr><td width="100%"> No Motion (00:00)</td></tr></tbody></table>"
hs.SetDeviceString un,t
fl="<"
end if
end if
' If the sensor is on then the following takes place
if hs.ison(un) then
if mid(fl,113,14)<>"motiondetected" then
'if fl<>"Motion Detected" then
ss="<table bgcolor="#ffff00" border="0" cellpadding="2" cellspacing="0" width="100%"><tbody><tr><td width="100%"> Motion Detected</td></tr></tbody></table>"
hs.setdevicestring un,ss
fl=mid(fl,204,6)
if right(fl,1)=")" then fl=left(fl,5)
' hs.writelog "MOTION",">>>>>>>> Motion Detected - "+nam+" "+loc+" - No Motion ("+fl+")"
end if
end if
' If the sensor is off then the following takes place
if hs.isoff(un) then
tim=hs.devicetime(un)
hour=int(tim/60)
tim=tim-(hour*60)
if len(tim)<2 then tim="0"+(cstr(tim))
tim=hour&":"&tim
if len(tim)<5 then tim="0"+tim
t="<table bgcolor="#460000" border="0" cellpadding="2" cellspacing="0" width="100%"><tbody><tr><td width="100%"> No Motion ("+tim+")</td></tr></tbody></table>"
hs.SetDeviceString un,t
' if mid(fl,199,1)="M" then hs.writelog "MOTION","<<<<<<<< No Motion Detected - "+nam+" "+loc
end if
end if
next
' This section determines how long HomeSeer has been active
tim=hs.devicetime("y2")
hour=int(tim/60)
day=int(hour/24)
tim=tim-(hour*60)
hour=hour-(day*24)
if len(tim)<2 then tim="0"+(cstr(tim))
tim=hour&" : "&tim
if len(tim)<7 then tim="0"+tim
tim=day&" : "&tim
if len(tim)<12 then tim="0"+tim
tim="<table border="0" cellpadding="0" cellspacing="0" width="100%"><tbody><tr><td width="100%">"+" "+tim+"</td></tr></tbody></table>"
hs.setdevicestring ("y1"),tim
end sub
Many thanks
Comment