OpenSprinkler Forums Hardware Questions OpenSprinkler Pi (OSPi) Google Calendar code – my plan and a request Re: Re: Google Calendar code – my plan and a request

#23575

danico
Blocked

Jon,
I went and wrote two programs, one to harvest the event info for the next seven days from Google Calendar and save to a XML file, the other to use that XML file to run the events. Will be good to compare your method to gather the events, I’m sure it is more elegant!
Also expanded the idea, so not just sprinklers (or Reticulation as we call it here), but to also include garden lights and maybe house lights when on holidays. Can be expanded further to include blinds and windows or whatever we need done on a periodic basis.
None of this is original work, it is all taken from others, and just tweaked, massaged and stretched a bit…
Works like this – the calendar and access is set up as per Ray’s instruction, it is a specific calendar used just for house tasking. On this calendar, we create our events, anything to do with sprinklers, the event starts with ‘Retic’, so to water my Citrus trees, the event title is ‘Retic:Citrus’, then we put in the start and stop time. For the garden lights the events are ‘Lights:Letterbox’ etc.,
I think the code is quite readbleto where you can add or remove these event types, and how to change the prefix wording.
So once every 15 minutes, GetCal reads the Calendar for the next seven days. If any of the events are newer or changed since the last read of the calendar, then the file is updated, else it is ignored. Also if the stored file is older than 24 hours, it will force a re-write of the event file.
At the moment the events are written to the current directory, eventually they will be written to my NAS, just not got there yet.
So that is all this does, over and over. Will likely be put on to my DNSPi – an extra job for it to be doing….

So now the other side of things.
SprinklerPi gets hold of the saved ‘CalRetic.txt’ file and pulls out the relevant zone data. I was planning on writing an elegant program that ordered the events, put all the of the starts and stop in sequence, set various clock alarms to take care of the event, but that just got too difficult. Looking at how Ray had already done the calendar program, it was just the most straight forward way to go. So in a very similar method as that program, every say 15 seconds we look to see if any events are currently in play, if they are then the zones are set. It is really just Rays original program, but data from a file instead of from Calendar.
It does check to see if the file has been updated, and if so re-reads the data, else it just runs on checking and setting zones.
When it came to the Master valve, this is set in the software (as I have one), or it could be a calendar event that encompasses all of the sprinkler events.

LightPi is very similar, it will sit in a box outside, but instead of an OpenSprinklerPi attached, it just has a SainSmart relay board, basically the same code but using the ‘Light’ XML data file.
In both of these programs, the tricky part is keeping track of how the time is being stored. The Atom feed from Google is in rfc3339 format, we want to save to file in a nice readable string, but to do comparisons and deltas, we need to be in datetime format. Can get very confusing, but I think it is right in the end.
Both programs are not yet complete, but are operational, and still contain many prints of current status as part of the debug process. These will be removed soon, and then the programs will run as a service.

This is my first outing in Python, so I’m sure that there is much better and elegant ways of doing things, and really the hard work was initially done by Devon and Ray, but just wanted to get these out there as they may assist others in their home reticulation designs!