here is what worked for me
[code]dofile(“/root/SceneScripts/Devices.luup”)
local ProjectorState= luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, Projector) – Get Projector State
local Dimmlvl= luup.variable_get(“urn:upnp-org:serviceId:Dimming1”, “LoadLevelLast”, HueKitchen2)
local SwitchState= luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, KitchenLights) – Get Get Kitchen Light State
local SS_SID = “urn:micasaverde-com:serviceId:SecuritySensor1” – Security Sensor Service ID
local SD_SID = “urn:upnp-org:serviceId:Dimming1” – Switch Dimming Service ID
local SP_SID = “urn:upnp-org:serviceId:SwitchPower1” – Switch Power Service ID
local PH_SID = “urn:upnp-org:serviceId:althue1”
local period = 130 – Seconds
local DefDimmlvl = 3 – Default Dimming Load Level
local Dimthresh = 30 – Dimming Threshhold
– Scene Id
local Kitchenbrightall = “N0uJiME6DcilNln”
local Kitchendimall = “hNQMaFECpN0Gu9v”
local Kitchenmoviebright = “Iht1YQUJziXbdg9”
if (tonumber (Dimmlvl) >= tonumber (Dimthresh) ) then --Checks the dimming level
Dimmlvl = DefDimmlvl
luup.log(“Dim load Level > Dimming Threshold”)
end
if (SwitchState ~= “1”) then – Check Projector State
luup.log(“Turn on Lights”)
luup.call_action(SP_SID, “SetTarget”, {[“newTargetValue”] = 1}, KitchenLights) – Brighten Turn On Kitchen Lights
end
if (ProjectorState == “1”) then – Check Projector State
luup.log(“run Scene to brighten back 2 lights to 60”)
luup.call_action(PH_SID, “RunHueScene”, {hueSceneID= Kitchenmoviebright }, BurnsedPl)
luup.log(“Kitchen number 2 load leve change”)
luup.call_action(SD_SID, “SetLoadLevelTarget”, {newLoadlevelTarget=“60”}, HueKitchen2) – Brighten Kitchen Number 2
luup.log(“Kitchen number 4 load leve change”)
luup.call_action(SD_SID, “SetLoadLevelTarget”, {newLoadlevelTarget=“60”}, HueKitchen4) – Brighten Kitchen Number 4
else
luup.log(“Projector is off Brighten All Lights”) – Projector off
luup.log(“run Scene to brighten all lights”)
luup.call_action(PH_SID, “RunHueScene”, {hueSceneID= Kitchenbrightall }, BurnsedPl) – Brighten Scene
luup.log(“Kitchen number 1 load leve change”)
luup.call_action(SD_SID, “SetLoadLevelTarget”, {newLoadlevelTarget=“100”}, HueKitchen1) – Brighten Kitchen Number 1
luup.log(“Kitchen number 2 load leve change”)
luup.call_action(SD_SID, “SetLoadLevelTarget”, {newLoadlevelTarget=“100”}, HueKitchen2) – Brighten Kitchen Number 2
luup.log(“Kitchen number 3 load leve change”)
luup.call_action(SD_SID, “SetLoadLevelTarget”, {newLoadlevelTarget=“100”}, HueKitchen3) – Brighten Kitchen Number 3
luup.log(“Kitchen number 4 load leve change”)
luup.call_action(SD_SID, “SetLoadLevelTarget”, {newLoadlevelTarget=“100”}, HueKitchen4) – Brighten Kitchen Number 4
end
function checkLastTrip()
local lastTripmotion = luup.variable_get (SS_SID, “LastTrip”, KitchenMotion) --or os.time()
local Tripstate = luup.variable_get (SS_SID, “Tripped”, KitchenMotion)
local Ostime = os.time()
local osdifftime = os.difftime (tonumber (os.time()), tonumber (lastTripmotion))
luup.log("Os Time = " … Ostime … ", LastTrip = " … lastTripmotion … ", Diff = " … osdifftime … ", Trip state = " … Tripstate … “.”)
if (Tripstate == “0”) then
–(tonumber (os.difftime (tonumber (os.time()), tonumber (lastTripmotion))) >= tonumber (period))
luup.log("run Scene to dimm lights")
luup.call_action(PH_SID, "RunHueScene", {hueSceneID= Kitchendimall }, BurnsedPl) -- Brighten Scene
luup.log("Re-dimm the light Scene")
luup.call_action(SD_SID, "SetLoadLevelTarget", {newLoadlevelTarget= tonumber (Dimmlvl)}, HueKitchen1) -- Re-dimm the light.
luup.log("Re-dimm the light.")
luup.call_action(SD_SID, "SetLoadLevelTarget", {newLoadlevelTarget= tonumber (Dimmlvl)}, HueKitchen1) -- Re-dimm the light.
luup.log("Re-dimm the light.")
luup.call_action(SD_SID, "SetLoadLevelTarget", {newLoadlevelTarget= tonumber (Dimmlvl)}, HueKitchen2) -- Re-dimm the light.
luup.log("Re-dimm the light.")
luup.call_action(SD_SID, "SetLoadLevelTarget", {newLoadlevelTarget= tonumber (Dimmlvl)}, HueKitchen3) -- Re-dimm the light.
luup.log("Re-dimm the light.")
luup.call_action(SD_SID, "SetLoadLevelTarget", {newLoadlevelTarget= tonumber (Dimmlvl)}, HueKitchen4) -- Re-dimm the light.
else
luup.call_delay ("checkLastTrip", period) -- Check when the sensor was last tripped every <period> seconds.
end
end
luup.call_delay (“checkLastTrip”, period)
return true
[/code]
the problem is for some reason Lasttrip fails to work because it fails to update so your sensor will look like it hasnt been tripped
so i just decresed the timeout to 1 min and used time out instead