LogicTimer Plugin

This little plugin does not do much that hasn’t been done before. It is just a delay timer. The special feature is that is it designed to be used from within a Programmable Logic Event Generator (PLEG) plugin. It allows dynamic, calculated and randomized timing to be incorporated into PLEG conditions by acting as a helper.

LogicTimer may be used to set a delay of up to 23:59:59 based on a few simple options:

[ul][li]Relative HH:MM:SS (from now)[/li]
[li]Absolute HH:MM:SS[/li]
[li]Daybreak (sunrise) ± HH:MM:SS[/li]
[li]Nightfall (sunset) ± HH:MM:SS[/li]
[li]All of the above with an added Random HH:MM:SS offset[/li][/ul]

In all cases, the times may be specified as HH:MM:SS, MM:SS or Seconds. Seconds may be any integer up to 86399. The time values may be calculated in PLEG condition expressions by using the special {(conditionname)} syntax in the action.

By default, LogicTimer will restart a running timer when Vera restarts - using the same end-time. This feature may be turned off.

The plugin also provides a dynamically-settable Flag variable that may be used to permit a single timer to be used for timing sequences in PLEG. Flag may be tested in condition expressions so that they only fire for their use of the timer rather than every time it ends.

See the attached PLEG report for an example of a simple, randomized light sequence. At 03:05 every day (the time is chosen to avoid DST changes), the timer is started with an end-time between 30 minutes before and 30 minutes after sunrise. This use of the timer is flagged as On. When the timer ends, the light is turned on and the timer is now started with an end-time between 1:00:00 and 1:30:00 from then. This use of the timer is flagged as Off. When the timer ends, the light is turned off and Flag is set to Clear to indicate that the timer is available for other uses.

See also the attached pdf for more details on how LogicTimer can be used with PLEG (or scenes).

The plugin files are: Here.

Edit: Files updated at 01:45 on 26/07/2013. Now shows Flag value above icon and added Trigger event.
Edit: Files updated at 20:21 on 26/07/2013. Flag may be set by appending F to newTimerCmd.
Edit: Files updated at 09:00 on 28/07/2013. Added date variables for additional Device Properties.
Edit: Files updated at 00:45 on 03/09/2013. Delayed running timer restart for 30s after Luup restart. Only I_LogicTimer.xml changed.

Thanks! ;D

I have attached a PLEG report to show a more-comprehensive example of how you may use LogicTimer to orchestrate random timing sequences. The example shows how lighting may be switched to give your home the appearance of being occupied whilst you are away.

There are two separate sequences - both enabled by a VirtualSwitch called Away. The reason for separating the sequences is that it allows you to set it running for the evening if you go out during the day. When you return home and turn-off Away, any remaining sequence is cancelled.

The morning sequence starts at 03:05 - chosen to be after any DST time change. It initiates the following actions:

[ul][li]Between 07:00:00 and 08:00:00, turn on the Bedroom light - unless it is already light[/li]
[li]If it is light when the Bedroom light timer fires, the whole morning sequence is skipped[/li]
[li]Between 30 seconds and 10 minutes 30 seconds later, turn on the Ensuite light[/li]
[li]Between 10 and 20 minutes later, turn off the Ensuite light[/li]
[li]Between 5 and 10 minutes later, turn on the Kitchen light[/li]
[li]Between 4 and 8 minutes later, turn on the Lounge light at 50% dim[/li]
[li]Between 30 and 90 minutes later, turn off the Bedroom light[/li]
[li]Between 1 and 11 minutes later, turn off the Kitchen light[/li]
[li]Between 30 seconds and 5 miutes 30 seconds later, turn off the Lounge light[/li]
[li]At this point the morning sequence has finished and LogicTimer will show AM_Finished[/li][/ul]

The evening sequence starts at 18:00. It initiates the following actions:

[ul][li]Between 19:00:00 and 20:00:00, turn on the Kitchen light[/li]
[li]Between 1 hour and 90 minutes later, turn off the Kitchen light[/li]
[li]Between 22:30:00 and 23:30:00, turn off the Lounge light (which was turned on when it got dark)[/li]
[li]20 seconds later, turn on the Bedroom light[/li]
[li]Between 10 seconds and 2 minutes 10 seconds later, turn on the Ensuite light[/li]
[li]Between 2 and 4 minutes later, turn off the Ensuite light[/li]
[li]Between 2 and 62 minutes later, turn off the Bedroom light[/li]
[li]At this point the evening sequence has finished and LogicTimer will show PM_Finished[/li][/ul]

Requires: one PLEG, one LogicTimer, one DayorNight, one VirtualSwitch, no scenes and no Lua. Try it out. :smiley:

Can you add the config info for your LogicTimer plugin for this example.

Can you add the config info for your LogicTimer plugin for this example.
It doesn't need any configuration. The only option is [b]Mode[/b] which determines whether it will restart a running timer during a Luup restart. This is enabled by default and I'm not sure why you would turn it off!

Everything LogicTimer needs it gets from PLEG actions.

I have added a few handy variables to LogicTimer. These can be accessed as PLEG Device Properties and used to adapt timing sequences according to the day, date or season.

[ul][li]DOW Contains the day of the week (1=Sunday … 7=Saturday)[/li]
[li]Day Contains the day of the month (1-31)[/li]
[li]Month Contains the month (1-12)[/li]
[li]DOY Contains the day of the year (1-366)[/li]
[li]Weekend Contains “1” on Saturday and Sunday and “0” for the rest of the week[/li]
[li]DST Contains “1” if Daylight Saving Time is in force otherwise “0”[/li][/ul]

You could include a test for Summer (in the northern hemisphere) in a condition by inserting the expression: and (DOY >= 172) and (DOY <= 265).

This is an update to the previous example to show another way of using LogicTimer to provide randomized timing. I have added a second timer (Away Radio Timer) to allow a radio to be turned on and off at randomized times when I am away from the house. Using a separate timer from the one driving the lights allows it to work differently. The lighting timing is, as before, run by Away Lights Timer.

The major difference is that, for the radio, the timer always runs the sequence whether I am at home or away. When the Away switch is changed (in my case by arming or disarming the alarm system), the radio will start or stop playing according to the current state of the time sequence. Thus it doesn’t matter what time of day I leave or return. The radio will get synchronized to the correct time sequence.

The radio timing is based on two calculated values: _AMRTime is, in seconds, 08:30 on weekdays and 09:30 at weekends. _PMRTime is 19:00 on weekdays and 18:00 at weekends. The daily time sequence starts at 07:30 when the condition _StartRadio starts the timer for the calculated _AMRTime plus a random time from 0 to 1 hour with a flag string of AMRadioOn. When the timer completes, the condition AMRadioOn fires and starts the timer for an interval of 90 minutes plus a random time of 0 to 1 hour and a flag string of AMRadioOff. The sequence continues using _PMRTime and random elements for the evening performance with the conditions PMRadioOn and PMRadioOff. So far, nothing has happened to the radio! ???

The state of the radio is controlled by the two conditions: RadioOnX and RadioOffX. These contain sequence expressions using the timestamps of AMRadioOn, AMRadioOff, PMRadioOn, PMRadioOff and also the state of the Away virtual switch. If one of the timer conditions fires, or the state of Away changes, one of these Radio…X conditions will fire and trigger the scenes that turn the radio on and off.

It works exactly as I want but you may really not care to have your radio controlled this way. ::slight_smile: I offer it as a demonstration of how you can add both calculated and randomized timing to PLEG logic.

I am looking for an easy way to give me weekday (all day) to use in PLEG. Could i use this ? I want to use a condition in PLEG which for example only runs on a Monday (or each Monday)
and i could create a condition in PLEG (monday;now;friday) which would be true from monday to friday

@mikee123

[(monday;now;friday)
Can not be done ... because there is no way to make a reference to a time in the future except using absolute times ... but that is only for the current day.

What you can do is have two times … that mark the beginning of the wekend and the beginning of the work week, called StartWeekend and StartWorkWeek

You then have the conditions:
WorkWeek StartWeekend; StartWorkWeek
Weekend StartWorkWeek; StartWeekend
or
Weekend Not WorkWeek

If you are going to use this for a lot of logic … I would have the actions toggle a virtual switch.
Then have the actual logic based on the Virtual Switch … You can then change the virtual switch when you want to simulate workweek or weekend behavior … like holidays, etc.

I would have the actions toggle a virtual switch
That sounds like a good idea. Thats probably easiest achieved by doing a schedule in Pleg, with monday 0:01 as StartWorkWeek and friday 23:59 as StartWeekend ?
Thats probably easiest achieved by doing a schedule in Pleg, with monday 0:01 as StartWorkWeek and friday 23:59 as StartWeekend ?

Yep … just change the ? to a ! in the above quote.

As i have just been promoted to sr member i probably should have had more confidence in myself and used the !.. :slight_smile:

If you create a LogicTimer device and have a PLEG Device Property set thus:

DayOfWk NameOfLogicTimer, DOW

You can add the following to your condition expressions so they only fire Monday to Friday:

  ... and (DayOfWk >= 2) and (DayOfWk <= 6) ...

You don’t have to actually use LogicTimer as a timer for this to work. Now this could be the dumbest way to eat-up your memory that I can think of… Of course, if you had another reason for installing LogicTimer you get this little trick for free. ;D

I thought i’ll have a go at logic timer…

got stuck here:

Copy the following two icon files to Vera folder /www/cmh/skins/default/icons using WinSCP or a similar tool.

I am pretty sure same cocept as copying files to an iphone. Is there a thread on here with a how to for this ?

The following instructions - with minor changes - come from a post by @winkoppp for setting up Alsteon.

Download and install the WinSCP program from WinSCP :: Official Site :: Download to your Windows computer. This program allows you to move and edit files from your computer to Vera/VeraLite. You will need your root password to be able to access Vera files. If you have a Vera2 or Vera3, it is written on the unit’s label. If you have Veralite, you can use the following procedure to discover the password:

Find root password for Veralite
Access the Tech Support settings in your VeraLite web browser. In the current firmware this is under the ACCOUNT tab. If Remote access is not enabled, click Enable to turn it on. You will see a message like this: Tech support full control enabled, access code 3000000-436969. The first number is your serial number, which is always printed on the bottom of the unit. The second number (436969) is a temporary password created for a user called remote. We will use this number with WinSCP to get our root password.

Open WinSCP, and click Session, New Session, New. Set Protocol to SCP. Enter your VeraLite IP address for the Host name, remote for the User name and the number we got above for the Password. The rest of the options just leave alone. Hit Save and then Login and you should see a new window. Click Commands, Open Terminal. Now type in the following command: nvram show | grep pass and click Execute. You’ll see a response like this: vera_wifipass=shade83forest. In this case, shade83forest, is the root password. Write it down and Log out or shut down WinSCP.

Using WinSCP
Open WinSCP, and click Session, New Session, New. Set Protocol to SCP. Enter your VeraLite IP address for the Host name, root for the User name and the name we just found under Password. The rest of the options just leave alone. Hit Save and then Login and you should see a new window.

WinSCP is a typical FTP program. The left window shows folders and files on your local windows computer and the right window shows folders and files on Vera. To copy a file, just click it and drag it to the other window.

Thanks RexBeckett, that worked. I now have logic timer and it seems to work. Now i will try and make use of the DOW in PLEG.

I have defined weekend as WE in device properties from Logic timer, so that makes my WE 0 or 1. If i want to check in PLEG for weekend, do i use weekend WE==1 or does the condition have to be weekend WE=1
I am never sure when to use == and when just a single =

To test for numerical equality, use ==, to assign a value, use =. So you want (WE == 1). PLEG is pretty tolerant, though, so you could just write: … and WE and….

at the moment i have WE==1, and at least since monday it is right, lets see the weekend if it changes state.
But you are saying i could just say ‘and WE’ , and if WE is 1, the condition would be true and false if it is 0 ?

But you are saying i could just say 'and WE' , and if WE is 1, the condition would be true and false if it is 0 ?
That is what I'm saying. PLEG is a very flexible beast.