I am revising this post......new Service IDs being created and new example will be posted
later today. Thanks ....Tim
For more info read all the responses.
.....................................
open a device and goto the advanced tab
Create a new Variable at the bottom.....first the Service, for this example use "Tim"
Then the Variable....enter "TimeA"
Under Value enter "10:00"
Close and Save (UI bug....don't try doing more than one....only the last one will be saved)
Create another Variable at the bottom....first the Service again make it "Tim"
Then the Variable....enter "TimeB"
Under Value enter "11:00"
now start a new scene and give it a job to turn off a light nearby.
goto the timer section and add a new timer to run every minute.
goto the Luup tab and paste in the following code:
***************************************************
local startTime = luup.variable_get("Tim","TimeA",52)
local endTime = luup.variable_get("Tim","TimeB",52)
local hour = tonumber( startTime:sub( startTime:find("%d+") ) )
local minute = tonumber(startTime:sub(-2))
startTime = hour * 60 + minute
luup.variable_set("Tim","STime",startTime,52)
hour = tonumber( endTime:sub( endTime:find("%d+") ) )
minute = tonumber(endTime:sub(-2))
endTime = hour * 60 + minute
luup.variable_set("Tim","ETime",endTime ,52)
local currentTime = os.date("*t")
currentTime = currentTime.hour * 60 + currentTime.min
luup.variable_set("Tim","CTime",currentTime,52)
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
luup.variable_set("Tim","Between?","Yes",52)
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
luup.variable_set("Tim","Between?","Yes",52)
return true
end
end
luup.variable_set("Tim","Between?","No",52)
return false
*******************************
I recommend you paste the code first into notepad for editing and saving.
Replace the ID number "52" with your ID number to the device holding the new Variables
If you have my program with variable watch run it now.....select your device and the new variables will pop up.
Four more will be created automatically "STime", "ETime", "CTime", and "Between?"
These variables represent Start Time, End Time, Current Time, and is it between those times.
If you are not running my program it will work under the Vera UI but its slower because the UI does NOT update its variables until a complete refresh is done on the UI. ( that means hit the refresh button at the top right and press save)
Using the advanced tab you can change the variables in your program....the 10:00 and 11:00 are your start and stop times so play with it.....if you are running my program you can see the current MIOS time with each update every two seconds. Try changing the times to the next minute and watch your variables update.
This is an example of an event that runs from time A to B and knows what to do do if they are on different days (after midnight)
The variable "Between?" is very important because it can be used in other Luup codes with very simple:
local BetweenTime = luup.variable_get("Tim","Between?",52) (use your ID of course.)
If BetweenTime = "Yes" then
turn up stereo to 100% and blow the neighbors away.....or whatever.
REMEMBER...that the scene only runs once a minute......so you must wait for the scene to execute in order to see the variables change. Be patient and have fun!
Is this starting to make sense?
Regards
Tim