Having a scene run only between specific dates of the year

Hello,

Looking to control a device to operate only between the 20th April and the 31st August each year.

How can this be done in the Vera dashboard ?

Regards

Gavin

If you don’t want to use any plugin to do this, then unquestionably, your easiest approach is to use the usual scene scheduling system and set it up to run every day at the desired time.

Then, in just a couple of lines of Lua code in the scene, you can cancel the scene for unwanted days.

There are examples of this in many old posts and a search of the new forum may find them, but ask again if you need a more concrete example of the code.

XI use this global function

function isDateInRange(mdStart, mdEnd)
	local smS, sdS = string.match(mdStart, "(%d+)%/(%d+)")
	local smE, sdE = string.match(mdEnd, "(%d+)%/(%d+)")
	local mS = tonumber(smS)
	local dS = tonumber(sdS)
	local mE = tonumber(smE)
	local dE = tonumber(sdE)
	local tNow = os.date("*t")
	local mN = tNow.month
	local dN = tNow.day
	if(mE > mS) or((mE == mS) and(dE >= dS)) then
		return(((mN > mS) or((mN == mS) and(dN >= dS))) and((mN < mE) or((mN == mE) and(dN <= dE))))
	else 
		return(((mN > mS) or((mN == mS) and(dN >= dS))) or((mN < mE) or((mN == mE) and(dN <= dE))))
	end
end

and then in the “run this lua code” section of a scene, I put something like

return isDateInRange("12/01", "01/06")

this is used to control some scenes valid only for Christmas time, but I have others running only on summertime that use Daylight Saving Time to know if it’s time or not:

local tNow = os.date("*t")
return tNow.isdst

I personally find it more useful to follow this approach, but you have both now and it’s not so diffucult to switch just in case.

1 Like

I have used PLEG to operate an outlet only during Christmas. It goes on during Home Mode between 11/15 to 1/15. Goes off in Away, Night, and Away modes during those dates. Otherwise the outlet is manually turned on/off.

I do this all of the time using a plug-in called Reactor. Available by Apps>Install Apps>Reactor
This app is very powerful and has good documentation. Far easier, in my opinion, than PLEG.

2 Likes

Same here, I use Reactor extensively in my Vera System and it’s simply brilliant - it’s everything PLEG isn’t, Simple, Intuitive, logical but powerful too.

I foolishly bought PLEG before trying it and, despite being in IT, gave up on it after a few hours, it’s a nightmare!

2 Likes