We have moved at community.getvera.com

Author Topic: GCAL3 - General Discussion  (Read 180437 times)

Offline Stuart

  • Moderator
  • Hero Member
  • *****
  • Posts: 728
  • Karma: +71/-2
Re: GCAL3 - Version 2.0
« Reply #480 on: April 08, 2016, 04:18:28 pm »
@Nettuno

In a PM to me you asked

Quote
Hello Stuart, forgive me, I would like a clarification.
I have 2 Device for 2 Calendars (that work :D) and I have your code to talk VeraAlerts events of tomorrow, so I would like to know whether the code should be repeated 2 times or must be rewritten?

At this stage in your relationship with Vera - you need to start playing with Lua code (and in the process, understanding how Vera works) - simple things are easy and fun ...
To get you on your way -- here is one way of make it do what you are asking.

Code: [Select]
function futureEvents(GCal_number,VeraAlerts_number,Profile,Msg)
  local GCAL_SID = "urn:srs-com:serviceId:GCalIII"
  Msg = Msg or "" -- makes sure it is not a nil
  Msg  = Msg .. "\n" -- puts this on a new line
 
  -- find out when tomorrow starts
  local nextday = os.time() + (3600*24)
  local ta = os.date("*t", nextday)
  local tomorrow = string.format("%d-%02d-%02d", ta.year, ta.month, ta.day)
 
  -- get the contents of gc_jsonEvents
  local jsonEvents = luup.variable_get(GCAL_SID, "gc_jsonEvents",GCal_number)
  if (jsonEvents == "[]") then -- equivalent of a nul
    return
  end

  -- read the events in gc_jsonEvents into an array
  local json = require("dkjson") -- depending on your vera version you may need to use require("json")
  local eventList =json.decode(jsonEvents)
  package.loaded.json = nil

  local numberEvents = #eventList
  local startevent, startDate, eventname, startTime, endTime
 
  -- now process the array one entry at a time
  for i = 1,numberEvents do
    startevent = eventList[i].eventStart -- the start time for this event
    startDate = os.date("%Y-%m-%d", startevent)
   if startDate == tomorrow then
    startTime = os.date("%H:%M:%S", startevent)
    endTime = os.date("%H:%M:%S", eventList[i].eventEnd)
    eventname = eventList[i].eventName
    Msg  = Msg .. "\n" .. "Event " .. eventname .. " will start at " .. startTime .. " and end at " .. endTime
    end
  end
  luup.call_action("urn:richardgreen:serviceId:VeraAlert1", "SendAlert",
                  {Message = Msg, Recipients = Profile}, VeraAlerts_number)
  return
end


local VeraAlerts_num = 47 -- change this to be the Vera Alert plugin number

local GCal_num = 42 -- change this to be the GCal plugin number for your Events
local VA_profile = "VeraAlerts" -- this will be the name of the VeraAlerts profile for you
local Message = "alerts for me" -- this will be the first line of the message sent to you
futureEvents(GCal_num,VeraAlerts_num,VA_profile,Message)

GCal_num = 42 -- change this to be the GCal plugin number for your wife's Events
VA_profile = "VeraAlerts" -- change this will be the name of the VeraAlerts profile for your wife
Message = "Per la mia bella moglie" -- you may not want to change this
futureEvents(GCal_num,VeraAlerts_num,VA_profile,Message)

Take a look at the code for the main function and you will see the differences are small.

Offline Nettuno

  • Sr. Newbie
  • *
  • Posts: 27
  • Karma: +4/-0
Re: GCAL3 - Version 2.0
« Reply #481 on: April 09, 2016, 08:23:14 am »
Quote
At this stage in your relationship with Vera - you need to start playing with Lua code (and in the process, understanding how Vera works) - simple things are easy and fun ...
To get you on your way -- here is one way of make it do what you are asking.
good but, due to problem VeraAlerts, code launches 2 messages at a distance of about 25 seconds and it does seem strange or, it seems that there is not another..

He should be saying:
Tomorrow appointments are, xxx, yyy, zzz etc ..

Ie those of calendars together
You think you cure my craze?  ;D ;D ;D

Offline Stuart

  • Moderator
  • Hero Member
  • *****
  • Posts: 728
  • Karma: +71/-2
Re: GCAL3 - Version 2.0
« Reply #482 on: April 09, 2016, 06:41:20 pm »
Quote
At this stage in your relationship with Vera - you need to start playing with Lua code (and in the process, understanding how Vera works) - simple things are easy and fun ...
To get you on your way -- here is one way of make it do what you are asking.
good but, due to problem VeraAlerts, code launches 2 messages at a distance of about 25 seconds and it does seem strange or, it seems that there is not another..

He should be saying:
Tomorrow appointments are, xxx, yyy, zzz etc ..

Ie those of calendars together
You think you cure my craze?  ;D ;D ;D

The function futureEvents is being called twice and the call to VeraAlerts is inside that function - That's why you get two Alerts sent.

You will need to modify the code if you want to just call VeraAlerts once with the events for both calendars together in one alert.  If that is what you want -- One way is to modify futureEvents to return the Msg variable (remove the Vera Alerts Call and the two parameters  VeraAlerts_num,VA_profile,).  Then call it twice (once for each calendar).  Concatenate the two messages into one and then call Vera Alerts.

It's up to you how you want to do it -- but as I said before, you will need to learn to use Lua.
 

Offline Stuart

  • Moderator
  • Hero Member
  • *****
  • Posts: 728
  • Karma: +71/-2
Re: GCAL3 - Version 2.0
« Reply #483 on: April 11, 2016, 10:29:59 am »
@ Nettuno

I decided that the suggestions I made earlier would be a good example for the documentation -- so this may save you some time.

Code: [Select]

function futureEvents(GCal_number)
  local GCAL_SID = "urn:srs-com:serviceId:GCalIII"
  local outInfo  = ""
 
  -- find out when tomorrow starts
  local nextday = os.time() + (3600*24)
  local ta = os.date("*t", nextday)
  local tomorrow = string.format("%d-%02d-%02d", ta.year, ta.month, ta.day)
 
  -- get the contents of gc_jsonEvents
  local jsonEvents = luup.variable_get(GCAL_SID, "gc_jsonEvents",GCal_number)
  if (jsonEvents == "[]") then -- equivalent of a nul
    return
  end

  -- read the events in gc_jsonEvents into an array
  local json = require("dkjson") -- depending on your vera version you may need to use require("json")
  local eventList =json.decode(jsonEvents)
  package.loaded.json = nil

  local numberEvents = #eventList
  local startevent, startDate, eventname, startTime, endTime
 
  -- now process the array one entry at a time
  for i = 1,numberEvents do
    startevent = eventList[i].eventStart -- the start time for this event
    startDate = os.date("%Y-%m-%d", startevent)
   if startDate == tomorrow then -- this is just an example filter
    startTime = os.date("%H:%M:%S", startevent)
    endTime = os.date("%H:%M:%S", eventList[i].eventEnd)
    eventname = eventList[i].eventName
    outInfo  = outInfo .. "\n" .. "Event " .. eventname .. " will start at " .. startTime .. " and end at " .. endTime
    end
  end
  return outInfo
end

local VeraAlerts_number = 47 -- change this to be the Vera Alert plugin number

local GCal_num = 42 -- change this to be the GCal plugin number for your Events
local Msg1 = futureEvents(GCal_num)

local Profile = "VeraAlerts" -- this will be the name of the VeraAlerts profile for you
Msg1 = "Alerts from calendar one \n" .. Msg1
local Msg = Msg1
-- luup.call_action("urn:richardgreen:serviceId:VeraAlert1", "SendAlert", {Message = Msg, Recipients = Profile}, VeraAlerts_number)
               
GCal_num = 42 -- change this to be the GCal plugin number for another plugin
local Msg2 = futureEvents(GCal_num)
Msg2 = "Alerts from calendar two \n" .. Msg2
Msg = Msg1 .. "\n\n" .. Msg2
luup.call_action("urn:richardgreen:serviceId:VeraAlert1", "SendAlert", {Message = Msg, Recipients = Profile}, VeraAlerts_number)

NOTE:  If there are no events then this code will fail -- please see post later on in this thread
« Last Edit: May 13, 2016, 04:06:07 pm by Stuart »

Offline MSW

  • Full Member
  • ***
  • Posts: 114
  • Karma: +6/-6
Re: GCAL3 - Version 2.0
« Reply #484 on: May 03, 2016, 02:40:45 pm »
Stuart - can you clarify in scene trigger creation the difference between "Event Matches Keyword" and "Event has a specified name"?  I can't figure out when I would use one or the other. 

I have a scene using Event has a specified name, and I specified one of the two keywords I set (semi-colon delimited) in the configuration.  Next event has the correct value but the scene isn't triggering.

thanks!

Offline Stuart

  • Moderator
  • Hero Member
  • *****
  • Posts: 728
  • Karma: +71/-2
Re: GCAL3 - Version 2.0
« Reply #485 on: May 03, 2016, 06:59:19 pm »
Stuart - can you clarify in scene trigger creation the difference between "Event Matches Keyword" and "Event has a specified name"?  I can't figure out when I would use one or the other. 

I have a scene using Event has a specified name, and I specified one of the two keywords I set (semi-colon delimited) in the configuration.  Next event has the correct value but the scene isn't triggering.

thanks!

For a full explanation - take a look at the documentation.

Basically you either set gc_Keyword to something -- in which case you use "Event Matches Keyword"; or you leave gc_Keyword blank -- in which case you use "Event has a specified name" and supply that value (Note: must be Upper Case).

Soooo -- if you have an event called tEsT and another event called StuFf (These get converted to TEST and STUFF internally)

If you set gc_Keyword blank and set "Event has a specified name" to TEST -- it will activate on the event called tEsT but not StuFf ..... or

you could set gc_Keyword to test; STUFF and trigger on Event Matches Keyword and it will trigger on both events.

There are many variations - some examples are in the documentation



Offline MSW

  • Full Member
  • ***
  • Posts: 114
  • Karma: +6/-6
Re: GCAL3 - Version 2.0
« Reply #486 on: May 03, 2016, 11:24:03 pm »
I read through the PDF doc twice before I posted. I don't believe what you wrote below is in there (I didn't see anything about scene creation). Thanks for the clarification! 
Stuart - can you clarify in scene trigger creation the difference between "Event Matches Keyword" and "Event has a specified name"?  I can't figure out when I would use one or the other. 

I have a scene using Event has a specified name, and I specified one of the two keywords I set (semi-colon delimited) in the configuration.  Next event has the correct value but the scene isn't triggering.

thanks!

For a full explanation - take a look at the documentation.

Basically you either set gc_Keyword to something -- in which case you use "Event Matches Keyword"; or you leave gc_Keyword blank -- in which case you use "Event has a specified name" and supply that value (Note: must be Upper Case).

Soooo -- if you have an event called tEsT and another event called StuFf (These get converted to TEST and STUFF internally)

If you set gc_Keyword blank and set "Event has a specified name" to TEST -- it will activate on the event called tEsT but not StuFf ..... or

you could set gc_Keyword to test; STUFF and trigger on Event Matches Keyword and it will trigger on both events.

There are many variations - some examples are in the documentation

Offline Stuart

  • Moderator
  • Hero Member
  • *****
  • Posts: 728
  • Karma: +71/-2
Re: GCAL3 - Version 2.0
« Reply #487 on: May 04, 2016, 06:30:58 pm »
I'm not trying to be argumentative here, I  would appreciate your input on how to better the documentation (my objective is "good enough" as it's not exactly my life's work  ;D ).

Can you take a look at the Usage Notes.  Short of an expansive explanation - what needs to be added to make it simpler for the new user.  Understanding that vera specific things (like setting up scenes and the like) are not in scope as this is just about using the plugin, assuming the user already has some familiarity with Vera.

Offline MSW

  • Full Member
  • ***
  • Posts: 114
  • Karma: +6/-6
Re: GCAL3 - Version 2.0
« Reply #488 on: May 05, 2016, 02:34:24 am »
I'm not trying to be argumentative here, I  would appreciate your input on how to better the documentation (my objective is "good enough" as it's not exactly my life's work  ;D ).

Can you take a look at the Usage Notes.  Short of an expansive explanation - what needs to be added to make it simpler for the new user.  Understanding that vera specific things (like setting up scenes and the like) are not in scope as this is just about using the plugin, assuming the user already has some familiarity with Vera.

Stuart - I wouldn't presume you are being argumentative and we are all very grateful for your continued improvement of this plugin!  What is not in the documentation is exactly what you posted above.  Something along the lines of:  "When you are creating a scene, the scene can be triggered a few different ways.  Basically you either set gc_Keyword to something -- in which case you use "Event Matches Keyword"; or you leave gc_Keyword blank -- in which case you use "Event has a specified name" and supply that value (Note: must be Upper Case)."

The documentation focuses on the parameters to make the events available to the controller, but not on how to consume them within the controller.

Offline Stuart

  • Moderator
  • Hero Member
  • *****
  • Posts: 728
  • Karma: +71/-2
Re: GCAL3 - Version 2.1
« Reply #489 on: May 13, 2016, 11:25:39 am »
@ MSW - thanks!  I made the updates you suggested and a few other minor edits.  There is a new version of the document in the first post.  There is also a new version of the plugin available through the marketplace.

Enjoy.

Offline Stuart

  • Moderator
  • Hero Member
  • *****
  • Posts: 728
  • Karma: +71/-2
Re: GCAL3 - Version 2.2
« Reply #490 on: May 13, 2016, 04:13:05 pm »
@ Nettuno

I was going through the code I posted earlier and noticed that if there are no events then it will fail :-(
This is because of trying to concatenate a value that is nil.

Here is code that is more correct:

Code: [Select]

function futureEvents(GCal_number)
  local GCAL_SID = "urn:srs-com:serviceId:GCalIII"
  local outInfo  = ""
 
  -- find out when tomorrow starts
  local nextday = os.time() + (3600*24)
  local ta = os.date("*t", nextday)
  local tomorrow = string.format("%d-%02d-%02d", ta.year, ta.month, ta.day)
 
  -- get the contents of gc_jsonEvents
  local jsonEvents = luup.variable_get(GCAL_SID, "gc_jsonEvents",GCal_number)
  if (jsonEvents == "[]") then -- equivalent of a nul
    return
  end

  -- read the events in gc_jsonEvents into an array
  local json = require("dkjson") -- depending on your vera version you may need to use require("json")
  local eventList =json.decode(jsonEvents)
  package.loaded.json = nil

  local numberEvents = #eventList
  local startevent, startDate, eventname, startTime, endTime
 
  -- now process the array one entry at a time
  for i = 1,numberEvents do
    startevent = eventList[i].eventStart -- the start time for this event
    startDate = os.date("%Y-%m-%d", startevent)
   if startDate == tomorrow then -- this is just an example filter
    startTime = os.date("%H:%M:%S", startevent)
    endTime = os.date("%H:%M:%S", eventList[i].eventEnd)
    eventname = eventList[i].eventName
    outInfo  = outInfo .. "\n" .. "Event " .. eventname .. " will start at " .. startTime .. " and end at " .. endTime
    end
  end
  return outInfo
end

local VeraAlerts_number = 47 -- change this to be the Vera Alert plugin number

local GCal_num = 42 -- change this to be the GCal plugin number for your Events
local Msg1 = futureEvents(GCal_num)
Msg1 = Msg1 or "NONE"
local Profile = "VeraAlerts" -- this will be the name of the VeraAlerts profile for you
Msg1 = "Alerts from calendar one \n" .. Msg1
local Msg = Msg1
-- luup.call_action("urn:richardgreen:serviceId:VeraAlert1", "SendAlert", {Message = Msg, Recipients = Profile}, VeraAlerts_number)
               
GCal_num = 42 -- change this to be the GCal plugin number for another plugin
local Msg2 = futureEvents(GCal_num)
Msg2 = Msg2 or "NONE"
Msg2 = "Alerts from calendar two \n" .. Msg2
Msg = Msg1 .. "\n\n" .. Msg2 .. "\n"
luup.call_action("urn:richardgreen:serviceId:VeraAlert1", "SendAlert", {Message = Msg, Recipients = Profile}, VeraAlerts_number)

The edits to the original are simple:
after this line
Code: [Select]
local Msg1 = futureEvents(GCal_num)
add
Code: [Select]
Msg1 = Msg1 or "NONE"

after this line
Code: [Select]
local Msg2 = futureEvents(GCal_num)
add
Code: [Select]
Msg2 = Msg2 or "NONE"

also change this line for formatting reasons
Code: [Select]
Msg = Msg1 .. "\n\n" .. Msg2
to
Code: [Select]
Msg = Msg1 .. "\n\n" .. Msg2 .. "\n"
« Last Edit: May 13, 2016, 04:15:00 pm by Stuart »

Offline MSW

  • Full Member
  • ***
  • Posts: 114
  • Karma: +6/-6
Re: GCAL3 - Version 2.2
« Reply #491 on: June 04, 2016, 02:30:01 pm »
I just had an issue where the plugin failed - it was working fine for at least a month (version 2.0) before this.  Tonight, after working fine for a calendar event yesterday, it missed an event on the calendar and I logged in to Vera to see a "Fatal calendar error" on the device.  The event it missed today had the same name as an event it had caught several times successfully in the past. I clicked "check" and it seemed to reset and looks fine now for the next event, but any idea what caused that and what I can do to not have it happen in the future so I can count on the trigger?  (I have since upgraded to 2.2, but the release notes didn't indicate anything that seemed to be related to this, so I assume whatever caused it is still in the code base).

thanks!

Offline Stuart

  • Moderator
  • Hero Member
  • *****
  • Posts: 728
  • Karma: +71/-2
Re: GCAL3 - Version 2.2
« Reply #492 on: June 05, 2016, 12:23:53 am »
You need to look at the log file at the time that the fatal event was reported.  Depending on the debug level set in gc_debug - the error may (or may not) have been caught.  I suspect that there may have been a network issue.

I have never seen this type of error in my testing or reported by any one else other than during initial setup (because of credential / setup issues)

Offline MSW

  • Full Member
  • ***
  • Posts: 114
  • Karma: +6/-6
Re: GCAL3 - Version 2.2
« Reply #493 on: June 05, 2016, 12:31:34 am »
You need to look at the log file at the time that the fatal event was reported.  Depending on the debug level set in gc_debug - the error may (or may not) have been caught.  I suspect that there may have been a network issue.

I have never seen this type of error in my testing or reported by any one else other than during initial setup (because of credential / setup issues)

Stuart - unfortunately, it's too late for that. Say there was an Internet outage. If it already had the next event known brogue the outage, couldn't it be coded to fire the next event as opposed to dying because it couldn't check to see if there was any more current information?  Also, if there is an internet outage, does it continue checking to see if the Internet reconnects or once it fails, it needs someone to manually reset it?

Offline Stuart

  • Moderator
  • Hero Member
  • *****
  • Posts: 728
  • Karma: +71/-2
Re: GCAL3 - Version 2.2
« Reply #494 on: June 05, 2016, 11:45:02 pm »
Let me take a look -- there is some retry logic associated with creating events.  What I need to think about is "unintended consequences" -- For example - not seeing that an event has been deleted since it last checked the calendar (because it could not check "this time") and behaving as if the event were still there .....