We have moved at community.getvera.com

Author Topic: Google Calendar Switch  (Read 136821 times)

Offline sjolshagen

  • Sr. Member
  • ****
  • Posts: 416
  • Karma: +5/-0
Re: Google Calendar Switch
« Reply #120 on: April 14, 2012, 06:58:53 pm »
I wound up biting  the bullet and upgrading to UI5 today and with that comes a couple of caveats. For starters, the GCAL event didn't seem to make the upgrade so I had to go into the "Apps" menu and install the plugin on top of the old one.

That, of course, meant that my patch (see above) disappeared and I had to reapply it. That, in turn, made me realize my "debug()" logging routine is a little busted so I another function got added to my local I_GCAL.xml file. Not sure if anybody but utz has privileges to update plugin in the Marketplace, but regardless I've attached my patched I_GCAL.xml file to this post.

Obviously, all the "normal" disclaimers apply: YMMW, Worked on my Vera 2, can't promise it'll work on yours, etc, etc...
Vera3/UI5 @ v1.5.622

Offline minxster

  • Newbie
  • *
  • Posts: 12
  • Karma: +1/-0
Re: Google Calendar Switch
« Reply #121 on: April 24, 2012, 11:38:32 am »
Hi all,

I'm a newbie to all of this, including Vera/MIOS. But thanks already for this great plugin. I've got it all up and running with my Thermostat  ;D

Quick question though - do Recurring Events work? I have a large number of these setup for my heating schedule, though they all worked yesterday, they don't seem to work today?

Minxster

Offline minxster

  • Newbie
  • *
  • Posts: 12
  • Karma: +1/-0
Re: Google Calendar Switch
« Reply #122 on: May 08, 2012, 07:39:35 pm »
Hi all,

I did figure out that repeat calendar events do indeed work perfectly fine. Though I have been pretty confused over the whole time of events firing off.

I did have problems with events firing off nearly an hour early which caused me a few problem. So I've finally took a little time to go through the I_GCal.xml file to see what's going on.
*
I'm not fully clued up on the programming luup but think ta = os.date('*t', t) should be ta = os.date('!*t', t)?? When left to the original code, the start-max seems to be nearly an hour ahead of the start-min. With the code change, the start-max is 5 mins (UPDATE_FREQU*60) ahead as it should be. This seems to have stopped events form firing up too early.

sjolshagen: I've noticed that your patched xml file (above) already has this change in place  ;D
« Last Edit: May 08, 2012, 07:44:26 pm by minxster »

Offline tom3dline

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: Google Calendar Switch
« Reply #123 on: May 16, 2012, 03:17:20 pm »
can someone please guide me how get it work? I download and created device no problems.
I can see the device green man and I can't seem get it to work. please tell me how to make scene sync with google calendar. for an example I want to pass HEATING_ON{20} onto a scene to turn on my thermostat at home. Thank you very much and I'm my English very limited.

Offline psykokwak

  • Jr. Member
  • **
  • Posts: 77
  • Karma: +0/-0
Re: Google Calendar Switch
« Reply #124 on: May 20, 2012, 06:28:10 am »
Hi all,

I'm a new vera user and I discovered this awesome google cal plugin.
I've made some improvements according to my needs.

- If my event is longer than UPDATE_FREQU minutes, device event "trigger" is launch every UPDATE_FREQU. So here a patch that fix that issue :
Code: [Select]
--- I_GCal.xml
+++ I_GCal.xml.new
@@ -54,10 +54,16 @@
                               debug("GCAL: no value attached")
                               luup.variable_set(GCAL_SID, "gcalval", "", lul_device)
                        end
-                       luup.variable_set(SECURITY_SID, "Tripped", 1, lul_device)
+                              local prevtripped = luup.variable_get(SECURITY_SID, "Tripped", lul_device)
+                              if (tonumber(prevtripped) == 0) then
+                                      luup.variable_set(SECURITY_SID, "Tripped", 1, lul_device)
+                              end
                else
                        debug("GCAL: no event with name " .. gcalon .. " is currently active")
-                       luup.variable_set(SECURITY_SID, "Tripped", 0, lul_device)
+                      local prevtripped = luup.variable_get(SECURITY_SID, "Tripped", lul_device)
+                      if (tonumber(prevtripped) == 1) then
+                              luup.variable_set(SECURITY_SID, "Tripped", 0, lul_device)
+                      end
                end
             end
        end

- I'm working on an other fix that trigger the device exactly when the calendar event starts and not if it starts between "now" and "UPDATE_FREQU".

Offline garrettwp

  • Master Member
  • *******
  • Posts: 6371
  • Karma: +227/-128
  • Vera 3, Lite, ISY994
Re: Google Calendar Switch
« Reply #125 on: May 20, 2012, 07:07:42 am »
psykokwak,

Welcome! Thank you for providing your patch and providing to the community. Looking forward to seeing what you come up with next.

- Garrett

Offline psykokwak

  • Jr. Member
  • **
  • Posts: 77
  • Karma: +0/-0
Re: Google Calendar Switch
« Reply #126 on: May 20, 2012, 10:18:37 am »
In France (daylight time), I have an error on start-max hour value. I Fixed it (and remove the useless get_timezone() function).
Hop will definitively fix the daylight issue.

Here my patch :
Code: [Select]
--- I_GCal.xml.def
+++ I_GCal.xml
@@ -3,7 +3,7 @@
   <functions>
       local GCAL_VERSION      = "V 0.10"
       local LOG_DEBUG         = true
-      local UPDATE_FREQU      = 5
+      local UPDATE_FREQU      = 2
       local GCAL_SID          = "urn:utz-com:serviceId:GCal1"
       local SECURITY_SID      = "urn:micasaverde-com:serviceId:SecuritySensor1"

@@ -27,15 +27,12 @@
        if ((gcallink~=nil) and (gcalon~=nil)) then
             debug("GCAL: checking google calendar")
             local url = gcallink .. "?alt=json&amp;fields=entry/title"
-            local t = os.time(t)
-            t = t - get_timezone()
-            local ta = os.date('!*t')
-            ta.isdst=true
+            local now = os.time()
+            local ta = os.date("!*t", now)
             local s = string.format("%d-%02d-%02dT%02d:%02d:%02d", ta.year, ta.month, ta.day, ta.hour, ta.min, ta.sec)
             debug("GCAL: start-min: " .. s)
             url = url .. "&amp;start-min=" .. s
-            t = t+(UPDATE_FREQU*60)
-            ta = os.date('*t', t)
+                ta = os.date("!*t", now + (UPDATE_FREQU * 60))
             s = string.format("%d-%02d-%02dT%02d:%02d:%02d", ta.year, ta.month, ta.day, ta.hour, ta.min, ta.sec)
             debug("GCAL: start-max: " .. s)
             url = url .. "&amp;start-max=" .. s
@@ -54,10 +51,16 @@
                               debug("GCAL: no value attached")
                               luup.variable_set(GCAL_SID, "gcalval", "", lul_device)
                        end
-                       luup.variable_set(SECURITY_SID, "Tripped", 1, lul_device)
+                              local prevtripped = luup.variable_get(SECURITY_SID, "Tripped", lul_device)
+                              if (tonumber(prevtripped) == 0) then
+                               luup.variable_set(SECURITY_SID, "Tripped", 1, lul_device)
+                              end
                else
                        debug("GCAL: no event with name " .. gcalon .. " is currently active")
-                       luup.variable_set(SECURITY_SID, "Tripped", 0, lul_device)
+                       local prevtripped = luup.variable_get(SECURITY_SID, "Tripped", lul_device)
+                       if (tonumber(prevtripped) == 1) then
+                              luup.variable_set(SECURITY_SID, "Tripped", 0, lul_device)
+                       end
                end
             end
        end
« Last Edit: May 20, 2012, 10:20:37 am by psykokwak »

Offline therealabdo

  • Sr. Member
  • ****
  • Posts: 339
  • Karma: +1/-0
Re: Google Calendar Switch
« Reply #127 on: May 22, 2012, 05:04:24 am »
hello all

I have installed everything and done eveyrthing
but when i set the link and the keyword nothing appears in the advanced tap. Actually i coundnt find the galink and gacon fields
in the advanced tap there is such a galink field to be filled

Offline psykokwak

  • Jr. Member
  • **
  • Posts: 77
  • Karma: +0/-0
Re: Google Calendar Switch
« Reply #128 on: May 23, 2012, 11:13:15 am »
I almost finish to entirely rewrite the Lua program of this plugin. I improved the polling system. Now we can set the UPDATE_FREQ at 1 hour (default value) or more and each event will be tripped exactly at the scheduled time (0.1 second resolution). It work with daily events and (I hope) with every timezone. I add a small improvement into the gcallink parsing value. You can copy/past the private link directly from google calendar without change "https" to "http".
However this "new" plugin needs a new lua module which is not present into the firmware. This is a lua json parser.

So, before releasing this update (on the Mios Market ?) I have some packaging questions.
- How to integrate this lua module into the plugin ? Actually I copy the module file in /usr/lib/lua directory.
- Is the original author of this plugin is agree with my modifications and accepts to put them into the Mios Market ?

Offline sjolshagen

  • Sr. Member
  • ****
  • Posts: 416
  • Karma: +5/-0
Re: Google Calendar Switch
« Reply #129 on: May 23, 2012, 11:32:58 am »
 
Quote
How to integrate this lua module into the plugin ? Actually I copy the module file in /usr/lib/lua directory.

I'm (obviously) not the original author, so it's pretty much up to him/MCV on how to distribute this.

However, I do have some feedback... I believe that having a library/module that's not part of the base distribution is a bit of a non-starter from a use perspective (and, possibly, also from a support perspective). Who owns fixing issues in this 3rd party parser and ensuring it doesn't have unintended interactions with the parser that I assume exists in the luup engine itself. I assume this because of the extensive use of JSON for the UI?. Also, another lua module/library will consume something I, personally, have precious little of as it is on my Vera2/UI4 combination; Memory.

I wonder how you'd deal with upgrades of the FW. Would that not mean the library would need to be re-installed?

Your plan to deploy this in the Mios Market suggests (perhaps incorrectly?) that your implementation is UI5 specific. Is that the case? If so, you're alienating a big part of the base which is Vera1/Vera2 and many of us have real problems with UI5 due to its increased resource consumption - which also brings it back to the 2nd "objection" I have to an implementation that leverages a 3rd party library which isn't distributed with the UI.
Vera3/UI5 @ v1.5.622

Offline psykokwak

  • Jr. Member
  • **
  • Posts: 77
  • Karma: +0/-0
Re: Google Calendar Switch
« Reply #130 on: May 23, 2012, 11:51:12 am »
Thanks for your answer.
There is actually no JSON library for LUA. It seems it's planned for the next update (http://forum.micasaverde.com/index.php/topic,10521.msg72854.html#msg72854). As the only two functions in the module have the same name and the same behaviour, moving the plugin to this library will be very easy.
I dont know if my plugin code is IU4 compliant. I'm pretty new in the Mios world and I use a vera light. This version can significantly reduce the number of requests to the google server and the program spends more time in sleep state. So I think it a good thing.

I think I will provide my code here. Any one who want could try and we will see if MVC staff want to add the plugin.
« Last Edit: May 24, 2012, 03:53:42 am by psykokwak »

Offline psykokwak

  • Jr. Member
  • **
  • Posts: 77
  • Karma: +0/-0
Re: Google Calendar Switch
« Reply #131 on: May 25, 2012, 08:17:52 am »
Ok, here my Google calendar swich plugin.

Changelog :
- Work with private and public calendar (like public holiday...)
- Trigger on a specific event name (eventually followed by a "{xxx} tag" or any event (leave the field empty)
- No need to poll more than once per day.
- Raises the event to the exact second at which it begins. Same for the end of the event.

In the zip file, there is a "json.lua" file that you have to put in your "/usr/lib/lua" directory before using the module.
If you already have the plugin installed, replace them (in "/etc/cmh-ludl")

Hope there is no bug. It's my first LUA program :)


Offline psykokwak

  • Jr. Member
  • **
  • Posts: 77
  • Karma: +0/-0
Re: Google Calendar Switch
« Reply #132 on: May 26, 2012, 07:19:21 pm »
Hop. New release "1.2.1" with some minor graphical improvements.

Offline psykokwak

  • Jr. Member
  • **
  • Posts: 77
  • Karma: +0/-0
Re: Google Calendar Switch
« Reply #133 on: May 28, 2012, 08:18:24 am »
New version again : 1.2.2
Changelog :
- Fix an issue with empty keyword
- Device was not triggered when we "check" when an event has already started

Offline fatal25

  • Jr. Member
  • **
  • Posts: 88
  • Karma: +0/-0
Re: Google Calendar Switch
« Reply #134 on: May 28, 2012, 01:07:28 pm »
Hi psykokwak,

thank you for your job but I've a error with Gcal device...

Code: [Select]
Ramassage Carton[39] : Startup Lua Failed
39 is my device number.

I don't understand this problem.


URL is a private adress like... https://... basic.ics

Keyword is Carton