Help on luup script for light on/off to concrete time of the day

I’m new to this world and I need help. I’m usig following a script from micasaverde, without success:

[code]local startTime = “10:30”
local endTime = “10:32”

local hour = tonumber( startTime:sub( startTime:find(“%d+”) ) )
local minute = tonumber(startTime:sub(-2))

if hour and minute then
startTime = hour * 100 + minute
else
luup.log(“ERROR: invalid start time”)
return false
end

hour = tonumber( endTime:sub( endTime:find(“%d+”) ) )
minute = tonumber(endTime:sub(-2))

if hour and minute then
endTime = hour * 100 + minute
else
luup.log(“ERROR: invalid end time”)
return false
end

local currentTime = os.date(“*t”)
currentTime = currentTime.hour * 100 + currentTime.min

luup.log("startTime = " … startTime … "; currentTime = " … currentTime … "; endTime = " … endTime)

if startTime <= endTime then
– Both the start time and the end time are in the same day:
– if the current time is in the given interval, run the scene.
if startTime <= currentTime and currentTime <= endTime then
return true
end
else
– The start time is before midnight, and the end time is after midnight:
– if the current time is not outside the given interval, run the scene.
if not (endTime < currentTime and currentTime < startTime) then
return true
end
end

return false[/code]

=======
Any help are welcomed.

@somar,

Welcome!

What are you trying to use it for?

This code will allow the actions you specified in the scene to commence if the current time is within the specified window; otherwise nothing is done. It needs a trigger to run.
(Example: allow a motion sensor to only turn on a light in a specified time frame. You’d create a scene, use the ‘tripped’ event from the motion sensor as the trigger, select the light you want to turn on, and put this code on the Luup tab.)

What I want is:

switch on a light at 20h:30m
switch off the same liight at 07h45m

every day.

Thank you for your availability.

That can be done without Luup/script. You can create two scenes, each triggered by a schedule.

Perhaps @Brientim’s write-up will help?

I’m usig UI4 and I don’t see how can I do it?

I understand that shoud be simple but I was not able to do it.

Thank you

For UI4 See http://wiki.micasaverde.com/index.php/Timer.
The same logic should be applied to establish a scene and then scheduling the timer.
I would recommend still using two scene.

Here’s a screenshot.

Many thanks for the support.

I’ve already done it, this creates a timer, but I don’t see how or where can I associate with a light.

Can you please tell me how we associate them?

In that same scene, click on the [tt]Commands[/tt] tab and select the appropriate light(s) and actions.