Google Calendar Switch

This is all still very beta but maybe someone out there has use for it …

The idea:
The plugin is a simple switch (similar to a motion detector) which uses a Google Calendar as input. The plugin will check periodically if an event with a particular name is active in the calendar. If such event is currently active the plugin will go to state tripped=1, if not then tripped=0. In addition a variable is set that can be additionally specified in the event and may be used in a scene.

For example, I control my central heating that way. I specify in Google Calendar events throughout the day that are called HEATING_ON. When an event with such name is present the scene running the heating is triggered. I can also specify an event in the form of HEATING_ON{20}. In this case the 20 is extracted and stored in a variable. I use the 20 to override the temperature set-point of the heating (it now will heat to 20 degree and not use the set-point of the room thermostat). Other options would be to use events such as LIGHT_ON or ALARM_ON which could be specified in the same calendar that several instances of the plugin use.

How it works:
The plugin periodically (period defined in I_GCAl.xml in UPDATE_FREQU with 5min as a reasonable value) contacts a google calendar and requests all calendar events in a window of UPDATE_FREQU. Google Calendar returns all active events in this period as a JSON output. In that output I look for a keyword defined in the control tab of the plugin (I do not parse the JSON properly, it is just a pattern matching in the output for the keyword). If the keyword is found the plugin goes to the state Tripped.

Install:

  1. Get a Google account and setup a calendar. You may want to create a separate calendar instance for the home automation stuff.
  2. Click on calendar settings and then click on the XML button at “Private Address”. You will now see a link that vera will use as a pointer to access the calendar. Copy this link and change at the start https to http (have not figured out yet how to use https).
  3. Install the 4 attached files on vera and create a device using D_GCal.xml
  4. Click on the device you created. In the control tab there will be 2 boxes. In the first one you have to insert the link to the calendar (The box is a bit small but it works). Then press set. In the second box you enter the event name you want to use (e.g. HEATING_ON). Then press set.
  5. You can use the button “check” to see if events in the calendar are picked up. Otherwise the plugin will check every 5min (this value can be configured).

Let me know if things don’t work and I see if I can fix it.

Known issues:

  • It works in the UK but there might be problems when located in other timezones (working on it!)
  • When pressing the set button it will not blink or something. So it is hard to tell that something happens without user feedback. If someone knows how to fix this I will put it in.
  • When you press the set button it will set the variables gcalon and gcallink. You can see the content of these variables on the advanced tab at the bottom (usually after reloading the page). The boxes for setting the link and the keyword are empty even if gcalon and gcallink are set (see in the advanced tab). In other words, variables may be set but they are not shown in the set boxes. Again, who knows how to fix this?
  • Arm/Bypass button only works properly after reloading the UI 2 or 3 times.

Version Log:

  • v1: initial version
  • v2: notifications tab (for henk); larger fields to input link and keyword; changed nill to nil (Ap15e)
  • v2b: hopefully fixes the timezone problem (currently under testing)
  • v3: added a tab with the calendar to view scheduled events

code has moved to Google Calendar Plugin

GREAT!

Will test this this weekend and get you some feedback!

Thx

  • Henk

@utz,

Congratulations on getting your plugin working. It looks like a great idea.

Thanks, seems like something I could make use of, and may even provide a certain amount of control if cp.mios.com is down perhaps?

I think @guessed was once working on something similar to this with Google calender that could record and play back events?

Thanks for sharing your code. Will test the plugin when time permits.
You should replace [tt]nill[/tt] with [tt]nil[/tt].

Yes will do. It seems both works so I was never sure what to use.

+1

This could be the start of something fantastic. I’ve long thought that a calendar interface would be a huge boost for usability and functionality. Graphic interface, recurring events and it would be fairly easy to simulate random events.

Good luck with this.

It started with Playback and pseudo natural language expressions in Calendar

ie. Calendar entries with titles of the form:

[tt]Set #10 to on[/tt] OR
[tt]Set #12 to 50%[/tt] OR
[tt]Run IamHomeScene[/tt]

would fire off Switch, Dimmer, or Scene events.

…but I haven’t worked on it in over a yr as I ran into a bag of problems with the specific CalDAV calls I was making, and how “portable” they were across CalDAV servers (Yahoo, Google, and the one at work). I was trying using [CalDAV] commands that would let me download a few hours worth to Vera so it could Operate when the Network was down, and there was all sorts of non-compliance for recurring events etc.

Sounds like this one is having more luck using the JSON interfaces.

@utz,
If you’re interested in salvaging bits from it, let me know and I’ll open the [private] code.mios.com space to you so you can get stuff from it.

@guessed

Using a language is a nice idea as it makes a very flexible system. I experimented with this as well and looked at putting Lua code directly in the event description. However, my intention was to create a simple shared calendar that family members can use to have some control over the house (without the need to deal with the vera UI). So I decided to make it relatively simple. The only one that would use complex programing via the calendar would be me and I can do that stuff via vera directly.

I also had several tries before this somewhat worked. I first started with the ICAl format and wrote a parser for this. The idea was to poll a calendar once a day and then operate on the events locally (to avoid constant calendar queries). That exploded in complexity and was just not feasible (I found some of your posts where the CalDav is discussed and that seemed to be similarly complex). So now the plugin queries the calendar every few minutes which is not very efficient (in terms of network traffic). However, that way all the work is on googles side in terms of figuring out if something is scheduled or not. The solution now is ugly but simple to implement and works.

Some things I came across and was wondering if anyone has an answer: Obviously, vera uses JSON and XML and there must be a parser for it on the system. Is there a way to use these parsers from Lua. It seems to me a bit silly to install a JSON parser for Lua while there must be one on the system already.

It looks like lxp (http://matthewwild.co.uk/projects/luaexpat/lom.html) is installed. Amazingly, there isn’t a JSON parser library on my Vera.

utz,

You’re right, it doesn’t matter whether you’re using nill or nil - as long as you don’t inizialize the variable nill … :slight_smile:

@utz

Whats not working with the https? Vera is unable to build the SSL connection?
What kind of error messages are you getting.

Just asking so i wont run into any unexpected thng when im going to try this out and i can report back with usuable feedback.

  • Henk

[quote=“utz, post:1, topic:169003”]Install:

  1. Get a Google account and setup a calendar. You may want to create a separate calendar instance for the home automation stuff.
  2. Click on calendar settings and then click on the XML button at “Private Address”. You will now see a link that vera will use as a pointer to access the calendar. Copy this link and change at the start https to http (have not figured out yet how to use https).
  3. Install the 4 attached files on vera and create a device using D_GCal.xml
  4. Click on the device you created. In the control tab there will be 2 boxes. In the first one you have to insert the link to the calendar (The box is a bit small but it works). Then press set. In the second box you enter the event name you want to use (e.g. HEATING_ON). Then press set.
  5. You can use the button “check” to see if events in the calendar are picked up. Otherwise the plugin will check every 5min (this value can be configured).[/quote]

Henk,

I just could not see in the documentation if luup.inet.wget can do https (only mentions http) or not so I never tried. Maybe it just works.

@utz,

We have seen that Vera does not support ssl nativly.
Here: http://forum.mios.com/index.php?topic=6665.0
And here: http://forum.mios.com/index.php?topic=6727.0

So im assuming you are right. I will try anyway and let you know the results!

  • Henk

[quote=“utz, post:13, topic:169003”]Henk,

I just could not see in the documentation if luup.inet.wget can do https (only mentions http) or not so I never tried. Maybe it just works.[/quote]

It does, you use LuaSec to initiate https calls and it’s preinstalled. Will likely be faster/better than using wget since it won’t launch processes and create all those temp files.

Ie. Less work for the little box.

It’s SSL/TLS (for SMTP) that it has difficulty with, since the smtp drivers weren’t modular enough to hook LuaSec into.

@guessed

Thx for the clarification! I was not aware of that. Sounds like a good alterntive then as well as more secure!

  • Henk

[quote=“guessed, post:15, topic:169003”]It does, you use LuaSec to initiate https calls and it’s preinstalled. Will likely be faster/better than using wget since it won’t launch processes and create all those temp files.

Ie. Less work for the little box.

It’s SSL/TLS (for SMTP) that it has difficulty with, since the smtp drivers weren’t modular enough to hook LuaSec into.[/quote]

[quote=“utz, post:1, topic:169003”]4) Click on the device you created. In the control tab there will be 2 boxes. In the first one you have to insert the link to the calendar (The box is a bit small but it works). Then press set. In the second box you enter the event name you want to use (e.g. HEATING_ON). Then press set.[/quote]After entering the Calendar Link and clicking set & then the Calendar Keyword and pressing set.

Should the information continue to display in these boxes after closing the device page?

Going back to the boxes, they are empty.

JOD.

@JOD,

What happens if you change one (1) box only and save?

  • Henk

[quote=“JOD, post:17, topic:169003”][quote=“utz, post:1, topic:169003”]4) Click on the device you created. In the control tab there will be 2 boxes. In the first one you have to insert the link to the calendar (The box is a bit small but it works). Then press set. In the second box you enter the event name you want to use (e.g. HEATING_ON). Then press set.[/quote]After entering the Calendar Link and clicking set & then the Calendar Keyword and pressing set.

Should the information continue to display in these boxes after closing the device page?

Going back to the boxes, they are empty.

JOD.[/quote]

[quote=“Henk, post:18, topic:169003”]What happens if you change one (1) box only and save?[/quote]After setting either or both boxes, neither box has content after leaving the “Control” page.
Does yours stay?

JOD.

@JOD & @utz

Correct, in 1338 (the version im using) im seeing the same.
I cannot enter and save the box’s contents.

Not 1, not the other and not both. It seems the “set” box is not clickable although the “hand” shows its linked.

Anyone else got it up and running follwing the installsteps here?
http://forum.mios.com/index.php?topic=7558.msg48518#msg48518

Ive tried it with http and with https, both no go…

  • Henk

[quote=“JOD, post:19, topic:169003”][quote=“Henk, post:18, topic:169003”]What happens if you change one (1) box only and save?[/quote]After setting either or both boxes, neither box has content after leaving the “Control” page.
Does yours stay?

JOD.[/quote]