Should be doable, try these scripts. I adapted them from scripts I use in my own system. I haven't tested the changes however, you may have to fix typos/debug.
Device Script, turns the light on or brightens it when motion detected:
Code: Select all
commandArray = {}
local TimerName = "Living Room Minder" --Name of the dummy switch that determines whether the light should auto on
local MotionSensor = "Living Room Motion Sensor" --Name of the motion sensor in the room
local LightSwitch = "Living Room Dimmer" -- Name of the light switch
local LightTimer = "Living Room Dimmer Blind Timeout" -- Name of auto-off timeout user variable
local LastLightStateHigh = "Living Room LghtSttHg" -- Light level to set to when motion detected user variable
if ((devicechanged[MotionSensor] == 'On') and (otherdevices[TimerName] == 'On') and (otherdevices[LightSwitch] == 'Off')) then
local s1 = otherdevices_lastupdate[LightSwitch]
if (s1 == nil) then
s1 = "2000-01-01 00:00:00"
end
local year1 = string.sub(s1, 1, 4)
local month1 = string.sub(s1, 6, 7)
local day1 = string.sub(s1, 9, 10)
local hour1 = string.sub(s1, 12, 13)
local minutes1 = string.sub(s1, 15, 16)
local seconds1 = string.sub(s1, 18, 19)
local t1 = os.time()
local t2 = os.time{year=year1, month=month1, day=day1, hour=hour1, min=minutes1, sec=seconds1}
local difference1 = t1-t2
local difference2 = t1-t3
if (difference1 > tonumber(uservariables[LightTimer])) then -- If the light was turned off don't turn it back on!
if (tonumber(uservariables[LastLightStateHigh]) ~= "On") then
commandArray[LightSwitch]='Set Level ' .. tonumber(uservariables[LastLightStateHigh])
else
commandArray[LightSwitch] = "On"
end
end
end
return commandArray
Timer script, turns the light off or sets it to low light level after timeout:
Code: Select all
commandArray = {}
local LightSwitch = "Living Room Dimmer" -- CHANGE: Name of light switch
local MotionSensor = "Living Room Motion Sensor" -- CHANGE: Name of motion sensor.
local LightTimer = "Lvngrm Light Off Timeout" -- CHANGE: Name of auto-off timeout user variable
local LvngRmMndr = "Living Room Minder" -- Dummy switch to Enable/disable auto off.
local LastLightStateLow = "LvngRmLghtSttLw" -- Light level to set to when NO motion detected user variable
--LightSwitch could be a dimmer, so we check if it's not off rather than if it's on.
if (otherdevices[LvngRmMndr] == "On" and otherdevices[LightSwitch] ~= "Off") then
local s1 = otherdevices_lastupdate[MotionSensor]
if (s1 == nil) then
s1 = "2000-01-01 00:00:00"
end
local year1 = string.sub(s1, 1, 4)
local month1 = string.sub(s1, 6, 7)
local day1 = string.sub(s1, 9, 10)
local hour1 = string.sub(s1, 12, 13)
local minutes1 = string.sub(s1, 15, 16)
local seconds1 = string.sub(s1, 18, 19)
local t1 = os.time()
local t2 = os.time{year=year1, month=month1, day=day1, hour=hour1, min=minutes1, sec=seconds1}
local difference1 = t1-t2
if (difference1 > tonumber(uservariables[LightTimer])) then
if (tonumber(uservariables[LastLightStateLow]) ~= "Off") then
commandArray[LightSwitch]='Set Level ' .. tonumber(uservariables[LastLightStateLow])
else
commandArray[LightSwitch] = "Off"
end
end
end
return commandArray
You WILL need another script to set the light level variable when you change it at the switch. I don't have anything like it so I won't bother providing it here, but it should be simple enough. If you don't the light values will ALWAYS default to the values you set in the variables.