' This script allows two motion detectors to control one light.
' Either motion detector will turn on the light.
' Both motion detectors have to send off before the light will go off.
' Create a virtual device. This can be used to lock the light on.
' Create two events.
' Event 1 - Respond Type By X10. Set to the code of the first motion detector. Run script dual_motion.txt
' Event 2 - Respond Type By X10. Set to the code of the second motion detector. Run script dual_motion.txt
sub main()
dim c
dim d
dim e
dim f
dim g
dim h
dim md1
dim md2
dim lm1
dim lpr
dim vnum
dim lpl
dim lpe
dim tm1
dim tm2
md1 = "A10" ' Replace A10 with your first motion detectors code.
md2 = "A12" ' Replace A12 with your second motion detectors code.
lm1 = "A1" ' Replace A1 with the module code that you want to control.
lpe = 100 ' Replace 100 with the percentage to turn the light to before the bedtime set above.
vnum = "z11" ' Replace Z11 with the virtual device you setup for the lock.
c = hs.Lastx10
d = hs.StringItem(c,2,";")
e = hs.StringItem(c,3,";")
lpr = 100 - lpe
if e = 2 then
f = d + "On"
else
f = d + "Off"
end if
if f = md2 + "On" then
if ah.IsOff(lm1) then
if lpr = 0 then
hs.execx10 lm1,"On",100
else
hs.execx10 lm1,"Dim", lpr
end if
end if
hs.SetDeviceString md2, ""
elseif f = md1 + "On" then
if ah.IsOff(lm1) then
if lpr = 0 then
hs.execx10 lm1,"On",100
else
hs.execx10 lm1,"Dim", lpr
end if
end if
hs.SetDeviceString md1, ""
elseif f = md2 + "Off" then
g = hs.IsOn(md1)
h = hs.DeviceStatus(vnum)
if g = 0 then
if h = 3 then
hs.execx10 lm1, "Off", 0
end if
end if
hs.SetDeviceString md2, ""
elseif f = md1 + "Off" then
g = hs.IsOn(md2)
h = hs.DeviceStatus(vnum)
if g = 0 then
if h = 3 then
hs.ExecX10 lm1, "Off", 0
end if
end if
hs.SetDeviceString md1, ""
else
hs.WriteLog "Info", "There was an error in the dual motion script."
end if
end sub