We have moved at community.getvera.com

Author Topic: Google Calendar Switch  (Read 143592 times)

Offline utz

  • Sr. Member
  • ****
  • Posts: 274
  • Karma: +0/-0
Google Calendar Switch
« on: August 24, 2011, 06:06:01 pm »
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 http://code.mios.com/trac/mios_google-calendar-plugin/
« Last Edit: February 14, 2012, 05:55:42 pm by utz »

Offline Henk

  • Hero Member
  • *****
  • Posts: 820
  • Karma: +3/-0
Re: Google Calendar Switch
« Reply #1 on: August 24, 2011, 06:22:24 pm »
GREAT!

Will test this this weekend and get you some feedback!

Thx

- Henk
| Vera2 @ UI4 1.1.1350 / 3.20 | Vera Lite @ UI5 | Vera 3 @ UI5 | 2x Merten  504519 | 1x Duewi  064374 | 1x Everspring SM103 doorbell mod |1 Y-cam IP cam | various LUUP plugins |

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3260
  • Karma: +192/-9
Re: Google Calendar Switch
« Reply #2 on: August 24, 2011, 06:24:13 pm »
@utz,

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

Offline strangely

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3722
  • Karma: +34/-2
  • Vera 1,3 & V light
Re: Google Calendar Switch
« Reply #3 on: August 24, 2011, 07:01:18 pm »
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?

Kwickset locks, HA01C, HA14C, HA02C, HA03C, HA05C, HA04C, HA07C, HA09C, Aeon HEM, GE 45604, 45606, 45609, ZDP100, VRF01-1LZ, WDTC-20, HA18WD, WDHA-12R, HRDS1, HM-TS001, AC1-ZW, TV-IP110, BL-C210A, LUUP control- EtherRain8, DSC Alarm, HDMI matrix, HR24-200, Panasonic TV, SQblaster

Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
Re: Google Calendar Switch
« Reply #4 on: August 24, 2011, 07:07:10 pm »
Thanks for sharing your code. Will test the plugin when time permits.
You should replace nill with nil.

Offline utz

  • Sr. Member
  • ****
  • Posts: 274
  • Karma: +0/-0
Re: Google Calendar Switch
« Reply #5 on: August 24, 2011, 07:16:30 pm »
You should replace nill with nil.

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

Offline DaveL17

  • Full Member
  • ***
  • Posts: 186
  • Karma: +0/-2
Re: Google Calendar Switch
« Reply #6 on: August 24, 2011, 09:40:29 pm »
+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.

Offline guessed

  • Community Beta
  • Master Member
  • ******
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Google Calendar Switch
« Reply #7 on: August 25, 2011, 01:50:52 am »
I think @guessed was once working on something similar to this with Google calender that could record and play back events?
It started with Playback and pseudo natural language expressions in Calendar

ie. Calendar entries with titles of the form:

Set #10 to on    OR
Set #12 to 50%    OR
Run IamHomeScene

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.

Offline utz

  • Sr. Member
  • ****
  • Posts: 274
  • Karma: +0/-0
Re: Google Calendar Switch
« Reply #8 on: August 25, 2011, 03:03:02 am »
@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.

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3260
  • Karma: +192/-9
Re: Google Calendar Switch
« Reply #9 on: August 25, 2011, 05:50:04 am »
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.

Offline Ap15e

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1998
  • Karma: +12/-0
Re: Google Calendar Switch
« Reply #10 on: August 25, 2011, 06:06:31 am »
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 ...  :)

Offline Henk

  • Hero Member
  • *****
  • Posts: 820
  • Karma: +3/-0
Re: Google Calendar Switch
« Reply #11 on: August 25, 2011, 07:14:15 am »
@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

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).
| Vera2 @ UI4 1.1.1350 / 3.20 | Vera Lite @ UI5 | Vera 3 @ UI5 | 2x Merten  504519 | 1x Duewi  064374 | 1x Everspring SM103 doorbell mod |1 Y-cam IP cam | various LUUP plugins |

Offline utz

  • Sr. Member
  • ****
  • Posts: 274
  • Karma: +0/-0
Re: Google Calendar Switch
« Reply #12 on: August 25, 2011, 07:18:44 am »
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.

Offline Henk

  • Hero Member
  • *****
  • Posts: 820
  • Karma: +3/-0
Re: Google Calendar Switch
« Reply #13 on: August 25, 2011, 07:25:12 am »
@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
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.
| Vera2 @ UI4 1.1.1350 / 3.20 | Vera Lite @ UI5 | Vera 3 @ UI5 | 2x Merten  504519 | 1x Duewi  064374 | 1x Everspring SM103 doorbell mod |1 Y-cam IP cam | various LUUP plugins |

Offline guessed

  • Community Beta
  • Master Member
  • ******
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Google Calendar Switch
« Reply #14 on: August 25, 2011, 09:47:15 am »
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.