<commit_before>--[[
%% properties
59 value
%% globals
--]]

-- Please note: 
-- Update the id's below to match yours.
-- This script requires global variable 'Sun' to be defined in the Variables Panel.

-- id of the motion sensor. Also update trigger at the top.
local motionSensor = 59
-- id of the light to switch
local light = 62
-- is the light a dimmer
local isDimmer = 1
-- dimmer percentage (ignored of not a dimmer)
local dimLevel = 10 

-- check how we are invoked
-- type=other => manual
local startSource = fibaro:getSourceTrigger();

-- if motion sensor is breached
if (((tonumber(fibaro:getValue(motionSensor, "value")) > 0 )
      -- or we invoke manually
      or startSource["type"] == "other" )
   -- and the sun is set (does not make sense to switch lights during daytime)
   and fibaro:getGlobalValue("Sun") == "Set")
then
    -- switch on the light
    fibaro:debug("Switched ON lights due to motion")
    if isDimmer == 1
      then
	    fibaro:call(light, "setValue", dimLevel);
    else
        fibaro:call(light, "turnOn");
    end
end
  
-- lights will be turned off by a separate scene.<commit_msg>improved script and added debug info<commit_after>--[[
%% properties
63 value
%% globals
--]]

-- Script to turn on lights when motion is detected
-- <NAME> <EMAIL>

-- Please note: 
-- Update the id's below to match yours. Also update trigger at the top.
-- This script requires global variable 'Sun' to be defined in the Variables Panel. See sunset/sunrise script for usage.

-- id of the motion sensor.
local motionSensor = 63
-- id of the light to switch
local light = 27
-- is the light a dimmer
local isDimmer = 1
-- dimmer percentage (ignored of not a dimmer)
local dimLevel = 70
-- whether or not to display debug messages
local debug = 1

-- check how we are invoked
-- type=other => manual
local startSource = fibaro:getSourceTrigger();
if debug ==1 then fibaro:debug("We were invoked by " .. startSource["type"]) end

-- if motion sensor is detected
if (((tonumber(fibaro:getValue(motionSensor, "value")) > 0 )
      -- or we invoke manually
      or startSource["type"] == "other" )
   -- and the sun is set (does not make sense to switch lights during daytime)
   and fibaro:getGlobalValue("Sun") == "Set")
then
    -- switch on the light
    if debug ==1 then fibaro:debug("Switching ON light due to motion") end
    if isDimmer == 1
      then
        if debug ==1 then fibaro:debug("Set dim level to " .. dimLevel .. "%") end
	    fibaro:call(light, "setValue", dimLevel);
    else
        if debug ==1 then fibaro:debug("Turned on the light") end
        fibaro:call(light, "turnOn");
    end
end
  
-- lights will be turned off by a separate scene.
{'fraction_non_alphanumeric': 0.10892193308550185, 'fraction_numerical': 0.010037174721189592, 'mean_word_length': 3.114678899082569, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7275952', 'n_tokens_mistral': 807, 'n_tokens_neox': 775, 'n_words': 350}