| ECS-L Home Automation and Security Archives |
| Subject: From: Date: | Event to read reminders from a text file Martin Terry Sun, 14 Nov 1999 12:04:43 -0800 |
OK, Here's the events I use to read reminders from a text file and send them to my pager. I have similar events to announce certain reminders, and a similar event for all announcement messages save a dozen or so. I found that this was an easy way to cut down the number of text items I had to define for ECS. Basically the reminder processing works like this. 1. A folder on the D drive called "remind" 2. Inside the folder are files like "daily.txt" and files for a specific day named after the day. For example if I have an appointment on 11/19/99 then there will be a file called d:\remind\111999 (no extension) 3. The contents of each file type looks like this: Time:RemindDaily1 10:00am| Doctor's Appointment at 10:30 | Time:RemindDaily2 4:30pm| Time for school| Each file can have up to 3 reminders at different times. The "daily" reminders are sent each day at the times specified, the files named after a specific date are sent on that date then deleted. The reminders are updated each day at 2am. There are 3 events related to this processing: Called:GetChar Reads the actual contents of the external files Set Reminders Sets up reminders at 2am each morning by defining times and text Send Reminders Sends the reminders at the given times I'm too lazy to cut and paste all the item definitions related to these events, but I think most of them are self explainatory. If not, let me know and I'll post them as well. Here's the Set Reminders event. It reads the d:\remind\daily.txt and defines up to 3 times and messages that will be sent to my pager. It would be easy enough to expand on the number of messages, but I never use up to 3. It would also be easy enough to modify this for weekdays/weekends, etc. The real magic of this event is the Set State command which lets you redefine an item's state based on some external criteria. It also calculates a filename based on today's date and winds up with something like d:\remind\111499. Notice there's no extension on this file. If this file exists, it reads the reminder entries in this as well, up to 3 reminders. |Event: Set Reminders Called ?:No | ;Used to Setup daily reminders | ;Martin Terry 8/3/99 | | ;Set the execution flag if 2am or starting | | If Time:CurrentTime Is Now Time:CalcRemind | Or Sys:StartStopStat Is Starting | Then Sys:EventLine Set LABEL1 | Do Sys:EventExit Set True | | LABEL1: | ;Clear all variables | | Do File:Scratch T1<-T1 File:RemindDaily | Do File:Scratch Set Rewind | Do Flg:ScratchA Set False | Do Time:RemindDaily1 Set None | Do Time:RemindDaily2 Set None | Do Time:RemindDaily3 Set None | Do Time:RemindSpec1 Set None | Do Time:RemindSpec2 Set None | Do Time:RemindSpec3 Set None | | | ;Get the first daily reminder time | Do Sys:EventCall Set Called:GetChar | Do Msg:ScratchA Set Set State | ;Get the first daily reminder message | Do Sys:EventCall Set Called:GetChar | Do Msg:RemindDaily1 T1<-T1 Msg:ScratchA | | ;Get the second daily reminder time | Do Sys:EventCall Set Called:GetChar | Do Msg:ScratchA Set Set State | ;Get the first second reminder message | Do Sys:EventCall Set Called:GetChar | Do Msg:RemindDaily2 T1<-T1 Msg:ScratchA | | ;Get the third daily reminder time | Do Sys:EventCall Set Called:GetChar | Do Msg:ScratchA Set Set State | ;Get the first third reminder message | Do Sys:EventCall Set Called:GetChar | Do Msg:RemindDaily3 T1<-T1 Msg:ScratchA | | | ;Calculate path to today's special file | Do Msg:ScratchA T1<-T1 Str:PathRemind | Do Num:ScratchA Set Date:CurrentMonth | If Date:CurrentMonth Is LE September | Then Msg:ScratchA Set 0 | Do Msg:ScratchA T1/A<-Stt Num:ScratchA | If Date:ThisCalDate Is LE 9 | Then Msg:ScratchA Set 0 | Do Msg:ScratchA T1/A<-Stt Date:ThisCalDate | Do File:Scratch T1<-T1 Msg:ScratchA | | ;Calculate Todays Special 1 | Do Sys:EventCall Set Called:GetChar | Do Msg:ScratchA Set Set State | Do Sys:EventCall Set Called:GetChar | Do Msg:RemindSpec1 T1<-T1 Msg:ScratchA | | ;Calculate Todays Special 2 | Do Sys:EventCall Set Called:GetChar | Do Msg:ScratchA Set Set State | Do Sys:EventCall Set Called:GetChar | Do Msg:RemindSpec2 T1<-T1 Msg:ScratchA | | ;Calculate Todays Special 3 | Do Sys:EventCall Set Called:GetChar | Do Msg:ScratchA Set Set State | Do Sys:EventCall Set Called:GetChar | Do Msg:RemindSpec3 T1<-T1 Msg:ScratchA | | ;Delete the special file for today | Do File:Scratch Set Delete | End Here's the Called:GetChar event. This event is used a lot in my configuration to read a text file and place it's contents into a text item. Why not use the @file method to redirect ECS to the contents? Well, it doesn't work as advertised. It works fine for speaking the contents of a text file for example, but if you try the Log command you will get @file written to the log. Oh well. I find my event more flexible anyway. Basically you copy the full path of the file that contains the text to File:ScratchA then call Called:GetChar. When it exits Msg:ScratchA will contain the text of the file. I use the "|" character to signify the end of the entry, so the event will exit at that point but it's not necessary if it's the EOF. If you have multiple lines in the file, like I do in the reminders event, each call to the event will place one line into the scratch text item. I make 2 calls, one to get the time, one to get the message. |Event: Called:GetChar Called ?:Yes | ;Get characters from a text file | ;Martin Terry - 7/26/99 | ;Copy the filename to File:ScratchA with T1<-T1 | ;When this event exits Msg:ScratchA will | ;contain the text and Flg:ScratchA will be true | ;if the end of file was reached | Do Flg:Loop Set True | Do Num:GetChar Set 0 | Do Msg:ScratchA T1<-T1 Msg:Blank | | WHILE Flg:Loop Is True | Do Num:GetChar Set File:Scratch | If Num:GetChar Is Not 10 | And Num:GetChar Is Not 13 | And Num:GetChar Is Not 124 | And Num:GetChar Is Not 256 | Then Msg:ScratchA Set Num:GetChar | If Num:GetChar Is 124 | Then Flg:Loop Set False | If Num:GetChar Is 256 | Then Flg:ScratchA Set True | Then Flg:Loop Set False | ENDWHILE | | End Here's the send reminder event. Nothing special here, just waits for the defined reminder time. I use an external program to send my pages because ECS couldn't multitask sending pages, but since I wrote this Mark has changed that. I didn't include the event that actually sends the page since it's calling a third party program, but it would be easy to just do a Send->Pager where I am setting the timer below. You could also just speak the reminder at this point. |Event: Send Reminders Called ?:No | ;Send Reminders at the proper time | ;8/5/99 Martin Terry | | If Time:CurrentTime Is Now Time:RemindDaily1 | Then Msg:Pager Set <Space> | Then Msg:Pager T1/A<-T1 Msg:RemindDaily1 | Then Tmr:SendPage Set 1 | | If Time:CurrentTime Is Now Time:RemindDaily2 | Then Msg:Pager Set <Space> | Then Msg:Pager T1/A<-T1 Msg:RemindDaily2 | Then Tmr:SendPage Set 1 | | If Time:CurrentTime Is Now Time:RemindDaily3 | Then Msg:Pager Set <Space> | Then Msg:Pager T1/A<-T1 Msg:RemindDaily3 | Then Tmr:SendPage Set 1 | | If Time:CurrentTime Is Now Time:RemindSpec1 | Then Msg:Pager Set <Space> | Then Msg:Pager T1/A<-T1 Msg:RemindSpec1 | Then Tmr:SendPage Set 1 | | If Time:CurrentTime Is Now Time:RemindSpec2 | Then Msg:Pager Set <Space> | Then Msg:Pager T1/A<-T1 Msg:RemindSpec2 | Then Tmr:SendPage Set 1 | | If Time:CurrentTime Is Now Time:RemindSpec3 | Then Msg:Pager Set <Space> | Then Msg:Pager T1/A<-T1 Msg:RemindSpec3 | Then Tmr:SendPage Set 1 | End Hope this is helpful to folks. Any questions please ask.