Calendar schedule to switch output on / off

I’m looking for some tips on how to design a schedule to switch an output on or off (in reality two 11kV generating engines). Ideally I would want a calendar where periods could be selected for the output to be on, with the facility to “block” book the “on” period. Basically like outlook express calendar, or, like a 7 day timer which this will in fact replace. A few pointers in the right direction would be really appreciated. I’m familiar with SQL when querying past time/dates but cannot seem to think of a way to plan into the future. I’m hoping the method would also be editable/foolproof i.e. self checking for duplicates etc, but I guess that will come with the “building” of such a method.

This is a very open-ended question.

Some things to think about that might influence your design:

What kind of resolution do you require? Can you consider a day to be a block of 24 hours, or do you need minute/second resolution?

Is there only 1 period of on-time allowed per day or can it by cycled on and off multiple times a day?

How fancy do you need the UI to look?

I would be looking for a resolution to a quarter of an hour, and would like to be able to have multiple on/offs to allow it to be versatile. As far as looks, well the prettier the better for sure. Heres what I have so far:

A SQL script that makes a calendar table with columns, Row number, date, startdate and time, enddate and time along with columns containing data regarding that row i.e. week/weekend (boolean), month, week number etc (more info to make “block” editing easier in the future???)

This populates the week view component which I can double click for an edit window (want a right click menu - any tutorials for this? if not have to copy others examples.) Edit window gets passed the SelectedEvent .

Finally came up with a gateway script (timer):

UfStartdate = system.db.runScalarQuery(“select startdate from calendar where “mm-dd-yy” like (SELECT CONVERT(VARCHAR(8), GETDATE(), 10))”)
UfEnddate = system.db.runScalarQuery(“select enddate from calendar where “mm-dd-yy” like (SELECT CONVERT(VARCHAR(8), GETDATE(), 10))”)
from java.util import Calendar
Startcal = Calendar.getInstance()
Startcal.setTime(UfStartdate)
Endcal = Calendar.getInstance()
Endcal.setTime(UfEnddate)
Nowcal = Calendar.getInstance()
NowmS = Nowcal.getTimeInMillis()
StartmS = Startcal.getTimeInMillis()
EndmS = Endcal.getTimeInMillis()
if NowmS > StartmS and NowmS < EndmS:
system.tag.writeToTag(“Engine’s ON”, 1)
else:
system.tag.writeToTag(“Engine’s ON”, 0 )

Struggled (6hrs) to get the SQL to a java format for comparison but I believe the above works OK. I’m thinking of adding an “add” window that just adds another row on the SQL table, also putting checks in place to prevent time overlaps etc. But as a starter does this look “correct”???

Yep, I think you’re on the right track.

Creating right-click menus is certainly script heavy. Follow the example in the user manual found here:
inductiveautomation.com/supp … upmenu.htm