Aller au contenu

angelz

Membres confirmés
  • Compteur de contenus

    70
  • Inscription

  • Dernière visite

À propos de angelz

  • Date de naissance 17 février

Profile Information

  • Sexe :
    Male
  • Box
    Home Center 2
  • Version
    4

Visiteurs récents du profil

1 056 visualisations du profil

angelz's Achievements

Newbie

Newbie (1/14)

4

Réputation sur la communauté

  1. Bonjour, j'utilise ce script depuis quelque semaine et ca marche bien sauf que j'ai des fausse detection j'aimerais dire au script : si une detection de mouvement, attendre 1 seconde ou plus et reverifier si il y a toujours une detection et seulement la allumer la lampe mais je ne vois pas comment faire. voici mon code : --[[ %% properties 65 value 79 value %% globals TimeOfDay PresentState --]] --[[ Change - XXX value - above. One for motion sensor, one for Light sensor. TimeOfDay global variable and lux make sure that the scene will be triggered when you are already in the room and something changes. Set your settings below, lights and add extra functions Feel free to suggest changes or contact when having problems. It is not allowed to sell or distribute this software and earlier versions without the approval of Control Living © 2014 - 2015 Smart lights by Control Living Version 1.6.7 --]] -------------------------------------------------------------------- -----------------------YOUR LIGHT SETTINGS-------------------------- motionSensorID = {65}; -- change id for your motion sensor. LuxSensorID = {79}; -- change id for your light sensor. actionDevice = 100; -- change id for your light sensor. --Enter the name of your Global variable. WITHOUT IT, THE SCENE DOES NOT WORK. Capital sensitive! sleepState = "SleepState"; --Sleep globalstate variable. timeOfDay = "TimeOfDay"; --Time of Day Global variable. presentState = "PresentState"; --Present state Global variable. --Enter the values of your global variables stated above. If not using, copy the name in front of the "YourValueName" sleepStateMapping = {Sleeping="Sleeping", Awake="Awake"}; timeOfDayMapping = {Morning="Morning", Day="Day", Evening="Evening", Night="Night"}; presentStateMapping = {Home="Home", Away="Away", Holiday="Holiday"}; -- Set the lux value for which the lights have to be turned on. -- If you don't want to use the MinLux then just set it to: 65535 minLuxMorning = 2500; minLuxDay = 2500; minLuxEvening = 2500; minLuxNight = 2500; --If the current lux value is above the maxlux, the lights will turn off after their set onTime. maxLuxMorning = 6000; maxLuxDay = 6000; --[[ Now the most important part: Here you can enter what light, for how long and at what value has to be turned on. Leave empty brackets for no lights. To set the light value without timer use 2 parameters: {id=LightID, setValue="VALUE"} To set the light value with timer use 3 parameters: {id=LightID, setValue="VALUE", onTime=timeInSeconds } To set the light value for RGBW: use the above, where setValue is: setValue={R="255",G="255",B="255",W="255"} -- RGBW set: {id=LightID, setValue={R="255",G="255",B="255",W="255"}, onTime=timeInSeconds } --]] lightsSleeping = {}; --lights that are triggered when Sleepstate is sleeping. lightsMorning = {{id=actionDevice, setValue="turnOn", onTime=20}}; lightsDay = {{id=actionDevice, setValue="turnOn", onTime=20}}; lightsEvening = {{id=actionDevice, setValue="turnOn", onTime=20}}; lightsNight = {{id=actionDevice, setValue="turnOn", onTime=20}}; --Manual Override, the time that lights will not be turned ON again after manually turning them off. OverrideFor = 90; dimmDownTime = 10; -------------------------------------------------------------------- -------------------------EXTRA FEATURES----------------------------- extraMorningFunc = function() -- Add your extra code here. If you want some checks or maybe run a virtual device button. --This code is always triggered if there is motion. -- movieLights = {{180, "10"},{181, "10"} }; --if (xbmc == "playing" ) then CallLightArray(movieLights); ExtraDebug("Extra morning function called"); end extraDayFunc = function() -- Add your extra code here. If you want some checks or maybe run a virtual device button. --This code is always triggered if there is motion. ExtraDebug("Extra day function called"); end extraEveningFunc = function() -- Add your extra code here. If you want some checks or maybe run a virtual device button. --This code is always triggered if there is motion. ExtraDebug("Extra evening function called"); end extraNightFunc = function() -- Add your extra code here. If you want some checks or maybe run a virtual device button. --This code is always triggered if there is motion. ExtraDebug("Extra night function called"); end extraLightTriggerChecks = function() --add extra checks here. and return the total true or false value. --if returning false the lights will not be triggered. -- for instance: return ( (pcTurnedOff == true ) and (xbmc ~= "Empty") ); -- return true to enable lights to turn on return true; end extraOffChecks = function() --return true to keep lights on. return false; end -------------------------------------------------------------------- ----------------------ADVANCES SETTINGS----------------------------- local showStandardDebugInfo = true; -- Debug shown in white local showExtraDebugInfo = false; -- Debug shown in orange -------------------------------------------------------------------- -------------------------------------------------------------------- -- DO NOT CHANGE THE CODE BELOW -- -------------------------------------------------------------------- --UPDATE FROM HERE --private variables startSource = fibaro:getSourceTrigger(); keepLightsOn = false; timerRunning = false; previousLights = nil; version = "1.6.7"; SavedState = { homeStatus = "", sleepState = 0, timeOfDay = "", lux = 0, motion = 0, startTime = 0 } CurrentState = { homeStatus = "", sleepState = "", timeOfDay = "", lux = 0, motionState = 0, currentLightArray = {} } RGBWDeviceType = { "com.fibaro.RGBW", "com.fibaro.colorController", "com.fibaro.FGRGBW441M" } BinaryDeviceType = { "com.fibaro.binarySwitch","com.fibaro.FGWP101", "com.fibaro.developer.angelz.SwitchLumiereFhem", "turnOn" } DimmerDeviceType = { "com.fibaro.multilevelSwitch" } OffModes = {None, ByScene, ManualOverride } function Debug( color, message ) fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span")); end --Making sure that only one instance of the scene is running. fibaro:sleep(50); --sleep to prevent all instances being killed. if (fibaro:countScenes() > 1) then if (showExtraDebugInfo) then Debug( "grey", "Abort, Scene count = " .. fibaro:countScenes()); end fibaro:abort(); end --------------------------EXECUTION---------------------------------- function SetCurrentStatus() ExtraDebug("Updating current variable statuses"); CurrentState.homeStatus = GetPresentState(); CurrentState.timeOfDay = GetTimeOfDay(); CurrentState.sleepState = GetSleepState(); CurrentState.lux = GetAverageLuxValue(); CurrentState.motionState = GetCurrentMotionStatus(); end function SaveCurrentStatus() ExtraDebug("Saving current variable statuses"); SavedState.homeStatus = CurrentState.homeStatus; SavedState.timeOfDay = CurrentState.timeOfDay; SavedState.sleepState = CurrentState.sleepState; SavedState.lux = CurrentState.lux; SavedState.motion = CurrentState.motionState; end function CheckStatusChanges() ExtraDebug("Status change check"); if (CurrentState.homeStatus ~= SavedState.homeStatus ) or (CurrentState.timeOfDay ~= SavedState.timeOfDay ) then if (CurrentState.homeStatus ~= presentStateMapping.Home ) then TurnOffLights(); else SceneTriggered(); --reset time. end; end SaveCurrentStatus(); -- if we still have a motion then reset timer. if ( (CurrentState.motionState ~= 0 or extraOffChecks() ) and not IsMaxLuxExceeded() ) then ExtraDebug( "Resetting time" ); SavedState.startTime = os.time(); else ExtraDebug("Timer is not reset."); end --any other case, we are not resetting the timer. end function IsMaxLuxExceeded() if (CurrentState.timeOfDay == timeOfDayMapping.Morning and CurrentState.lux > maxLuxMorning ) then ExtraDebug( "Current lux value: " .. CurrentState.lux .. " higher then max Lux Morning: " .. maxLuxMorning .. "."); return true; elseif (CurrentState.timeOfDay == timeOfDayMapping.Day and CurrentState.lux > maxLuxDay ) then ExtraDebug( "Current lux value: " .. CurrentState.lux .. " higher then max Lux Day: " .. maxLuxDay .. "."); return true; end return false; end function LightsOff( lightArray ) local stillLightsOn = 0; local currentTime = os.time(); for i = 1,#lightArray do if ( lightArray[i].onTime ~= nil) then lightItem = lightArray[i]; lightItem.OffMode = CheckManualOverrideItem( lightItem ); --local if ( lightItem.OffMode == "ManualOverride" ) then ExtraDebug("Manual override for light: [" .. lightItem.id .. "]" .. lightItem.name .. " active, not turning on"); goto continue; end --On till: local timeL = SavedState.startTime + (lightItem.onTime); local timeLeft = timeL - currentTime; if (timeLeft >= 0 ) then ExtraDebug("Time left for: [" .. lightItem.id .. "]" .. lightItem.name .. ": " .. timeLeft .. " seconds" ); end if ( timeLeft < dimmDownTime ) then if ( lightItem.OffMode ~= "ManualOverride" ) then lightItem.OffMode = "ByScene"; end if ( (timeLeft <= 0) and (lightItem.currentValue ~= 0) ) then fibaro:call(lightItem.id, "turnOff"); StandardDebug("Switch off light: [" .. lightItem.id .. "]'" .. lightItem.name .."'"); else if ( item.lightType == "com.fibaro.multilevelSwitch" ) then currentValueDiv = roundit(((lightItem.currentValue) / (dimmDownTime)), 0); currentValueNew = (lightItem.currentValue - currentValueDiv); if (currentValueNew <=0 ) then currentValueNew = 0; end fibaro:call(lightItem.id, "setValue", tostring(currentValueNew)); end stillLightsOn = stillLightsOn + 1; end elseif (CheckLightToBeTurnedOnAgain(lightItem)) then ExtraDebug("Turn light: " .. lightItem.id .. " back on"); turnLightOn(lightItem); lightItem.OffMode = ""; stillLightsOn = stillLightsOn + 1; else lightItem.OffMode = "NoOverride"; stillLightsOn = stillLightsOn + 1; end end ::continue:: end return stillLightsOn; end function KeepLightsOnTimer() ExtraDebug("--------------- Timer running ---------------"); ExtraDebug("starting with while loop, to keep lights on"); SavedState.startTime = os.time(); SaveCurrentStatus(); sleepTime = 1000; while ( keepLightsOn ) do ExtraDebug("--------------- next timer run ---------------"); fibaro:sleep(sleepTime); start_time = os.clock(); SetCurrentStatus(); currentLightArray = GetTimeOfDayLightArray(); UpdateLightValues(currentLightArray); CheckStatusChanges(); local stillLightsOn = 0; stillLightsOn = LightsOff( currentLightArray ); if (stillLightsOn == 0 ) then keepLightsOn = RunManualOverrideMode( currentLightArray ); end_time = 0; --if lights turned back on after override. else end_time = os.clock() end elapsed_time = (end_time - start_time) * 1000; sleepTime = 1000 - elapsed_time; end end function CheckManualOverrideItem( currentItem ) --ExtraDebug("Manual override check for: [" .. currentItem.id .. "]" .. currentItem.name); --fibaro:debug(currentItem.currentValue) --fibaro:debug(currentItem.OffMode) if (currentItem.currentValue == 0 and currentItem.OffMode ~= "ByScene" ) then ExtraDebug( "Manual override for light: [" .. currentItem.id .. "]" .. currentItem.name .. " active" ); return "ManualOverride"; elseif (currentItem.currentValue ~= 0 and currentItem.OffMode == "ManualOverride" ) then ExtraDebug( "Manual override for light: [" .. currentItem.id .. "]" .. currentItem.name .. " cancelled" ); return "NoOverride"; end return currentItem.OffMode; --returning current mode; end function RunManualOverrideMode( currentLightArray ) OverrideForAll = CheckIfAllInOverrideMode(currentLightArray); if ( OverrideForAll ) then ExtraDebug("-----------------Override Mode---------------"); OverrideTimer = os.time(); while ( OverrideForAll and (OverrideTimer + OverrideFor ) - os.time() > 0 ) do ExtraDebug("Still in override for: " .. (OverrideTimer + OverrideFor ) - os.time() .. " seconds" ); fibaro:sleep(1000); UpdateLightValues(currentLightArray); OverrideForAll = CheckIfAllInOverrideMode(currentLightArray); motion = GetCurrentMotionStatus(); if ( motion ~= 0 ) then OverrideTimer = os.time(); end end else return false; end -- if ( (OverrideTimer + OverrideFor ) - os.time() <= 0 ) then --time has end. So not continue to run lights loop -- return false; -- end if (OverrideForAll) then return false; --run lights else return true; end end function CheckIfAllInOverrideMode(currentLightArray) OverrideForAll = 0; for i = 1,#currentLightArray do if ( CheckManualOverrideItem(currentLightArray[i]) == "ManualOverride" ) then OverrideForAll = OverrideForAll +1; else return false; end end if ( OverrideForAll ~= 0 and OverrideForAll == #currentLightArray ) then return true; end return false; end function RunTimer() if ( keepLightsOn and not timerRunning ) then ExtraDebug("Starting timer, not yet running"); timerRunning = true; KeepLightsOnTimer(); else ExtraDebug("Timer already running, returning"); end end function TurnOffLights() local timeOfDayArray = GetTimeOfDayLightArray(); SetLightValues(timeOfDayArray); UpdateLightValues(timeOfDayArray); CallLightArray(timeOfDayArray, "off" ); return; end ----------------------Turn lights on functions------------------------ function CallLightArray( lightArray, turnOnOrOff ) if (#lightArray == 0 ) then if (CurrentState.sleepState == sleepStateMapping.Sleeping) then noLightsSetText = "lightsSleeping"; else noLightsSetText = CurrentState.timeOfDay; end StandardDebug( "No lights set for " .. noLightsSetText ); return; end if not ( CheckIfTable(lightArray, "lights" .. CurrentState.timeOfDay ) ) then return end for i = 1,#lightArray do if not ( CheckIfTable(lightArray[i], "lights" .. CurrentState.timeOfDay ) ) then break end lightItem = lightArray[i]; if (turnOnOrOff == "on" ) then turnLightOn(lightItem); if (lightItem.onTime ~= nil) then keepLightsOn = true; end else fibaro:call(lightItem.id, "turnOff"); --Always turn off, if HC2 light status is not actual. if ( lightItem.currentValue ~= 0) then keepLightsOn = false; StandardDebug("Switch off light: [" .. lightItem.id .. "]'" .. lightItem.name .."'"); end end end StandardDebug( "Lights turned: " .. turnOnOrOff .. " for " .. CurrentState.timeOfDay ); end function turnLightOn( lightItem ) if (lightItem.lightType == "com.fibaro.multilevelSwitch" ) then fibaro:call(lightItem.id, "setValue", tostring(lightItem.setValue)); StandardDebug( "Set: [" .. lightItem.id .. "]'" .. lightItem.name .. "' to Value: " .. lightItem.setValue ); elseif ( lightItem.lightType == "com.fibaro.RGBW" )then StandardDebug( "Turn: [" .. lightItem.id .. "]'" .. lightItem.name .. "' On"); if ( lightItem.setValue.brg~= nil ) then fibaro:call(lightItem.id, "setBrightness", tostring(lightItem.setValue.brg)); else local clrvalues =lightItem.setValue; fibaro:call(lightItem.id, "setColor", clrvalues.R, clrvalues.G, clrvalues.B, clrvalues.W) end elseif (lightItem.lightType == "com.fibaro.binarySwitch") then fibaro:call(lightItem.id, "turnOn"); StandardDebug( "Turn: [" .. lightItem.id .. "]'" .. lightItem.name .. "' On"); end end function CheckPreviousLights( NewLightArray ) if ( previousLights ~= nil ) then for i = 1,#previousLights do local lightItem = previousLights[i]; for i = 1,#NewLightArray do local lightItem1 = NewLightArray[i]; inarray = false; if ( lightItem.id == lightItem1.id ) then inarray= true; break end end if not ( inarray ) then fibaro:call(lightItem.id, "turnOff"); end end end previousLights = NewLightArray; end function LightperDayPart( minLux, lightArray ) local newLuxValue = CurrentState.lux; if ( extraLightTriggerChecks() ) then if ( newLuxValue > minLux ) then StandardDebug( "Sensor lux: " .. newLuxValue .. " higher then minValue: " .. minLux .. " : no action"); else StandardDebug("Sensor lux: " .. newLuxValue .. " is lower then minValue: " .. minLux); SetLightValues(lightArray); CallLightArray( lightArray, "on" ); CheckPreviousLights( lightArray ); end else ExtraDebug("ExtraLightTriggerChecks failed, so no lights"); end end function SceneTriggered() if ( CurrentState.homeStatus ~= presentStateMapping.Home ) then ExtraDebug("Presentstate = not at home, so no lights"); elseif ( CurrentState.sleepState == sleepStateMapping.Sleeping ) then LightperDayPart( 65535, lightsSleeping ); elseif ( CurrentState.timeOfDay == timeOfDayMapping.Morning ) then extraMorningFunc(); LightperDayPart( minLuxMorning, lightsMorning ); elseif ( CurrentState.timeOfDay == timeOfDayMapping.Day ) then extraDayFunc(); LightperDayPart( minLuxDay, lightsDay ); elseif ( CurrentState.timeOfDay == timeOfDayMapping.Evening ) then extraEveningFunc(); LightperDayPart( minLuxEvening, lightsEvening ); elseif ( CurrentState.timeOfDay == timeOfDayMapping.Night ) then extraNightFunc(); LightperDayPart( minLuxNight, lightsNight ); else ErrorDebug( "No lights: " .. CurrentState.timeOfDay ); end if (keepLightsOn == true) then RunTimer(); end end function SceneTriggeredByLights( st ) if (st == "off") then ExtraDebug( "light turned off, sleep 4 sec" ); fibaro:sleep(4000); elseif (st == "on") then ExtraDebug( "light turned on, activating timer" ); fibaro:sleep(4000); --TODO: add light to current array. --keepLightsOn = true; --RunTimer(); end end ------------------------STATUS functions------------------------------ function GetTimeOfDay() return LookupGlobal( timeOfDay, "TimeOfDay", "Day"); end function GetSleepState() return LookupGlobal( sleepState, "sleepState", "Awake"); end function GetPresentState() return LookupGlobal( presentState, "presentState", "Home"); end function LookupGlobal( name, stateName, default ) local ps = fibaro:getGlobalValue( name ); if ( (ps ~= "") and (ps ~= nil ) ) then ExtraDebug("returned " .. stateName .. ": " .. ps ); return ps; else ErrorDebug( stateName .. " variable not found"); return default; end end function lightsStatus( id ) --check if lights are already on. allLights = {lightsSleeping, lightsMorning, lightsDay, lightsEvening, lightsNight }; for i = 1,#allLights do for iL = 1, #allLights[i] do local lightItem = allLights[i][iL]; if ( lightItem.id == tonumber(id) ) then if ( lightItem.currentValue == 0 ) then return "off"; else return "on"; end end end end ErrorDebug("Light status unknown"); return "Unknown"; end function GetTimeOfDayLightArray() if ( CurrentState.sleepState == sleepStateMapping.Sleeping ) then return lightsSleeping; elseif ( CurrentState.timeOfDay == timeOfDayMapping.Morning ) then return lightsMorning; elseif ( CurrentState.timeOfDay == timeOfDayMapping.Day ) then return lightsDay; elseif ( CurrentState.timeOfDay == timeOfDayMapping.Evening ) then return lightsEvening; elseif ( CurrentState.timeOfDay == timeOfDayMapping.Night ) then return lightsNight; end end function GetCurrentMotionStatus() local sensorbreached = 0; if (CheckIfTable(motionSensorID, "motionSensorID") ) then for i = 1,#motionSensorID do if ( tonumber(fibaro:getValue(motionSensorID[i], "value")) > 0 ) then sensorbreached = 1; end end else --if not a table, just return the value of the containing ID sensorbreached = tonumber(fibaro:getValue(motionSensorID, "value")) end return sensorbreached; end function GetAverageLuxValue() local luxAverage = 0; if (CheckIfTable(LuxSensorID, "LuxSensorID") ) then if (#LuxSensorID == 1) then return tonumber(fibaro:getValue(LuxSensorID[1], "value")); end for i = 1,#LuxSensorID do luxAverage = luxAverage + tonumber(fibaro:getValue(LuxSensorID[i], "value")); end luxAverage = roundit( (luxAverage / #LuxSensorID), 0 ); else --if not a table, just return the value of the containing ID luxAverage = tonumber(fibaro:getValue(LuxSensorID, "value")); end return luxAverage; end function UpdateLightValues( currentArray ) for i = 1,#currentArray do item = currentArray[i]; newValue = fibaro:getValue(item.id, "value"); item.currentValue = tonumber(newValue) ~= nil and tonumber(newValue) or ( newValue == "true" and 1 or 0 ); if ( item.lightType == "com.fibaro.RGBW" )then color = fibaro:getValue(item.id, "color"); c = {R="0", G="0", B="0", W="0", brg="0" } c.R, c.G, c.B, c.W = color:match("([^,]+),([^,]+),([^,]+),([^,]+)"); c.brg = fibaro:getValue(item.id, "brightness"); item.currentValue = c; end end end function SetLightValues(currentArray) for i = 1,#currentArray do item = currentArray[i]; item.name = tostring(fibaro:getName(item.id)); item.OffMode = "NoOverride"; if (item.name == nil) then item.name = "Unknown"; end item.lightType = GetDeviceType( item.id ); end end function GetDeviceType(itemId) deviceType = fibaro:getType(item.id); if ( idIsInList(deviceType, RGBWDeviceType) ) then deviceType ="com.fibaro.RGBW"; elseif ( idIsInList(deviceType, BinaryDeviceType) ) then deviceType = "com.fibaro.binarySwitch"; elseif ( idIsInList(deviceType, DimmerDeviceType ) ) then deviceType = "com.fibaro.multilevelSwitch"; --elseif( ) then --deviceType = "Philips.Hue"; end return deviceType; end --------------------Helper functions-------------------------------- function CheckLightToBeTurnedOnAgain(lightItem) if not (lightItem.OffMode=="ByScene") then return; end if (lightItem.lightType == "com.fibaro.multilevelSwitch" ) then if (lightItem.currentValue) < tonumber(lightItem.setValue) then return true; end elseif( lightItem.lightType == "com.fibaro.RGBW" )then c = lightItem.currentValue; if (c.R == "0" and c.G == "0" and c.B == "0" and c.W == "0" ) then return true; end elseif (lightItem.lightType == "com.fibaro.binarySwitch") then if (lightItem.setValue == "turnOn" and lightItem.currentValue == 0 ) then return true; end end return false; end function CheckIfTable( array, arrayname ) local tableCheck = tostring( type( array ) ); if ( tableCheck ~= "table" ) then ErrorDebug("Missing brackets for variable: '" .. arrayname .. "', please place extra brackts: { } around: " .. array .. "."); return false; end return true; end function roundit(num, idp) local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end function idIsInList( startSourceId, sensorList ) for i = 1,#sensorList do if ( startSourceId == sensorList[i] ) then return true; end end return false; end --------------------Debugging Functions----------------------------- function StandardDebug( debugMessage ) if ( showStandardDebugInfo ) then Debug( "white", debugMessage); end end function ExtraDebug( debugMessage ) if ( showExtraDebugInfo ) then Debug( "orange", debugMessage); end end function ErrorDebug( debugMessage ) Debug( "red", "Error: " .. debugMessage); Debug( "red", ""); end function TestDebug(debugMessage ) Debug( "blue", "Testing: " .. debugMessage ); end ----------------------START OF THE SCENE---------------------------- SetCurrentStatus(); StandardDebug("Home status: " .. CurrentState.homeStatus ); StandardDebug("Motion status: " .. ( CurrentState.motionState == 0 and "No movement" or "movement")); if (startSource["type"] == "property") then startSourceID = tonumber(startSource['deviceID']); triggerDebug = "Triggered by: " .. startSourceID; if ( idIsInList( startSourceID, motionSensorID ) ) then StandardDebug( triggerDebug .. " Motion sensor" ); if ( CurrentState.motionState > 0 ) then SceneTriggered(); end elseif ( idIsInList( startSourceID, LuxSensorID ) ) then StandardDebug( triggerDebug .. " Lux sensor" ); ExtraDebug( "Lux value changed to: " .. CurrentState.lux ); if ( CurrentState.motionState > 0 ) then SceneTriggered(); end else StandardDebug( triggerDebug .. " Light switch" ); st = lightsStatus( startSourceID ); if (st == "Unknown") then ErrorDebug( "Unknown light trigger" ); else SceneTriggeredByLights( st ); end -- Maybe we can change the light preset to make it more intelligent. -- Maybe we can change the Lux preset to make it more intelligent. end elseif ( startSource["type"] == "global" ) then StandardDebug( "Triggered by: " .. "global variable" ); -- If home status away, we trigger so the current array will be turned off. If motion, turn them on. if (CurrentState.homeStatus ~= presentStateMapping.Home) then TurnOffLights(); elseif (CurrentState.motionState > 0 ) then SceneTriggered(); end else StandardDebug( "Triggered by: " .. startSource["type"] .. " , Not checking the motion state." ); --Just run the Light Code, not checking for motion. Probably triggered manually. if ( startSource["type"] == "other" ) then SceneTriggered(); end end Debug( "green", "© Smart Lights V" .. version .. " | by Control Living, Finished" ); Debug( "green", "-------------------------------------------------------" ); --fibaro:abort(); --otherwise scene will stay alive to long. --UPDATE TILL HERE si quelqu'un a une idée ? merci
  2. bonjour, voila j'utilise ce script depuis quelques semaines et c'est vrai qu'il est pas mal :-) par contre je ne vois pas comment (et si c'est possible) que la détection se fasse sur X sec et pas a chaque détection en fait pour ma monté d'escalier les lumière s'allume trop souvent j'aimerais dire au script si détection de mouvement et que 2 sec plus tard il y a toujours une détection la lampe s'allume voici mon script : --[[ %% properties 65 value 79 value %% globals TimeOfDay PresentState --]] --[[ Change - XXX value - above. One for motion sensor, one for Light sensor. TimeOfDay global variable and lux make sure that the scene will be triggered when you are already in the room and something changes. Set your settings below, lights and add extra functions Feel free to suggest changes or contact when having problems. It is not allowed to sell or distribute this software and earlier versions without the approval of Control Living © 2014 - 2015 Smart lights by Control Living Version 1.6.7 --]] -------------------------------------------------------------------- -----------------------YOUR LIGHT SETTINGS-------------------------- motionSensorID = {65}; -- change id for your motion sensor. LuxSensorID = {79}; -- change id for your light sensor. actionDevice = 100; -- change id for your light sensor. --Enter the name of your Global variable. WITHOUT IT, THE SCENE DOES NOT WORK. Capital sensitive! sleepState = "SleepState"; --Sleep globalstate variable. timeOfDay = "TimeOfDay"; --Time of Day Global variable. presentState = "PresentState"; --Present state Global variable. --Enter the values of your global variables stated above. If not using, copy the name in front of the "YourValueName" sleepStateMapping = {Sleeping="Sleeping", Awake="Awake"}; timeOfDayMapping = {Morning="Morning", Day="Day", Evening="Evening", Night="Night"}; presentStateMapping = {Home="Home", Away="Away", Holiday="Holiday"}; -- Set the lux value for which the lights have to be turned on. -- If you don't want to use the MinLux then just set it to: 65535 minLuxMorning = 2500; minLuxDay = 2500; minLuxEvening = 2500; minLuxNight = 2500; --If the current lux value is above the maxlux, the lights will turn off after their set onTime. maxLuxMorning = 6000; maxLuxDay = 6000; --[[ Now the most important part: Here you can enter what light, for how long and at what value has to be turned on. Leave empty brackets for no lights. To set the light value without timer use 2 parameters: {id=LightID, setValue="VALUE"} To set the light value with timer use 3 parameters: {id=LightID, setValue="VALUE", onTime=timeInSeconds } To set the light value for RGBW: use the above, where setValue is: setValue={R="255",G="255",B="255",W="255"} -- RGBW set: {id=LightID, setValue={R="255",G="255",B="255",W="255"}, onTime=timeInSeconds } --]] lightsSleeping = {}; --lights that are triggered when Sleepstate is sleeping. lightsMorning = {{id=actionDevice, setValue="turnOn", onTime=20}}; lightsDay = {{id=actionDevice, setValue="turnOn", onTime=20}}; lightsEvening = {{id=actionDevice, setValue="turnOn", onTime=20}}; lightsNight = {{id=actionDevice, setValue="turnOn", onTime=20}}; --Manual Override, the time that lights will not be turned ON again after manually turning them off. OverrideFor = 90; dimmDownTime = 10; -------------------------------------------------------------------- -------------------------EXTRA FEATURES----------------------------- extraMorningFunc = function() -- Add your extra code here. If you want some checks or maybe run a virtual device button. --This code is always triggered if there is motion. -- movieLights = {{180, "10"},{181, "10"} }; --if (xbmc == "playing" ) then CallLightArray(movieLights); ExtraDebug("Extra morning function called"); end extraDayFunc = function() -- Add your extra code here. If you want some checks or maybe run a virtual device button. --This code is always triggered if there is motion. ExtraDebug("Extra day function called"); end extraEveningFunc = function() -- Add your extra code here. If you want some checks or maybe run a virtual device button. --This code is always triggered if there is motion. ExtraDebug("Extra evening function called"); end extraNightFunc = function() -- Add your extra code here. If you want some checks or maybe run a virtual device button. --This code is always triggered if there is motion. ExtraDebug("Extra night function called"); end extraLightTriggerChecks = function() --add extra checks here. and return the total true or false value. --if returning false the lights will not be triggered. -- for instance: return ( (pcTurnedOff == true ) and (xbmc ~= "Empty") ); -- return true to enable lights to turn on return true; end extraOffChecks = function() --return true to keep lights on. return false; end -------------------------------------------------------------------- ----------------------ADVANCES SETTINGS----------------------------- local showStandardDebugInfo = true; -- Debug shown in white local showExtraDebugInfo = false; -- Debug shown in orange -------------------------------------------------------------------- -------------------------------------------------------------------- -- DO NOT CHANGE THE CODE BELOW -- -------------------------------------------------------------------- --UPDATE FROM HERE --private variables startSource = fibaro:getSourceTrigger(); keepLightsOn = false; timerRunning = false; previousLights = nil; version = "1.6.7"; SavedState = { homeStatus = "", sleepState = 0, timeOfDay = "", lux = 0, motion = 0, startTime = 0 } CurrentState = { homeStatus = "", sleepState = "", timeOfDay = "", lux = 0, motionState = 0, currentLightArray = {} } RGBWDeviceType = { "com.fibaro.RGBW", "com.fibaro.colorController", "com.fibaro.FGRGBW441M" } BinaryDeviceType = { "com.fibaro.binarySwitch","com.fibaro.FGWP101", "com.fibaro.developer.angelz.SwitchLumiereFhem", "turnOn" } DimmerDeviceType = { "com.fibaro.multilevelSwitch" } OffModes = {None, ByScene, ManualOverride } function Debug( color, message ) fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span")); end --Making sure that only one instance of the scene is running. fibaro:sleep(50); --sleep to prevent all instances being killed. if (fibaro:countScenes() > 1) then if (showExtraDebugInfo) then Debug( "grey", "Abort, Scene count = " .. fibaro:countScenes()); end fibaro:abort(); end --------------------------EXECUTION---------------------------------- function SetCurrentStatus() ExtraDebug("Updating current variable statuses"); CurrentState.homeStatus = GetPresentState(); CurrentState.timeOfDay = GetTimeOfDay(); CurrentState.sleepState = GetSleepState(); CurrentState.lux = GetAverageLuxValue(); CurrentState.motionState = GetCurrentMotionStatus(); end function SaveCurrentStatus() ExtraDebug("Saving current variable statuses"); SavedState.homeStatus = CurrentState.homeStatus; SavedState.timeOfDay = CurrentState.timeOfDay; SavedState.sleepState = CurrentState.sleepState; SavedState.lux = CurrentState.lux; SavedState.motion = CurrentState.motionState; end function CheckStatusChanges() ExtraDebug("Status change check"); if (CurrentState.homeStatus ~= SavedState.homeStatus ) or (CurrentState.timeOfDay ~= SavedState.timeOfDay ) then if (CurrentState.homeStatus ~= presentStateMapping.Home ) then TurnOffLights(); else SceneTriggered(); --reset time. end; end SaveCurrentStatus(); -- if we still have a motion then reset timer. if ( (CurrentState.motionState ~= 0 or extraOffChecks() ) and not IsMaxLuxExceeded() ) then ExtraDebug( "Resetting time" ); SavedState.startTime = os.time(); else ExtraDebug("Timer is not reset."); end --any other case, we are not resetting the timer. end function IsMaxLuxExceeded() if (CurrentState.timeOfDay == timeOfDayMapping.Morning and CurrentState.lux > maxLuxMorning ) then ExtraDebug( "Current lux value: " .. CurrentState.lux .. " higher then max Lux Morning: " .. maxLuxMorning .. "."); return true; elseif (CurrentState.timeOfDay == timeOfDayMapping.Day and CurrentState.lux > maxLuxDay ) then ExtraDebug( "Current lux value: " .. CurrentState.lux .. " higher then max Lux Day: " .. maxLuxDay .. "."); return true; end return false; end function LightsOff( lightArray ) local stillLightsOn = 0; local currentTime = os.time(); for i = 1,#lightArray do if ( lightArray[i].onTime ~= nil) then lightItem = lightArray[i]; lightItem.OffMode = CheckManualOverrideItem( lightItem ); --local if ( lightItem.OffMode == "ManualOverride" ) then ExtraDebug("Manual override for light: [" .. lightItem.id .. "]" .. lightItem.name .. " active, not turning on"); goto continue; end --On till: local timeL = SavedState.startTime + (lightItem.onTime); local timeLeft = timeL - currentTime; if (timeLeft >= 0 ) then ExtraDebug("Time left for: [" .. lightItem.id .. "]" .. lightItem.name .. ": " .. timeLeft .. " seconds" ); end if ( timeLeft < dimmDownTime ) then if ( lightItem.OffMode ~= "ManualOverride" ) then lightItem.OffMode = "ByScene"; end if ( (timeLeft <= 0) and (lightItem.currentValue ~= 0) ) then fibaro:call(lightItem.id, "turnOff"); StandardDebug("Switch off light: [" .. lightItem.id .. "]'" .. lightItem.name .."'"); else if ( item.lightType == "com.fibaro.multilevelSwitch" ) then currentValueDiv = roundit(((lightItem.currentValue) / (dimmDownTime)), 0); currentValueNew = (lightItem.currentValue - currentValueDiv); if (currentValueNew <=0 ) then currentValueNew = 0; end fibaro:call(lightItem.id, "setValue", tostring(currentValueNew)); end stillLightsOn = stillLightsOn + 1; end elseif (CheckLightToBeTurnedOnAgain(lightItem)) then ExtraDebug("Turn light: " .. lightItem.id .. " back on"); turnLightOn(lightItem); lightItem.OffMode = ""; stillLightsOn = stillLightsOn + 1; else lightItem.OffMode = "NoOverride"; stillLightsOn = stillLightsOn + 1; end end ::continue:: end return stillLightsOn; end function KeepLightsOnTimer() ExtraDebug("--------------- Timer running ---------------"); ExtraDebug("starting with while loop, to keep lights on"); SavedState.startTime = os.time(); SaveCurrentStatus(); sleepTime = 1000; while ( keepLightsOn ) do ExtraDebug("--------------- next timer run ---------------"); fibaro:sleep(sleepTime); start_time = os.clock(); SetCurrentStatus(); currentLightArray = GetTimeOfDayLightArray(); UpdateLightValues(currentLightArray); CheckStatusChanges(); local stillLightsOn = 0; stillLightsOn = LightsOff( currentLightArray ); if (stillLightsOn == 0 ) then keepLightsOn = RunManualOverrideMode( currentLightArray ); end_time = 0; --if lights turned back on after override. else end_time = os.clock() end elapsed_time = (end_time - start_time) * 1000; sleepTime = 1000 - elapsed_time; end end function CheckManualOverrideItem( currentItem ) --ExtraDebug("Manual override check for: [" .. currentItem.id .. "]" .. currentItem.name); --fibaro:debug(currentItem.currentValue) --fibaro:debug(currentItem.OffMode) if (currentItem.currentValue == 0 and currentItem.OffMode ~= "ByScene" ) then ExtraDebug( "Manual override for light: [" .. currentItem.id .. "]" .. currentItem.name .. " active" ); return "ManualOverride"; elseif (currentItem.currentValue ~= 0 and currentItem.OffMode == "ManualOverride" ) then ExtraDebug( "Manual override for light: [" .. currentItem.id .. "]" .. currentItem.name .. " cancelled" ); return "NoOverride"; end return currentItem.OffMode; --returning current mode; end function RunManualOverrideMode( currentLightArray ) OverrideForAll = CheckIfAllInOverrideMode(currentLightArray); if ( OverrideForAll ) then ExtraDebug("-----------------Override Mode---------------"); OverrideTimer = os.time(); while ( OverrideForAll and (OverrideTimer + OverrideFor ) - os.time() > 0 ) do ExtraDebug("Still in override for: " .. (OverrideTimer + OverrideFor ) - os.time() .. " seconds" ); fibaro:sleep(1000); UpdateLightValues(currentLightArray); OverrideForAll = CheckIfAllInOverrideMode(currentLightArray); motion = GetCurrentMotionStatus(); if ( motion ~= 0 ) then OverrideTimer = os.time(); end end else return false; end -- if ( (OverrideTimer + OverrideFor ) - os.time() <= 0 ) then --time has end. So not continue to run lights loop -- return false; -- end if (OverrideForAll) then return false; --run lights else return true; end end function CheckIfAllInOverrideMode(currentLightArray) OverrideForAll = 0; for i = 1,#currentLightArray do if ( CheckManualOverrideItem(currentLightArray[i]) == "ManualOverride" ) then OverrideForAll = OverrideForAll +1; else return false; end end if ( OverrideForAll ~= 0 and OverrideForAll == #currentLightArray ) then return true; end return false; end function RunTimer() if ( keepLightsOn and not timerRunning ) then ExtraDebug("Starting timer, not yet running"); timerRunning = true; KeepLightsOnTimer(); else ExtraDebug("Timer already running, returning"); end end function TurnOffLights() local timeOfDayArray = GetTimeOfDayLightArray(); SetLightValues(timeOfDayArray); UpdateLightValues(timeOfDayArray); CallLightArray(timeOfDayArray, "off" ); return; end ----------------------Turn lights on functions------------------------ function CallLightArray( lightArray, turnOnOrOff ) if (#lightArray == 0 ) then if (CurrentState.sleepState == sleepStateMapping.Sleeping) then noLightsSetText = "lightsSleeping"; else noLightsSetText = CurrentState.timeOfDay; end StandardDebug( "No lights set for " .. noLightsSetText ); return; end if not ( CheckIfTable(lightArray, "lights" .. CurrentState.timeOfDay ) ) then return end for i = 1,#lightArray do if not ( CheckIfTable(lightArray[i], "lights" .. CurrentState.timeOfDay ) ) then break end lightItem = lightArray[i]; if (turnOnOrOff == "on" ) then turnLightOn(lightItem); if (lightItem.onTime ~= nil) then keepLightsOn = true; end else fibaro:call(lightItem.id, "turnOff"); --Always turn off, if HC2 light status is not actual. if ( lightItem.currentValue ~= 0) then keepLightsOn = false; StandardDebug("Switch off light: [" .. lightItem.id .. "]'" .. lightItem.name .."'"); end end end StandardDebug( "Lights turned: " .. turnOnOrOff .. " for " .. CurrentState.timeOfDay ); end function turnLightOn( lightItem ) if (lightItem.lightType == "com.fibaro.multilevelSwitch" ) then fibaro:call(lightItem.id, "setValue", tostring(lightItem.setValue)); StandardDebug( "Set: [" .. lightItem.id .. "]'" .. lightItem.name .. "' to Value: " .. lightItem.setValue ); elseif ( lightItem.lightType == "com.fibaro.RGBW" )then StandardDebug( "Turn: [" .. lightItem.id .. "]'" .. lightItem.name .. "' On"); if ( lightItem.setValue.brg~= nil ) then fibaro:call(lightItem.id, "setBrightness", tostring(lightItem.setValue.brg)); else local clrvalues =lightItem.setValue; fibaro:call(lightItem.id, "setColor", clrvalues.R, clrvalues.G, clrvalues.B, clrvalues.W) end elseif (lightItem.lightType == "com.fibaro.binarySwitch") then fibaro:call(lightItem.id, "turnOn"); StandardDebug( "Turn: [" .. lightItem.id .. "]'" .. lightItem.name .. "' On"); end end function CheckPreviousLights( NewLightArray ) if ( previousLights ~= nil ) then for i = 1,#previousLights do local lightItem = previousLights[i]; for i = 1,#NewLightArray do local lightItem1 = NewLightArray[i]; inarray = false; if ( lightItem.id == lightItem1.id ) then inarray= true; break end end if not ( inarray ) then fibaro:call(lightItem.id, "turnOff"); end end end previousLights = NewLightArray; end function LightperDayPart( minLux, lightArray ) local newLuxValue = CurrentState.lux; if ( extraLightTriggerChecks() ) then if ( newLuxValue > minLux ) then StandardDebug( "Sensor lux: " .. newLuxValue .. " higher then minValue: " .. minLux .. " : no action"); else StandardDebug("Sensor lux: " .. newLuxValue .. " is lower then minValue: " .. minLux); SetLightValues(lightArray); CallLightArray( lightArray, "on" ); CheckPreviousLights( lightArray ); end else ExtraDebug("ExtraLightTriggerChecks failed, so no lights"); end end function SceneTriggered() if ( CurrentState.homeStatus ~= presentStateMapping.Home ) then ExtraDebug("Presentstate = not at home, so no lights"); elseif ( CurrentState.sleepState == sleepStateMapping.Sleeping ) then LightperDayPart( 65535, lightsSleeping ); elseif ( CurrentState.timeOfDay == timeOfDayMapping.Morning ) then extraMorningFunc(); LightperDayPart( minLuxMorning, lightsMorning ); elseif ( CurrentState.timeOfDay == timeOfDayMapping.Day ) then extraDayFunc(); LightperDayPart( minLuxDay, lightsDay ); elseif ( CurrentState.timeOfDay == timeOfDayMapping.Evening ) then extraEveningFunc(); LightperDayPart( minLuxEvening, lightsEvening ); elseif ( CurrentState.timeOfDay == timeOfDayMapping.Night ) then extraNightFunc(); LightperDayPart( minLuxNight, lightsNight ); else ErrorDebug( "No lights: " .. CurrentState.timeOfDay ); end if (keepLightsOn == true) then RunTimer(); end end function SceneTriggeredByLights( st ) if (st == "off") then ExtraDebug( "light turned off, sleep 4 sec" ); fibaro:sleep(4000); elseif (st == "on") then ExtraDebug( "light turned on, activating timer" ); fibaro:sleep(4000); --TODO: add light to current array. --keepLightsOn = true; --RunTimer(); end end ------------------------STATUS functions------------------------------ function GetTimeOfDay() return LookupGlobal( timeOfDay, "TimeOfDay", "Day"); end function GetSleepState() return LookupGlobal( sleepState, "sleepState", "Awake"); end function GetPresentState() return LookupGlobal( presentState, "presentState", "Home"); end function LookupGlobal( name, stateName, default ) local ps = fibaro:getGlobalValue( name ); if ( (ps ~= "") and (ps ~= nil ) ) then ExtraDebug("returned " .. stateName .. ": " .. ps ); return ps; else ErrorDebug( stateName .. " variable not found"); return default; end end function lightsStatus( id ) --check if lights are already on. allLights = {lightsSleeping, lightsMorning, lightsDay, lightsEvening, lightsNight }; for i = 1,#allLights do for iL = 1, #allLights[i] do local lightItem = allLights[i][iL]; if ( lightItem.id == tonumber(id) ) then if ( lightItem.currentValue == 0 ) then return "off"; else return "on"; end end end end ErrorDebug("Light status unknown"); return "Unknown"; end function GetTimeOfDayLightArray() if ( CurrentState.sleepState == sleepStateMapping.Sleeping ) then return lightsSleeping; elseif ( CurrentState.timeOfDay == timeOfDayMapping.Morning ) then return lightsMorning; elseif ( CurrentState.timeOfDay == timeOfDayMapping.Day ) then return lightsDay; elseif ( CurrentState.timeOfDay == timeOfDayMapping.Evening ) then return lightsEvening; elseif ( CurrentState.timeOfDay == timeOfDayMapping.Night ) then return lightsNight; end end function GetCurrentMotionStatus() local sensorbreached = 0; if (CheckIfTable(motionSensorID, "motionSensorID") ) then for i = 1,#motionSensorID do if ( tonumber(fibaro:getValue(motionSensorID[i], "value")) > 0 ) then sensorbreached = 1; end end else --if not a table, just return the value of the containing ID sensorbreached = tonumber(fibaro:getValue(motionSensorID, "value")) end return sensorbreached; end function GetAverageLuxValue() local luxAverage = 0; if (CheckIfTable(LuxSensorID, "LuxSensorID") ) then if (#LuxSensorID == 1) then return tonumber(fibaro:getValue(LuxSensorID[1], "value")); end for i = 1,#LuxSensorID do luxAverage = luxAverage + tonumber(fibaro:getValue(LuxSensorID[i], "value")); end luxAverage = roundit( (luxAverage / #LuxSensorID), 0 ); else --if not a table, just return the value of the containing ID luxAverage = tonumber(fibaro:getValue(LuxSensorID, "value")); end return luxAverage; end function UpdateLightValues( currentArray ) for i = 1,#currentArray do item = currentArray[i]; newValue = fibaro:getValue(item.id, "value"); item.currentValue = tonumber(newValue) ~= nil and tonumber(newValue) or ( newValue == "true" and 1 or 0 ); if ( item.lightType == "com.fibaro.RGBW" )then color = fibaro:getValue(item.id, "color"); c = {R="0", G="0", B="0", W="0", brg="0" } c.R, c.G, c.B, c.W = color:match("([^,]+),([^,]+),([^,]+),([^,]+)"); c.brg = fibaro:getValue(item.id, "brightness"); item.currentValue = c; end end end function SetLightValues(currentArray) for i = 1,#currentArray do item = currentArray[i]; item.name = tostring(fibaro:getName(item.id)); item.OffMode = "NoOverride"; if (item.name == nil) then item.name = "Unknown"; end item.lightType = GetDeviceType( item.id ); end end function GetDeviceType(itemId) deviceType = fibaro:getType(item.id); if ( idIsInList(deviceType, RGBWDeviceType) ) then deviceType ="com.fibaro.RGBW"; elseif ( idIsInList(deviceType, BinaryDeviceType) ) then deviceType = "com.fibaro.binarySwitch"; elseif ( idIsInList(deviceType, DimmerDeviceType ) ) then deviceType = "com.fibaro.multilevelSwitch"; --elseif( ) then --deviceType = "Philips.Hue"; end return deviceType; end --------------------Helper functions-------------------------------- function CheckLightToBeTurnedOnAgain(lightItem) if not (lightItem.OffMode=="ByScene") then return; end if (lightItem.lightType == "com.fibaro.multilevelSwitch" ) then if (lightItem.currentValue) < tonumber(lightItem.setValue) then return true; end elseif( lightItem.lightType == "com.fibaro.RGBW" )then c = lightItem.currentValue; if (c.R == "0" and c.G == "0" and c.B == "0" and c.W == "0" ) then return true; end elseif (lightItem.lightType == "com.fibaro.binarySwitch") then if (lightItem.setValue == "turnOn" and lightItem.currentValue == 0 ) then return true; end end return false; end function CheckIfTable( array, arrayname ) local tableCheck = tostring( type( array ) ); if ( tableCheck ~= "table" ) then ErrorDebug("Missing brackets for variable: '" .. arrayname .. "', please place extra brackts: { } around: " .. array .. "."); return false; end return true; end function roundit(num, idp) local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end function idIsInList( startSourceId, sensorList ) for i = 1,#sensorList do if ( startSourceId == sensorList[i] ) then return true; end end return false; end --------------------Debugging Functions----------------------------- function StandardDebug( debugMessage ) if ( showStandardDebugInfo ) then Debug( "white", debugMessage); end end function ExtraDebug( debugMessage ) if ( showExtraDebugInfo ) then Debug( "orange", debugMessage); end end function ErrorDebug( debugMessage ) Debug( "red", "Error: " .. debugMessage); Debug( "red", ""); end function TestDebug(debugMessage ) Debug( "blue", "Testing: " .. debugMessage ); end ----------------------START OF THE SCENE---------------------------- SetCurrentStatus(); StandardDebug("Home status: " .. CurrentState.homeStatus ); StandardDebug("Motion status: " .. ( CurrentState.motionState == 0 and "No movement" or "movement")); if (startSource["type"] == "property") then startSourceID = tonumber(startSource['deviceID']); triggerDebug = "Triggered by: " .. startSourceID; if ( idIsInList( startSourceID, motionSensorID ) ) then StandardDebug( triggerDebug .. " Motion sensor" ); if ( CurrentState.motionState > 0 ) then SceneTriggered(); end elseif ( idIsInList( startSourceID, LuxSensorID ) ) then StandardDebug( triggerDebug .. " Lux sensor" ); ExtraDebug( "Lux value changed to: " .. CurrentState.lux ); if ( CurrentState.motionState > 0 ) then SceneTriggered(); end else StandardDebug( triggerDebug .. " Light switch" ); st = lightsStatus( startSourceID ); if (st == "Unknown") then ErrorDebug( "Unknown light trigger" ); else SceneTriggeredByLights( st ); end -- Maybe we can change the light preset to make it more intelligent. -- Maybe we can change the Lux preset to make it more intelligent. end elseif ( startSource["type"] == "global" ) then StandardDebug( "Triggered by: " .. "global variable" ); -- If home status away, we trigger so the current array will be turned off. If motion, turn them on. if (CurrentState.homeStatus ~= presentStateMapping.Home) then TurnOffLights(); elseif (CurrentState.motionState > 0 ) then SceneTriggered(); end else StandardDebug( "Triggered by: " .. startSource["type"] .. " , Not checking the motion state." ); --Just run the Light Code, not checking for motion. Probably triggered manually. if ( startSource["type"] == "other" ) then SceneTriggered(); end end Debug( "green", "© Smart Lights V" .. version .. " | by Control Living, Finished" ); Debug( "green", "-------------------------------------------------------" ); --fibaro:abort(); --otherwise scene will stay alive to long. --UPDATE TILL HERE si quelqu'un a une idée ? merci de votre aide
  3. bonjour, merci pour la piste :-) en fait effectivement j'utilise un plugin perso pour gérer des switch knx via fhem et donc, pour que ça marche il faut rajouter dans la ligne 154 BinaryDeviceType = { "com.fibaro.binarySwitch","com.fibaro.FGWP101", "turnOn" } le type du plugin, pour moi ça donne ceci BinaryDeviceType = { "com.fibaro.binarySwitch","com.fibaro.FGWP101", "com.fibaro.developer.angelz.SwitchLumiereFhem", "turnOn" } et hop ça marche :-) maintenant que ca s'est réglé :-) est-il possible de faire en sorte que la détection se fasse sur 2 sec au lieu de faire ça a chaque détection ? merci de l'aide :-)
  4. voici la fin d'une "séquence" et le début d'une autre: [DEBUG] 19:49:52: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:49:52: Still in override for: 19 seconds [DEBUG] 19:49:53: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:49:53: Still in override for: 18 seconds [DEBUG] 19:49:54: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:49:54: Still in override for: 17 seconds [DEBUG] 19:49:55: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:49:55: Still in override for: 16 seconds [DEBUG] 19:49:56: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:49:56: Still in override for: 15 seconds [DEBUG] 19:49:57: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:49:57: Still in override for: 14 seconds [DEBUG] 19:49:58: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:49:58: Still in override for: 13 seconds [DEBUG] 19:49:59: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:49:59: Still in override for: 12 seconds [DEBUG] 19:50:00: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:50:00: Still in override for: 11 seconds [DEBUG] 19:50:01: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:50:01: Still in override for: 10 seconds [DEBUG] 19:50:02: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:50:02: Still in override for: 9 seconds [DEBUG] 19:50:03: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:50:03: Still in override for: 8 seconds [DEBUG] 19:50:04: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:50:04: Still in override for: 7 seconds [DEBUG] 19:50:05: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:50:05: Still in override for: 6 seconds [DEBUG] 19:50:06: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:50:06: Still in override for: 5 seconds [DEBUG] 19:50:07: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:50:07: Still in override for: 4 seconds [DEBUG] 19:50:08: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:50:08: Still in override for: 3 seconds [DEBUG] 19:50:09: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:50:09: Still in override for: 2 seconds [DEBUG] 19:50:10: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:50:10: Still in override for: 1 seconds [DEBUG] 19:50:11: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:50:11: © Smart Lights V1.6.7 | by Control Living, Finished [DEBUG] 19:50:11: ------------------------------------------------------- [DEBUG] 19:56:23: Updating current variable statuses [DEBUG] 19:56:23: returned presentState: Home [DEBUG] 19:56:23: returned TimeOfDay: Day [DEBUG] 19:56:23: returned sleepState: Awake [DEBUG] 19:56:23: Home status: Home [DEBUG] 19:56:23: Motion status: movement [DEBUG] 19:56:23: Triggered by: 42 Motion sensor [DEBUG] 19:56:23: Extra day function called [DEBUG] 19:56:23: Sensor lux: 500 is lower then minValue: 2500 [DEBUG] 19:56:23: Lights turned: on for Day [DEBUG] 19:56:23: Starting timer, not yet running [DEBUG] 19:56:23: --------------- Timer running --------------- [DEBUG] 19:56:23: starting with while loop, to keep lights on [DEBUG] 19:56:23: Saving current variable statuses [DEBUG] 19:56:23: --------------- next timer run --------------- [DEBUG] 19:56:24: Updating current variable statuses [DEBUG] 19:56:24: returned presentState: Home [DEBUG] 19:56:24: returned TimeOfDay: Day [DEBUG] 19:56:24: returned sleepState: Awake [DEBUG] 19:56:24: Status change check [DEBUG] 19:56:24: Saving current variable statuses [DEBUG] 19:56:24: Resetting time [DEBUG] 19:56:24: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:56:24: Manual override for light: [73]Spot Hall Entrée active, not turning on [DEBUG] 19:56:24: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:56:24: -----------------Override Mode--------------- [DEBUG] 19:56:24: Still in override for: 90 seconds [DEBUG] 19:56:25: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:56:25: Still in override for: 90 seconds [DEBUG] 19:56:26: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:56:26: Still in override for: 90 seconds [DEBUG] 19:56:27: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:56:27: Still in override for: 90 seconds [DEBUG] 19:56:28: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:56:28: Still in override for: 90 seconds [DEBUG] 19:56:29: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:56:29: Still in override for: 90 seconds [DEBUG] 19:56:30: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:56:30: Still in override for: 90 seconds [DEBUG] 19:56:31: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:56:31: Still in override for: 90 seconds [DEBUG] 19:56:32: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:56:32: Still in override for: 90 seconds [DEBUG] 19:56:33: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:56:33: Still in override for: 90 seconds [DEBUG] 19:56:34: Abort, Scene count = 2 [DEBUG] 19:56:34: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:56:34: Still in override for: 89 seconds [DEBUG] 19:56:35: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:56:35: Still in override for: 88 seconds [DEBUG] 19:56:36: Abort, Scene count = 2 [DEBUG] 19:56:36: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 19:56:36: Still in override for: 90 seconds
  5. voila la variable sleepState enlever pour les Maj/min j'ai vérifier tout est correct voici le log [DEBUG] 00:17:49: Updating current variable statuses [DEBUG] 00:17:49: returned presentState: Home [DEBUG] 00:17:49: returned TimeOfDay: Day [DEBUG] 00:17:49: returned sleepState: Awake [DEBUG] 00:17:49: Home status: Home [DEBUG] 00:17:49: Motion status: movement [DEBUG] 00:17:49: Triggered by: 42 Motion sensor [DEBUG] 00:17:49: Extra day function called [DEBUG] 00:17:49: Sensor lux: 0 is lower then minValue: 2500 [DEBUG] 00:17:49: Lights turned: on for Day [DEBUG] 00:17:49: Starting timer, not yet running [DEBUG] 00:17:49: --------------- Timer running --------------- [DEBUG] 00:17:49: starting with while loop, to keep lights on [DEBUG] 00:17:49: Saving current variable statuses [DEBUG] 00:17:49: --------------- next timer run --------------- [DEBUG] 00:17:50: Updating current variable statuses [DEBUG] 00:17:50: returned presentState: Home [DEBUG] 00:17:50: returned TimeOfDay: Day [DEBUG] 00:17:50: returned sleepState: Awake [DEBUG] 00:17:50: Status change check [DEBUG] 00:17:50: Saving current variable statuses [DEBUG] 00:17:50: Resetting time [DEBUG] 00:17:50: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:17:50: Manual override for light: [73]Spot Hall Entrée active, not turning on [DEBUG] 00:17:50: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:17:50: -----------------Override Mode--------------- [DEBUG] 00:17:50: Still in override for: 90 seconds [DEBUG] 00:17:51: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:17:51: Still in override for: 90 seconds [DEBUG] 00:17:52: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:17:52: Still in override for: 90 seconds [DEBUG] 00:17:53: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:17:53: Still in override for: 90 seconds [DEBUG] 00:17:54: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:17:54: Still in override for: 90 seconds [DEBUG] 00:17:55: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:17:55: Still in override for: 90 seconds [DEBUG] 00:17:56: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:17:56: Still in override for: 90 seconds [DEBUG] 00:17:57: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:17:57: Still in override for: 90 seconds [DEBUG] 00:17:58: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:17:58: Still in override for: 90 seconds [DEBUG] 00:17:59: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:17:59: Still in override for: 90 seconds [DEBUG] 00:18:00: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:00: Still in override for: 90 seconds [DEBUG] 00:18:01: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:01: Still in override for: 89 seconds [DEBUG] 00:18:01: Abort, Scene count = 2 [DEBUG] 00:18:02: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:02: Still in override for: 88 seconds [DEBUG] 00:18:03: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:03: Still in override for: 87 seconds [DEBUG] 00:18:04: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:04: Still in override for: 86 seconds [DEBUG] 00:18:05: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:05: Still in override for: 85 seconds [DEBUG] 00:18:06: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:06: Still in override for: 84 seconds [DEBUG] 00:18:07: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:07: Still in override for: 83 seconds [DEBUG] 00:18:08: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:08: Still in override for: 82 seconds [DEBUG] 00:18:09: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:09: Still in override for: 81 seconds [DEBUG] 00:18:10: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:10: Still in override for: 80 seconds [DEBUG] 00:18:11: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:11: Still in override for: 79 seconds [DEBUG] 00:18:12: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:12: Still in override for: 78 seconds [DEBUG] 00:18:13: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:13: Still in override for: 77 seconds [DEBUG] 00:18:14: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:14: Still in override for: 76 seconds [DEBUG] 00:18:15: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:15: Still in override for: 75 seconds [DEBUG] 00:18:16: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:16: Still in override for: 74 seconds [DEBUG] 00:18:17: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:17: Still in override for: 73 seconds [DEBUG] 00:18:18: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:18: Still in override for: 72 seconds [DEBUG] 00:18:19: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:19: Still in override for: 71 seconds [DEBUG] 00:18:20: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:20: Still in override for: 70 seconds [DEBUG] 00:18:21: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:21: Still in override for: 69 seconds [DEBUG] 00:18:22: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:22: Still in override for: 68 seconds [DEBUG] 00:18:23: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:23: Still in override for: 67 seconds [DEBUG] 00:18:24: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:24: Still in override for: 66 seconds [DEBUG] 00:18:25: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:25: Still in override for: 65 seconds [DEBUG] 00:18:26: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:26: Still in override for: 64 seconds [DEBUG] 00:18:27: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:27: Still in override for: 63 seconds [DEBUG] 00:18:28: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:28: Still in override for: 62 seconds [DEBUG] 00:18:29: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:29: Still in override for: 61 seconds [DEBUG] 00:18:30: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:30: Still in override for: 60 seconds [DEBUG] 00:18:31: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:31: Still in override for: 59 seconds [DEBUG] 00:18:32: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:32: Still in override for: 58 seconds [DEBUG] 00:18:33: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:33: Still in override for: 57 seconds [DEBUG] 00:18:34: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:34: Still in override for: 56 seconds [DEBUG] 00:18:35: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:35: Still in override for: 55 seconds [DEBUG] 00:18:36: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:36: Still in override for: 54 seconds [DEBUG] 00:18:37: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:37: Still in override for: 53 seconds [DEBUG] 00:18:38: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:38: Still in override for: 52 seconds [DEBUG] 00:18:39: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:39: Still in override for: 51 seconds [DEBUG] 00:18:40: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:40: Still in override for: 50 seconds [DEBUG] 00:18:41: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:41: Still in override for: 49 seconds [DEBUG] 00:18:42: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:42: Still in override for: 48 seconds [DEBUG] 00:18:43: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:43: Still in override for: 47 seconds [DEBUG] 00:18:44: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:44: Still in override for: 46 seconds [DEBUG] 00:18:45: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:45: Still in override for: 45 seconds [DEBUG] 00:18:46: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:46: Still in override for: 44 seconds [DEBUG] 00:18:47: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:47: Still in override for: 43 seconds [DEBUG] 00:18:48: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:48: Still in override for: 42 seconds [DEBUG] 00:18:49: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:49: Still in override for: 41 seconds [DEBUG] 00:18:50: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:50: Still in override for: 40 seconds [DEBUG] 00:18:51: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:51: Still in override for: 39 seconds [DEBUG] 00:18:52: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:52: Still in override for: 38 seconds [DEBUG] 00:18:53: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:53: Still in override for: 37 seconds [DEBUG] 00:18:54: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:54: Still in override for: 36 seconds [DEBUG] 00:18:55: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:55: Still in override for: 35 seconds [DEBUG] 00:18:56: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:56: Still in override for: 34 seconds [DEBUG] 00:18:57: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:57: Still in override for: 33 seconds [DEBUG] 00:18:58: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:58: Still in override for: 32 seconds [DEBUG] 00:18:59: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:18:59: Still in override for: 31 seconds [DEBUG] 00:19:00: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:00: Still in override for: 30 seconds [DEBUG] 00:19:01: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:01: Still in override for: 29 seconds [DEBUG] 00:19:02: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:02: Still in override for: 28 seconds [DEBUG] 00:19:03: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:03: Still in override for: 27 seconds [DEBUG] 00:19:04: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:04: Still in override for: 26 seconds [DEBUG] 00:19:05: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:05: Still in override for: 25 seconds [DEBUG] 00:19:06: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:06: Still in override for: 24 seconds [DEBUG] 00:19:07: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:07: Still in override for: 23 seconds [DEBUG] 00:19:08: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:08: Still in override for: 22 seconds [DEBUG] 00:19:09: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:09: Still in override for: 21 seconds [DEBUG] 00:19:10: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:10: Still in override for: 20 seconds [DEBUG] 00:19:11: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:11: Still in override for: 19 seconds [DEBUG] 00:19:12: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:12: Still in override for: 18 seconds [DEBUG] 00:19:13: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:13: Still in override for: 17 seconds [DEBUG] 00:19:14: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:14: Still in override for: 16 seconds [DEBUG] 00:19:15: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:15: Still in override for: 15 seconds [DEBUG] 00:19:16: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:16: Still in override for: 14 seconds [DEBUG] 00:19:17: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:17: Still in override for: 13 seconds [DEBUG] 00:19:18: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:18: Still in override for: 12 seconds [DEBUG] 00:19:19: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:19: Still in override for: 11 seconds [DEBUG] 00:19:20: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:20: Still in override for: 10 seconds [DEBUG] 00:19:21: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:21: Still in override for: 9 seconds [DEBUG] 00:19:22: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:22: Still in override for: 8 seconds [DEBUG] 00:19:23: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:23: Still in override for: 7 seconds [DEBUG] 00:19:24: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:24: Still in override for: 6 seconds [DEBUG] 00:19:25: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:25: Still in override for: 5 seconds [DEBUG] 00:19:26: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:26: Still in override for: 4 seconds [DEBUG] 00:19:27: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:27: Still in override for: 3 seconds [DEBUG] 00:19:28: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:28: Still in override for: 2 seconds [DEBUG] 00:19:29: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:29: Still in override for: 1 seconds [DEBUG] 00:19:30: Manual override for light: [73]Spot Hall Entrée active [DEBUG] 00:19:30: © Smart Lights V1.6.7 | by Control Living, Finished [DEBUG] 00:19:30: -------------------------------------------------------
  6. j'ai enlever la ligne vide mais toujours pas voici le script total :-) --[[ %% properties 42 value 53 value %% globals TimeOfDay PresentState sleepState --]] --[[ Change - XXX value - above. One for motion sensor, one for Light sensor. TimeOfDay global variable and lux make sure that the scene will be triggered when you are already in the room and something changes. Set your settings below, lights and add extra functions Feel free to suggest changes or contact when having problems. It is not allowed to sell or distribute this software and earlier versions without the approval of Control Living © 2014 - 2015 Smart lights by Control Living Version 1.6.7 --]] -------------------------------------------------------------------- -----------------------YOUR LIGHT SETTINGS-------------------------- motionSensorID = {42}; -- change id for your motion sensor. LuxSensorID = {53}; -- change id for your light sensor. --Enter the name of your Global variable. WITHOUT IT, THE SCENE DOES NOT WORK. Capital sensitive! sleepState = "SleepState"; --Sleep globalstate variable. timeOfDay = "TimeOfDay"; --Time of Day Global variable. presentState = "PresentState"; --Present state Global variable. --Enter the values of your global variables stated above. If not using, copy the name in front of the "YourValueName" sleepStateMapping = {Sleeping="Sleeping", Awake="Awake"}; timeOfDayMapping = {Morning="Morning", Day="Day", Evening="Evening", Night="Night"}; presentStateMapping = {Home="Home", Away="Away", Holiday="Holiday"}; -- Set the lux value for which the lights have to be turned on. -- If you don't want to use the MinLux then just set it to: 65535 minLuxMorning = 2500; minLuxDay = 2500; minLuxEvening = 2500; minLuxNight = 2500; --If the current lux value is above the maxlux, the lights will turn off after their set onTime. maxLuxMorning = 6000; maxLuxDay = 6000; --[[ Now the most important part: Here you can enter what light, for how long and at what value has to be turned on. Leave empty brackets for no lights. To set the light value without timer use 2 parameters: {id=LightID, setValue="VALUE"} To set the light value with timer use 3 parameters: {id=LightID, setValue="VALUE", onTime=timeInSeconds } To set the light value for RGBW: use the above, where setValue is: setValue={R="255",G="255",B="255",W="255"} -- RGBW set: {id=LightID, setValue={R="255",G="255",B="255",W="255"}, onTime=timeInSeconds } --]] --lightsSleeping = {}; --lights that are triggered when Sleepstate is sleeping. --lightsMorning = {{id=471, setValue="99", onTime=300},{id=491, setValue="99", onTime=300},{id=902, setValue="turnOn", onTime=360}}; --lightsDay = {{id=471, setValue="80", onTime=90},{id=491, setValue="80", onTime=90}}; --lightsEvening = {{id=471, setValue="60", onTime=300},{id=491, setValue="60", onTime=300},{id=902, setValue="turnOn", onTime=300}}; --lightsNight = {{id=471, setValue="45", onTime=60}, {id=491, setValue="45", onTime=60}}; lightsSleeping = {}; --lights that are triggered when Sleepstate is sleeping. lightsMorning = {{id=73, setValue="turnOn", onTime=360}}; lightsDay = {{id=73, setValue="turnOn", onTime=360}}; lightsEvening = {{id=73, setValue="turnOn", onTime=360}}; lightsNight = {{id=73, setValue="turnOn", onTime=360}}; --Manual Override, the time that lights will not be turned ON again after manually turning them off. OverrideFor = 90; dimmDownTime = 10; -------------------------------------------------------------------- -------------------------EXTRA FEATURES----------------------------- extraMorningFunc = function() -- Add your extra code here. If you want some checks or maybe run a virtual device button. --This code is always triggered if there is motion. -- movieLights = {{180, "10"},{181, "10"} }; --if (xbmc == "playing" ) then CallLightArray(movieLights); ExtraDebug("Extra morning function called"); end extraDayFunc = function() -- Add your extra code here. If you want some checks or maybe run a virtual device button. --This code is always triggered if there is motion. ExtraDebug("Extra day function called"); end extraEveningFunc = function() -- Add your extra code here. If you want some checks or maybe run a virtual device button. --This code is always triggered if there is motion. ExtraDebug("Extra evening function called"); end extraNightFunc = function() -- Add your extra code here. If you want some checks or maybe run a virtual device button. --This code is always triggered if there is motion. ExtraDebug("Extra night function called"); end extraLightTriggerChecks = function() --add extra checks here. and return the total true or false value. --if returning false the lights will not be triggered. -- for instance: return ( (pcTurnedOff == true ) and (xbmc ~= "Empty") ); -- return true to enable lights to turn on return true; end extraOffChecks = function() --return true to keep lights on. return false; end -------------------------------------------------------------------- ----------------------ADVANCES SETTINGS----------------------------- local showStandardDebugInfo = true; -- Debug shown in white local showExtraDebugInfo = false; -- Debug shown in orange -------------------------------------------------------------------- -------------------------------------------------------------------- -- DO NOT CHANGE THE CODE BELOW -- -------------------------------------------------------------------- --UPDATE FROM HERE --private variables startSource = fibaro:getSourceTrigger(); keepLightsOn = false; timerRunning = false; previousLights = nil; version = "1.6.7"; SavedState = { homeStatus = "", sleepState = 0, timeOfDay = "", lux = 0, motion = 0, startTime = 0 } CurrentState = { homeStatus = "", sleepState = "", timeOfDay = "", lux = 0, motionState = 0, currentLightArray = {} } RGBWDeviceType = { "com.fibaro.RGBW", "com.fibaro.colorController", "com.fibaro.FGRGBW441M" } BinaryDeviceType = { "com.fibaro.binarySwitch","com.fibaro.FGWP101", "turnOn" } DimmerDeviceType = { "com.fibaro.multilevelSwitch" } OffModes = {None, ByScene, ManualOverride } function Debug( color, message ) fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span")); end --Making sure that only one instance of the scene is running. fibaro:sleep(50); --sleep to prevent all instances being killed. if (fibaro:countScenes() > 1) then if (showExtraDebugInfo) then Debug( "grey", "Abort, Scene count = " .. fibaro:countScenes()); end fibaro:abort(); end --------------------------EXECUTION---------------------------------- function SetCurrentStatus() ExtraDebug("Updating current variable statuses"); CurrentState.homeStatus = GetPresentState(); CurrentState.timeOfDay = GetTimeOfDay(); CurrentState.sleepState = GetSleepState(); CurrentState.lux = GetAverageLuxValue(); CurrentState.motionState = GetCurrentMotionStatus(); end function SaveCurrentStatus() ExtraDebug("Saving current variable statuses"); SavedState.homeStatus = CurrentState.homeStatus; SavedState.timeOfDay = CurrentState.timeOfDay; SavedState.sleepState = CurrentState.sleepState; SavedState.lux = CurrentState.lux; SavedState.motion = CurrentState.motionState; end function CheckStatusChanges() ExtraDebug("Status change check"); if (CurrentState.homeStatus ~= SavedState.homeStatus ) or (CurrentState.timeOfDay ~= SavedState.timeOfDay ) then if (CurrentState.homeStatus ~= presentStateMapping.Home ) then TurnOffLights(); else SceneTriggered(); --reset time. end; end SaveCurrentStatus(); -- if we still have a motion then reset timer. if ( (CurrentState.motionState ~= 0 or extraOffChecks() ) and not IsMaxLuxExceeded() ) then ExtraDebug( "Resetting time" ); SavedState.startTime = os.time(); else ExtraDebug("Timer is not reset."); end --any other case, we are not resetting the timer. end function IsMaxLuxExceeded() if (CurrentState.timeOfDay == timeOfDayMapping.Morning and CurrentState.lux > maxLuxMorning ) then ExtraDebug( "Current lux value: " .. CurrentState.lux .. " higher then max Lux Morning: " .. maxLuxMorning .. "."); return true; elseif (CurrentState.timeOfDay == timeOfDayMapping.Day and CurrentState.lux > maxLuxDay ) then ExtraDebug( "Current lux value: " .. CurrentState.lux .. " higher then max Lux Day: " .. maxLuxDay .. "."); return true; end return false; end function LightsOff( lightArray ) local stillLightsOn = 0; local currentTime = os.time(); for i = 1,#lightArray do if ( lightArray[i].onTime ~= nil) then lightItem = lightArray[i]; lightItem.OffMode = CheckManualOverrideItem( lightItem ); --local if ( lightItem.OffMode == "ManualOverride" ) then ExtraDebug("Manual override for light: [" .. lightItem.id .. "]" .. lightItem.name .. " active, not turning on"); goto continue; end --On till: local timeL = SavedState.startTime + (lightItem.onTime); local timeLeft = timeL - currentTime; if (timeLeft >= 0 ) then ExtraDebug("Time left for: [" .. lightItem.id .. "]" .. lightItem.name .. ": " .. timeLeft .. " seconds" ); end if ( timeLeft < dimmDownTime ) then if ( lightItem.OffMode ~= "ManualOverride" ) then lightItem.OffMode = "ByScene"; end if ( (timeLeft <= 0) and (lightItem.currentValue ~= 0) ) then fibaro:call(lightItem.id, "turnOff"); StandardDebug("Switch off light: [" .. lightItem.id .. "]'" .. lightItem.name .."'"); else if ( item.lightType == "com.fibaro.multilevelSwitch" ) then currentValueDiv = roundit(((lightItem.currentValue) / (dimmDownTime)), 0); currentValueNew = (lightItem.currentValue - currentValueDiv); if (currentValueNew <=0 ) then currentValueNew = 0; end fibaro:call(lightItem.id, "setValue", tostring(currentValueNew)); end stillLightsOn = stillLightsOn + 1; end elseif (CheckLightToBeTurnedOnAgain(lightItem)) then ExtraDebug("Turn light: " .. lightItem.id .. " back on"); turnLightOn(lightItem); lightItem.OffMode = ""; stillLightsOn = stillLightsOn + 1; else lightItem.OffMode = "NoOverride"; stillLightsOn = stillLightsOn + 1; end end ::continue:: end return stillLightsOn; end function KeepLightsOnTimer() ExtraDebug("--------------- Timer running ---------------"); ExtraDebug("starting with while loop, to keep lights on"); SavedState.startTime = os.time(); SaveCurrentStatus(); sleepTime = 1000; while ( keepLightsOn ) do ExtraDebug("--------------- next timer run ---------------"); fibaro:sleep(sleepTime); start_time = os.clock(); SetCurrentStatus(); currentLightArray = GetTimeOfDayLightArray(); UpdateLightValues(currentLightArray); CheckStatusChanges(); local stillLightsOn = 0; stillLightsOn = LightsOff( currentLightArray ); if (stillLightsOn == 0 ) then keepLightsOn = RunManualOverrideMode( currentLightArray ); end_time = 0; --if lights turned back on after override. else end_time = os.clock() end elapsed_time = (end_time - start_time) * 1000; sleepTime = 1000 - elapsed_time; end end function CheckManualOverrideItem( currentItem ) --ExtraDebug("Manual override check for: [" .. currentItem.id .. "]" .. currentItem.name); if (currentItem.currentValue == 0 and currentItem.OffMode ~= "ByScene" ) then ExtraDebug( "Manual override for light: [" .. currentItem.id .. "]" .. currentItem.name .. " active" ); return "ManualOverride"; elseif (currentItem.currentValue ~= 0 and currentItem.OffMode == "ManualOverride" ) then ExtraDebug( "Manual override for light: [" .. currentItem.id .. "]" .. currentItem.name .. " cancelled" ); return "NoOverride"; end return currentItem.OffMode; --returning current mode; end function RunManualOverrideMode( currentLightArray ) OverrideForAll = CheckIfAllInOverrideMode(currentLightArray); if ( OverrideForAll ) then ExtraDebug("-----------------Override Mode---------------"); OverrideTimer = os.time(); while ( OverrideForAll and (OverrideTimer + OverrideFor ) - os.time() > 0 ) do ExtraDebug("Still in override for: " .. (OverrideTimer + OverrideFor ) - os.time() .. " seconds" ); fibaro:sleep(1000); UpdateLightValues(currentLightArray); OverrideForAll = CheckIfAllInOverrideMode(currentLightArray); motion = GetCurrentMotionStatus(); if ( motion ~= 0 ) then OverrideTimer = os.time(); end end else return false; end -- if ( (OverrideTimer + OverrideFor ) - os.time() <= 0 ) then --time has end. So not continue to run lights loop -- return false; -- end if (OverrideForAll) then return false; --run lights else return true; end end function CheckIfAllInOverrideMode(currentLightArray) OverrideForAll = 0; for i = 1,#currentLightArray do if ( CheckManualOverrideItem(currentLightArray[i]) == "ManualOverride" ) then OverrideForAll = OverrideForAll +1; else return false; end end if ( OverrideForAll ~= 0 and OverrideForAll == #currentLightArray ) then return true; end return false; end function RunTimer() if ( keepLightsOn and not timerRunning ) then ExtraDebug("Starting timer, not yet running"); timerRunning = true; KeepLightsOnTimer(); else ExtraDebug("Timer already running, returning"); end end function TurnOffLights() local timeOfDayArray = GetTimeOfDayLightArray(); SetLightValues(timeOfDayArray); UpdateLightValues(timeOfDayArray); CallLightArray(timeOfDayArray, "off" ); return; end ----------------------Turn lights on functions------------------------ function CallLightArray( lightArray, turnOnOrOff ) if (#lightArray == 0 ) then if (CurrentState.sleepState == sleepStateMapping.Sleeping) then noLightsSetText = "lightsSleeping"; else noLightsSetText = CurrentState.timeOfDay; end StandardDebug( "No lights set for " .. noLightsSetText ); return; end if not ( CheckIfTable(lightArray, "lights" .. CurrentState.timeOfDay ) ) then return end for i = 1,#lightArray do if not ( CheckIfTable(lightArray[i], "lights" .. CurrentState.timeOfDay ) ) then break end lightItem = lightArray[i]; if (turnOnOrOff == "on" ) then turnLightOn(lightItem); if (lightItem.onTime ~= nil) then keepLightsOn = true; end else fibaro:call(lightItem.id, "turnOff"); --Always turn off, if HC2 light status is not actual. if ( lightItem.currentValue ~= 0) then keepLightsOn = false; StandardDebug("Switch off light: [" .. lightItem.id .. "]'" .. lightItem.name .."'"); end end end StandardDebug( "Lights turned: " .. turnOnOrOff .. " for " .. CurrentState.timeOfDay ); end function turnLightOn( lightItem ) if (lightItem.lightType == "com.fibaro.multilevelSwitch" ) then fibaro:call(lightItem.id, "setValue", tostring(lightItem.setValue)); StandardDebug( "Set: [" .. lightItem.id .. "]'" .. lightItem.name .. "' to Value: " .. lightItem.setValue ); elseif ( lightItem.lightType == "com.fibaro.RGBW" )then StandardDebug( "Turn: [" .. lightItem.id .. "]'" .. lightItem.name .. "' On"); if ( lightItem.setValue.brg~= nil ) then fibaro:call(lightItem.id, "setBrightness", tostring(lightItem.setValue.brg)); else local clrvalues =lightItem.setValue; fibaro:call(lightItem.id, "setColor", clrvalues.R, clrvalues.G, clrvalues.B, clrvalues.W) end elseif (lightItem.lightType == "com.fibaro.binarySwitch") then fibaro:call(lightItem.id, "turnOn"); StandardDebug( "Turn: [" .. lightItem.id .. "]'" .. lightItem.name .. "' On"); end end function CheckPreviousLights( NewLightArray ) if ( previousLights ~= nil ) then for i = 1,#previousLights do local lightItem = previousLights[i]; for i = 1,#NewLightArray do local lightItem1 = NewLightArray[i]; inarray = false; if ( lightItem.id == lightItem1.id ) then inarray= true; break end end if not ( inarray ) then fibaro:call(lightItem.id, "turnOff"); end end end previousLights = NewLightArray; end function LightperDayPart( minLux, lightArray ) local newLuxValue = CurrentState.lux; if ( extraLightTriggerChecks() ) then if ( newLuxValue > minLux ) then StandardDebug( "Sensor lux: " .. newLuxValue .. " higher then minValue: " .. minLux .. " : no action"); else StandardDebug("Sensor lux: " .. newLuxValue .. " is lower then minValue: " .. minLux); SetLightValues(lightArray); CallLightArray( lightArray, "on" ); CheckPreviousLights( lightArray ); end else ExtraDebug("ExtraLightTriggerChecks failed, so no lights"); end end function SceneTriggered() if ( CurrentState.homeStatus ~= presentStateMapping.Home ) then ExtraDebug("Presentstate = not at home, so no lights"); elseif ( CurrentState.sleepState == sleepStateMapping.Sleeping ) then LightperDayPart( 65535, lightsSleeping ); elseif ( CurrentState.timeOfDay == timeOfDayMapping.Morning ) then extraMorningFunc(); LightperDayPart( minLuxMorning, lightsMorning ); elseif ( CurrentState.timeOfDay == timeOfDayMapping.Day ) then extraDayFunc(); LightperDayPart( minLuxDay, lightsDay ); elseif ( CurrentState.timeOfDay == timeOfDayMapping.Evening ) then extraEveningFunc(); LightperDayPart( minLuxEvening, lightsEvening ); elseif ( CurrentState.timeOfDay == timeOfDayMapping.Night ) then extraNightFunc(); LightperDayPart( minLuxNight, lightsNight ); else ErrorDebug( "No lights: " .. CurrentState.timeOfDay ); end if (keepLightsOn == true) then RunTimer(); end end function SceneTriggeredByLights( st ) if (st == "off") then ExtraDebug( "light turned off, sleep 4 sec" ); fibaro:sleep(4000); elseif (st == "on") then ExtraDebug( "light turned on, activating timer" ); fibaro:sleep(4000); --TODO: add light to current array. --keepLightsOn = true; --RunTimer(); end end ------------------------STATUS functions------------------------------ function GetTimeOfDay() return LookupGlobal( timeOfDay, "TimeOfDay", "Day"); end function GetSleepState() return LookupGlobal( sleepState, "sleepState", "Awake"); end function GetPresentState() return LookupGlobal( presentState, "presentState", "Home"); end function LookupGlobal( name, stateName, default ) local ps = fibaro:getGlobalValue( name ); if ( (ps ~= "") and (ps ~= nil ) ) then ExtraDebug("returned " .. stateName .. ": " .. ps ); return ps; else ErrorDebug( stateName .. " variable not found"); return default; end end function lightsStatus( id ) --check if lights are already on. allLights = {lightsSleeping, lightsMorning, lightsDay, lightsEvening, lightsNight }; for i = 1,#allLights do for iL = 1, #allLights[i] do local lightItem = allLights[i][iL]; if ( lightItem.id == tonumber(id) ) then if ( lightItem.currentValue == 0 ) then return "off"; else return "on"; end end end end ErrorDebug("Light status unknown"); return "Unknown"; end function GetTimeOfDayLightArray() if ( CurrentState.sleepState == sleepStateMapping.Sleeping ) then return lightsSleeping; elseif ( CurrentState.timeOfDay == timeOfDayMapping.Morning ) then return lightsMorning; elseif ( CurrentState.timeOfDay == timeOfDayMapping.Day ) then return lightsDay; elseif ( CurrentState.timeOfDay == timeOfDayMapping.Evening ) then return lightsEvening; elseif ( CurrentState.timeOfDay == timeOfDayMapping.Night ) then return lightsNight; end end function GetCurrentMotionStatus() local sensorbreached = 0; if (CheckIfTable(motionSensorID, "motionSensorID") ) then for i = 1,#motionSensorID do if ( tonumber(fibaro:getValue(motionSensorID[i], "value")) > 0 ) then sensorbreached = 1; end end else --if not a table, just return the value of the containing ID sensorbreached = tonumber(fibaro:getValue(motionSensorID, "value")) end return sensorbreached; end function GetAverageLuxValue() local luxAverage = 0; if (CheckIfTable(LuxSensorID, "LuxSensorID") ) then if (#LuxSensorID == 1) then return tonumber(fibaro:getValue(LuxSensorID[1], "value")); end for i = 1,#LuxSensorID do luxAverage = luxAverage + tonumber(fibaro:getValue(LuxSensorID[i], "value")); end luxAverage = roundit( (luxAverage / #LuxSensorID), 0 ); else --if not a table, just return the value of the containing ID luxAverage = tonumber(fibaro:getValue(LuxSensorID, "value")); end return luxAverage; end function UpdateLightValues( currentArray ) for i = 1,#currentArray do item = currentArray[i]; newValue = fibaro:getValue(item.id, "value"); item.currentValue = tonumber(newValue) ~= nil and tonumber(newValue) or ( newValue == "true" and 1 or 0 ); if ( item.lightType == "com.fibaro.RGBW" )then color = fibaro:getValue(item.id, "color"); c = {R="0", G="0", B="0", W="0", brg="0" } c.R, c.G, c.B, c.W = color:match("([^,]+),([^,]+),([^,]+),([^,]+)"); c.brg = fibaro:getValue(item.id, "brightness"); item.currentValue = c; end end end function SetLightValues(currentArray) for i = 1,#currentArray do item = currentArray[i]; item.name = tostring(fibaro:getName(item.id)); item.OffMode = "NoOverride"; if (item.name == nil) then item.name = "Unknown"; end item.lightType = GetDeviceType( item.id ); end end function GetDeviceType(itemId) deviceType = fibaro:getType(item.id); if ( idIsInList(deviceType, RGBWDeviceType) ) then deviceType ="com.fibaro.RGBW"; elseif ( idIsInList(deviceType, BinaryDeviceType) ) then deviceType = "com.fibaro.binarySwitch"; elseif ( idIsInList(deviceType, DimmerDeviceType ) ) then deviceType = "com.fibaro.multilevelSwitch"; --elseif( ) then --deviceType = "Philips.Hue"; end return deviceType; end --------------------Helper functions-------------------------------- function CheckLightToBeTurnedOnAgain(lightItem) if not (lightItem.OffMode=="ByScene") then return; end if (lightItem.lightType == "com.fibaro.multilevelSwitch" ) then if (lightItem.currentValue) < tonumber(lightItem.setValue) then return true; end elseif( lightItem.lightType == "com.fibaro.RGBW" )then c = lightItem.currentValue; if (c.R == "0" and c.G == "0" and c.B == "0" and c.W == "0" ) then return true; end elseif (lightItem.lightType == "com.fibaro.binarySwitch") then if (lightItem.setValue == "turnOn" and lightItem.currentValue == 0 ) then return true; end end return false; end function CheckIfTable( array, arrayname ) local tableCheck = tostring( type( array ) ); if ( tableCheck ~= "table" ) then ErrorDebug("Missing brackets for variable: '" .. arrayname .. "', please place extra brackts: { } around: " .. array .. "."); return false; end return true; end function roundit(num, idp) local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end function idIsInList( startSourceId, sensorList ) for i = 1,#sensorList do if ( startSourceId == sensorList[i] ) then return true; end end return false; end --------------------Debugging Functions----------------------------- function StandardDebug( debugMessage ) if ( showStandardDebugInfo ) then Debug( "white", debugMessage); end end function ExtraDebug( debugMessage ) if ( showExtraDebugInfo ) then Debug( "orange", debugMessage); end end function ErrorDebug( debugMessage ) Debug( "red", "Error: " .. debugMessage); Debug( "red", ""); end function TestDebug(debugMessage ) Debug( "blue", "Testing: " .. debugMessage ); end ----------------------START OF THE SCENE---------------------------- SetCurrentStatus(); StandardDebug("Home status: " .. CurrentState.homeStatus ); StandardDebug("Motion status: " .. ( CurrentState.motionState == 0 and "No movement" or "movement")); if (startSource["type"] == "property") then startSourceID = tonumber(startSource['deviceID']); triggerDebug = "Triggered by: " .. startSourceID; if ( idIsInList( startSourceID, motionSensorID ) ) then StandardDebug( triggerDebug .. " Motion sensor" ); if ( CurrentState.motionState > 0 ) then SceneTriggered(); end elseif ( idIsInList( startSourceID, LuxSensorID ) ) then StandardDebug( triggerDebug .. " Lux sensor" ); ExtraDebug( "Lux value changed to: " .. CurrentState.lux ); if ( CurrentState.motionState > 0 ) then SceneTriggered(); end else StandardDebug( triggerDebug .. " Light switch" ); st = lightsStatus( startSourceID ); if (st == "Unknown") then ErrorDebug( "Unknown light trigger" ); else SceneTriggeredByLights( st ); end -- Maybe we can change the light preset to make it more intelligent. -- Maybe we can change the Lux preset to make it more intelligent. end elseif ( startSource["type"] == "global" ) then StandardDebug( "Triggered by: " .. "global variable" ); -- If home status away, we trigger so the current array will be turned off. If motion, turn them on. if (CurrentState.homeStatus ~= presentStateMapping.Home) then TurnOffLights(); elseif (CurrentState.motionState > 0 ) then SceneTriggered(); end else StandardDebug( "Triggered by: " .. startSource["type"] .. " , Not checking the motion state." ); --Just run the Light Code, not checking for motion. Probably triggered manually. if ( startSource["type"] == "other" ) then SceneTriggered(); end end Debug( "green", "© Smart Lights V" .. version .. " | by Control Living, Finished" ); Debug( "green", "-------------------------------------------------------" ); --fibaro:abort(); --otherwise scene will stay alive to long. --UPDATE TILL HERE j’espère que cela pourra aider a décortiquer cette histoire :-)
  7. voici l'entete : --[[ %% properties 42 value 53 value %% globals TimeOfDay PresentState sleepState --]] 42 --> mouvement 53 --> lux -------------------------------------------------------------------- -----------------------YOUR LIGHT SETTINGS-------------------------- motionSensorID = {42}; -- change id for your motion sensor. LuxSensorID = {53}; -- change id for your light sensor. je ne vois vraiment pas pourquoi cela ne s'allume pas ...
  8. donc si je vous suis -- Set the lux value for which the lights have to be turned on. -- If you don't want to use the MinLux then just set it to: 65535 minLuxMorning = 2500; minLuxDay = 2500; minLuxEvening = 2500; minLuxNight = 2500; --If the current lux value is above the maxlux, the lights will turn off after their set onTime. maxLuxMorning = 6000; maxLuxDay = 6000; la les min sont a 2500 donc en dessous de 2500 cela s'allume pour le moment la sonde lux donne 500 donc on est bon ? etat des VG : SleepState = .Awake TimeOfDay = Day PresentState = Home commande pour l'allumage : lightsSleeping = {}; --lights that are triggered when Sleepstate is sleeping. lightsMorning = {{id=73, setValue="turnOn", onTime=360}}; lightsDay = {{id=73, setValue="turnOn", onTime=360}}; lightsEvening = {{id=73, setValue="turnOn", onTime=360}}; lightsNight = {{id=73, setValue="turnOn", onTime=360}}; si je ne me trompe pas tout a l'air correct non ?
  9. c'est juste une échelle de valeur différente toi 0 --> 20 par ex (0% = 0 et 100% = 20) moi 0 --> 5000 (0% = 0 et 100% = 5000) après c'est juste une autre échelle mais ça devrait marcher.... je ne comprends pas
  10. les sondes réagisse bien lumière éteinte 500lux (un peu sombre mais on vois un peu) lumière allumé 5196 lux je suis d'accord sur le fait que les valeur soit bizarre mais bon au lieu de me basé sur min 5 max 15, je me base sur min 500 max 2500 en prod ça ne devrait pas interférer avec le scripts
  11. le type d’éclairage est un simple on/off
  12. oui je sais les valeur de mes sondes lux sont bizarre en pleine journée quand beaucoup de lumière dehors mes pièces sont entre 2000 et 3500 lux sur mes sondes (valeur afficher sur la hc2) donc min 2500 lux c'est pour mes test ainsi je suis sur que les lux n’interfère pas dans le script quand cela marchera je baisserai cette valeur
  13. alors voici la config des variables : --Enter the name of your Global variable. WITHOUT IT, THE SCENE DOES NOT WORK. Capital sensitive! sleepState = "SleepState"; --Sleep globalstate variable. timeOfDay = "TimeOfDay"; --Time of Day Global variable. presentState = "PresentState"; --Present state Global variable. --Enter the values of your global variables stated above. If not using, copy the name in front of the "YourValueName" sleepStateMapping = {Sleeping="Sleeping", Awake="Awake"}; timeOfDayMapping = {Morning="Morning", Day="Day", Evening="Evening", Night="Night"}; presentStateMapping = {Home="Home", Away="Away", Holiday="Holiday"}; les paramètres lux : -- Set the lux value for which the lights have to be turned on. -- If you don't want to use the MinLux then just set it to: 65535 minLuxMorning = 2500; minLuxDay = 2500; minLuxEvening = 2500; minLuxNight = 2500; --If the current lux value is above the maxlux, the lights will turn off after their set onTime. maxLuxMorning = 3000; maxLuxDay = 3000; les commandes (toutes les même) lightsSleeping = {}; --lights that are triggered when Sleepstate is sleeping. lightsMorning = {{id=73, onTime=300}}; lightsDay = {{id=73, onTime=300}}; lightsEvening = {{id=73, onTime=300}}; lightsNight = {{id=73, onTime=300}}; --Manual Override, the time that lights will not be turned ON again after manually turning them off. OverrideFor = 90; dimmDownTime = 10; je ne comprends pas trop a quoi correspond ceci : OverrideFor = 90; dimmDownTime = 10; mais j'ai laisser par défaut l'etat des variable global PresentState = Home TimeOfDay = Day SleepState = Awake et encore une fois cette ligne dans les log qui me pousse a croire qu'il envoie la commande d'allumage Lights turned: on for Day qui est je crois : lightsDay = {{id=73, onTime=300}}; ou ai-je fait une erreur :-) ?
  14. justement j'essaye comme cela : {{id=73, onTime=300}}; le onTime veut dire on allume pendant 300 sec OU on allume aprés 300sec ?
  15. bonjour juste pour etre sur, les lignes de log indique : que detecteur mvt a detecter un mouvement les lux sont bien inférieur au lux min commande pour allumer les lumière ? [DEBUG] 10:11:01: Home status: Home [DEBUG] 10:11:01: Motion status: movement [DEBUG] 10:11:01: Triggered by: 42 Motion sensor [DEBUG] 10:11:01: Sensor lux: 500 is lower then minValue: 2500 [DEBUG] 10:11:01: Lights turned: on for Night mais rien ne s'allume... pour être sur de la commande : {{id=73, onTime=300}}; ---> turnOn de l'id 73 pendant 300 seconde puis turnOff ?
×
×
  • Créer...