BakSeeDaa´s Google Calendar for Domoticz (deprecated)

In this subforum you can show projects you have made, or you are busy with. Please create your own topic.

Moderator: leecollings

User avatar
Ferpando
Posts: 30
Joined: Friday 23 October 2015 9:45
Target OS: NAS (Synology & others)
Domoticz version:
Location: Spain
Contact:

Re: BakSeeDaa´s Google Calendar for Domoticz V 1.0.0 Release

Post by Ferpando »

kept installing the plugin, edited user variables and here's what I have now
2015-10-24 16:59:00.752 LUA: GCal3 V 1.0.1: Running Plugin ...
2015-10-24 16:59:00.752 LUA: GCal3 V 1.0.1: local function: checkGCal
2015-10-24 16:59:00.752 LUA: GCal3 V 1.0.1: Checking semaphore
2015-10-24 16:59:00.755 LUA: GCal3 V 1.0.1: Command /bin/ls /root/GCal3/GCal3.sem returned true
2015-10-24 16:59:00.755 LUA: GCal3 V 1.0.1: Semaphore file returned 24
2015-10-24 16:59:00.759 LUA: GCal3 V 1.0.1: Command /bin/ls /root/GCal3/GCal3.sem returned true
2015-10-24 16:59:00.759 LUA: GCal3 V 1.0.1: Device 24 claimed semaphore
2015-10-24 16:59:00.759 LUA: GCal3 V 1.0.1: StartMin is 2015-10-23T22:00:00Z StartMax is 2015-10-25T12:59:00Z
2015-10-24 16:59:00.759 LUA: GCal3 V 1.0.1: End of day is 2015-10-24T23:59:59
2015-10-24 16:59:00.759 LUA: GCal3 V 1.0.1: local function: requestCalendar
2015-10-24 16:59:00.759 LUA: GCal3 V 1.0.1: local function: get_access_token
2015-10-24 16:59:00.759 LUA: GCal3 V 1.0.1: Getting a new token
2015-10-24 16:59:01.376 LUA: GCal3 V 1.0.1: Got new token
2015-10-24 16:59:01.376 LUA: GCal3 V 1.0.1: Checking google calendar
2015-10-24 16:59:02.691 LUA: GCal3 V 1.0.1: Error getting calendar data: {
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "Not Found"
}
],
"code": 404,
"message": "Not Found"
}
}

2015-10-24 16:59:02.750 LUA: GCal3 V 1.0.1: Device 24 released the semaphore - reason: calendar check complete
2015-10-24 16:59:02.750 LUA: GCal3 V 1.0.1: Next check will be in 500 sec on 2015-10-24 at 17:07:22
2015-10-24 16:59:02.751 LUA: GCal3 V 1.0.1: Device 24 released the semaphore - reason: initialization complete
2015-10-24 16:59:02.751 LUA: GCal3 V 1.0.1: Switch recent status: Off
User avatar
Ferpando
Posts: 30
Joined: Friday 23 October 2015 9:45
Target OS: NAS (Synology & others)
Domoticz version:
Location: Spain
Contact:

Re: BakSeeDaa´s Google Calendar for Domoticz V 1.0.0 Release

Post by Ferpando »

ok.. another problem with the calendarID. Sorry about that..
Now it seems to be working :-)
cal.gif
cal.gif (3.69 KiB) Viewed 5691 times
I'll do some more testing and get back with the results.
Thanks again for your time
2015-10-24 17:03:29.704 LUA: GCal3 V 1.0.1: Command /bin/ls /root/GCal3/GCal3.sem returned true
2015-10-24 17:03:29.705 LUA: GCal3 V 1.0.1: Device 24 claimed semaphore
2015-10-24 17:03:29.705 LUA: GCal3 V 1.0.1: StartMin is 2015-10-23T22:00:00Z StartMax is 2015-10-25T13:03:00Z
2015-10-24 17:03:29.705 LUA: GCal3 V 1.0.1: End of day is 2015-10-24T23:59:59
2015-10-24 17:03:29.705 LUA: GCal3 V 1.0.1: local function: requestCalendar
2015-10-24 17:03:29.705 LUA: GCal3 V 1.0.1: local function: get_access_token
2015-10-24 17:03:29.705 LUA: GCal3 V 1.0.1: Getting a new token
2015-10-24 17:03:30.090 LUA: GCal3 V 1.0.1: Got new token
2015-10-24 17:03:30.091 LUA: GCal3 V 1.0.1: Checking google calendar
2015-10-24 17:03:30.454 LUA: GCal3 V 1.0.1: No event in the next day. Retry later...
2015-10-24 17:03:30.454 LUA: GCal3 V 1.0.1: local function: setTrippedOff
2015-10-24 17:03:30.454 LUA: GCal3 V 1.0.1: Event-End Inactive
2015-10-24 17:03:30.508 LUA: GCal3 V 1.0.1: Device 24 released the semaphore - reason: calendar check complete
2015-10-24 17:03:30.509 LUA: GCal3 V 1.0.1: Next check will be in 10800 sec on 2015-10-24 at 20:03:30
2015-10-24 17:03:30.510 LUA: GCal3 V 1.0.1: Device 24 released the semaphore - reason: initialization complete
2015-10-24 17:03:30.510 LUA: GCal3 V 1.0.1: Switch recent status: Off
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: BakSeeDaa´s Google Calendar for Domoticz V 1.0.0 Release

Post by BakSeeDaa »

Thanks. That looks good. Put something in your calendar and press on the GCAl check button :D
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: BakSeeDaa´s Google Calendar for Domoticz V 1.0.1 Release

Post by BakSeeDaa »

Version 1.0.1 released.

- Removed the check for openssl since the command differ on different unix systems.
- Added CalendarID as part of the json Events file name to allow multiple instances.
- Fixed so that the events.json file is written using valid json syntax.
User avatar
Ferpando
Posts: 30
Joined: Friday 23 October 2015 9:45
Target OS: NAS (Synology & others)
Domoticz version:
Location: Spain
Contact:

Re: BakSeeDaa´s Google Calendar for Domoticz V 1.0.1 Release

Post by Ferpando »

When an event is triggered, I'd like to test the Text Variable for the event name.
That's currently not working because the variable contains also the times for the event

Code: Select all

22	Calendar CHECK	Off	2015-10-26 08:43:01	0
23	Calendar Status	     2015-10-26 08:43:00	NEW EVENT
                                                  09:00 Oct 26 to 10:00 Oct 26
How could I check for event name once the calendar device has been triggered?

I was thinking of creating another virtual device with some Lua to split the text in the text device (something like splitting the wunderground information to get only temperature described https://www.domoticz.com/wiki/Virtual_weather_devices) but I don't know if there is an easy way of doing it.
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: BakSeeDaa´s Google Calendar for Domoticz V 1.0.1 Release

Post by BakSeeDaa »

Ferpando wrote:When an event is triggered, I'd like to test the Text Variable for the event name.
That's currently not working because the variable contains also the times for the event

Code: Select all

22	Calendar CHECK	Off	2015-10-26 08:43:01	0
23	Calendar Status	     2015-10-26 08:43:00	NEW EVENT
                                                  09:00 Oct 26 to 10:00 Oct 26
How could I check for event name once the calendar device has been triggered?

I was thinking of creating another virtual device with some Lua to split the text in the text device (something like splitting the wunderground information to get only temperature described https://www.domoticz.com/wiki/Virtual_weather_devices) but I don't know if there is an easy way of doing it.
If an event is tripped (GCal device is "On") , then you can simply check the GCalnnTrippedEvent user variable for the event name.
User avatar
Ferpando
Posts: 30
Joined: Friday 23 October 2015 9:45
Target OS: NAS (Synology & others)
Domoticz version:
Location: Spain
Contact:

Re: BakSeeDaa´s Google Calendar for Domoticz V 1.0.1 Release

Post by Ferpando »

That should work, after realizing event names are capitalized inside Gcal :-) but it doesn't.
This is never true
cal2.gif
cal2.gif (8.3 KiB) Viewed 5641 times
maybe the variable is set after calendar device becomes true? So when evaluating the variable, it does not have the text yet?

Also, what would the contents be if there were 2 concurrent events?


EDIT:
If i use one word event it seems to work. The message is sent but with 0 as the text? So instead of getting 'CALENDAR EVENTO' the message reads 'CALENDAR 0'
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: BakSeeDaa´s Google Calendar for Domoticz V 1.0.1 Release

Post by BakSeeDaa »

Ferpando wrote:That should work, after realizing event names are capitalized inside Gcal :-) but it doesn't.
This is never true
....

maybe the variable is set after calendar device becomes true? So when evaluating the variable, it does not have the text yet?

Also, what would the contents be if there were 2 concurrent events?
I'm not sure if Blockly really can read user variables yet, I don't use Blockly so I don't know. You can test your Blockly code using a dummy switch. Then You will know.
V0.9 - GCal3 PDF wrote:Similarly the variable gc_jsonActiveEvents gives a json array of the currently active events – not just the
first event but any overlapping or nested events. The event name and any associated parameter are
provided. This variable can be used in the same manner as described above by Luup/Lua code to trigger
scenes.
For simpler uses, gc_ActiveEvents is a comma delimited list of active/overlapping/ nested events (with no
parameter) that can be used by Luup/Lua/PLEG to trigger scenes.
For overlapping events you can probably do with GCalnnActiveEvents. I don't think Blockly can find a substring in the string though... If You need to trigger on (and evaluate) overlapping events I suggest you consider a plain Lua script instead.

Below is a simple Lua script that does (or should do) the same thing as your Blockly script

Code: Select all

-- script_device_testing.lua
-------------------------------------
commandArray = {}

if ((devicechanged["Calendar Vera"] == "On")
and (uservariables["GCal24TrippedEvent"] == "QUE EVENTO")) then
	print("Tjohooo")
	commandArray['SendNotification']='subject#body'
end

return commandArray
User avatar
Ferpando
Posts: 30
Joined: Friday 23 October 2015 9:45
Target OS: NAS (Synology & others)
Domoticz version:
Location: Spain
Contact:

Re: BakSeeDaa´s Google Calendar for Domoticz V 1.0.1 Release

Post by Ferpando »

ok, thank you. I'll take a look at Lua
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: BakSeeDaa´s Google Calendar for Domoticz V 1.0.1 Release

Post by BakSeeDaa »

For a complete documentation about what is in the user variables created by BGCD You can read V0.9 - GCal3 PDF.

For the ones that do Lua scripting the possibilities are endless.. (well almost)

Here is a "quick and dirty" (It could probably be improved) Lua script that I use for the Laundry room booking. Several people can book the laundry room in a Google Calendar. The Calendar is set up with 10 minutes time offset. The reason for that is that I want to send an SMS reminder to the person 10 minutes in advance before the laundry time starts. The script reads the json file with active events that is created by BGCD and checks that the booking is made within the allowed time schedule.

The script uses some routines that are defined in the bakseeda.lua (You have it already)
It's just here as an example on how it can be made on Domoticz. The original script I got inspired by is also in the V0.9 - GCal3 PDF. (Note that the documentation is made for another HA-System and the original script need some changes in order to work. See my script below which is working on Domoticz and You might be able to figure it out.)

Code: Select all

commandArray = {}

if (devicechanged["GCal Laundry Room Booking"] == "On") then
	local b = require("scripts/lua/bakseeda")
	b.debugPre = "Laundry"
	b.debug = 3
	b.DEBUG(3, "Checking who is going to use the laundry room")
	local SMSText, washer
	local TrippedID = b.getVar("GCal59TrippedID")
	if ((TrippedID == "") or (TrippedID == nil)) then
		return commandArray
	end

	local open = io.open
	local function read_file(path)
		local file = open(path, "rb")
		if not file then return nil end
		local content = file:read "*a" 
		file:close()
		return content
	end

	local jsonEvents = read_file("/home/pi/domoticz/GCal3/events59.json")

	if ((jsonEvents == "[]") or (jsonEvents == nil)) then
		return false
	end
	b.DEBUG(3, "jsonEvents: " .. jsonEvents)
	-- load the json package
	local json = require("scripts/lua/json")
	local eventList =json.decode(jsonEvents)
	local startevent, endevent, eventname, eventID
	b.DEBUG(3, "TrippedID: " .. TrippedID)

	-- Find active event
	for i = 1, #eventList do
		endevent = eventList[ i ].eventEnd
		eventname = eventList[ i ].eventName
		eventID = eventname .. " " .. os.date("%m", endevent) .. "/" .. os.date("%d", endevent) .. " " .. os.date("%H:%M", endevent)
		b.DEBUG(3, "eventID: " .. eventID)
		if eventID == TrippedID then
			if string.find(eventname, "JOHN") then washer = "Mr Holmes" end
			if string.find(eventname, "ANN") or string.find(eventname, "ANNA") or string.find(eventname, "CLARA") then washer = "Anna Clara" end
			if string.find(eventname, "PAUL") then washer = "Paul" end
			if washer then
				local startHour, startMinute, endHour, endMinute, errorText
				startevent = eventList[ i ].eventStart + 600 -- Add 10 minutes to startevent
				endevent = endevent - 600 -- Subtract 10 minutes from endevent
				startHour = os.date("%H", startevent)
				startMinute = os.date("%M", startevent)
				endHour = os.date("%H", endevent)
				endMinute = os.date("%M", endevent)
				if (startHour < "07") or (startHour > "20") or (startHour == "20" and (startMinute > "00")) then errorText = "You have tried to book the laundry room outside the allowed schedule. After booking You may use the laundry room all weekdays between 07:00 and 20:00" end
				if (endHour < "07") or (endHour > "20") or (endHour == "20" and (endMinute > "00")) then errorText = "You have tried to book the laundry room outside the allowed schedule. After booking You may use the laundry room all weekdays between 07:00 and 20:00" end
				SMSText = " Your booking is from " .. os.date("%H:%M", startevent) .. " to " .. os.date("%H:%M", endevent) .. ". Thank You for using our facilities. Good luck with the laundry :D"
				if errorText then
					SMSText = errorText
				else
					SMSText = "Hello " .. washer .. ". This is a reminder that you have booked the laundry room. Youwill be able to access the laundry room after 10 minuter from now." .. SMSText
				end
				b.DEBUG(3, "SMSText: " .. SMSText)
				break
			end
		end
	end

	if washer then
		b.DEBUG(3, "washer: " .. washer)
		if washer == "Mr Holmes" then
			b.SMSAlert(SMSText, "073999999999")
		elseif washer == "Anna Clara" then
			b.SMSAlert(SMSText, "07299999999")
		elseif washer == "Paul" then
			b.SMSAlert(SMSText, "0769999999999")
		end
	end

end

return commandArray
ricorico94
Posts: 94
Joined: Monday 26 October 2015 10:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: BakSeeDaa´s Google Calendar for Domoticz V 1.0.1 Release

Post by ricorico94 »

Hi,

My question will probably sounds stupid to most of you, but I'm new to both linux and Domoticz..
Does this module works with a Domoticz installation installed for the "plug and play" SD image provided on Domoticz website ? (I mean installation made using this link: https://www.domoticz.com/wiki/Domoticz_ ... i_SD_Image )
br,
Ricorico94
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: BakSeeDaa´s Google Calendar for Domoticz V 1.0.1 Release

Post by BakSeeDaa »

ricorico94 wrote:Hi,

My question will probably sounds stupid to most of you, but I'm new to both linux and Domoticz..
Does this module works with a Domoticz installation installed for the "plug and play" SD image provided on Domoticz website ? (I mean installation made using this link: https://www.domoticz.com/wiki/Domoticz_ ... i_SD_Image )
br,
Ricorico94
Yes it will :D
User avatar
capman
Posts: 153
Joined: Friday 12 July 2013 20:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Belgium
Contact:

Re: BakSeeDaa´s Google Calendar for Domoticz V 1.0.1 Release

Post by capman »

Okee , first of all , thank you for your work on this project. Nice job.
But I have a problem :mrgreen:
A followed all your steps to setup the calendar but on my log a see this , and nothing happend.
2015-11-01 21:15:40.709 LUA: localhost:8084
2015-11-01 21:15:40.712 LUA: GCal3 V 1.0.1: Calendar device GCal Domoticz (idx:208 ) initializing
2015-11-01 21:15:40.717 LUA: GCal3 V 1.0.1: Command /bin/ls /root/GCal3/ returned true
2015-11-01 21:15:40.722 LUA: GCal3 V 1.0.1: Command /bin/rm -f /root/GCal3/GCal3.sem returned true
2015-11-01 21:15:40.725 LUA: GCal3 V 1.0.1: Command bin/rm -f /root/GCal3/*.token returned nil
2015-11-01 21:15:40.725 LUA: GCal3 V 1.0.1: Checking semaphore
2015-11-01 21:15:40.730 LUA: GCal3 V 1.0.1: Command /bin/ls /root/GCal3/GCal3.sem returned nil
2015-11-01 21:15:40.730 LUA: GCal3 V 1.0.1: Semaphore file returned nil
2015-11-01 21:15:40.731 LUA: GCal3 V 1.0.1: Device 208 requested semaphore
2015-11-01 21:15:40.735 LUA: GCal3 V 1.0.1: Command /bin/ls /root/GCal3/GCal3.sem returned true
2015-11-01 21:15:40.735 LUA: GCal3 V 1.0.1: Device 208 claimed semaphore
2015-11-01 21:15:40.736 LUA: GCal3 V 1.0.1: New user variables were created. Please run again.
2015-11-01 21:15:40.737 EventSystem: Fetching url...
2015-11-01 21:15:40.737 EventSystem: Fetching url...
2015-11-01 21:15:40.737 EventSystem: Fetching url...
2015-11-01 21:15:40.737 EventSystem: Fetching url...
2015-11-01 21:15:40.737 EventSystem: Fetching url...
2015-11-01 21:15:40.737 EventSystem: Fetching url...
2015-11-01 21:15:40.737 EventSystem: Fetching url...
2015-11-01 21:15:40.737 EventSystem: Fetching url...
2015-11-01 21:15:40.737 EventSystem: Fetching url...
2015-11-01 21:15:40.737 EventSystem: Fetching url...
2015-11-01 21:15:40.737 EventSystem: Fetching url...
2015-11-01 21:15:40.737 EventSystem: Fetching url...
2015-11-01 21:15:40.737 EventSystem: Fetching url...
2015-11-01 21:15:40.738 EventSystem: Fetching url...
2015-11-01 21:15:40.738 EventSystem: Fetching url...
2015-11-01 21:15:40.738 EventSystem: Fetching url...
2015-11-01 21:15:40.738 EventSystem: Fetching url...
2015-11-01 21:15:40.738 EventSystem: Fetching url...
2015-11-01 21:15:40.738 EventSystem: Fetching url...
2015-11-01 21:15:40.738 EventSystem: Fetching url...
2015-11-01 21:15:40.738 EventSystem: Fetching url...
2015-11-01 21:15:40.738 EventSystem: Fetching url...
2015-11-01 21:15:40.738 EventSystem: Fetching url...
2015-11-01 21:15:40.738 EventSystem: Fetching url...
2015-11-01 21:15:40.738 EventSystem: Fetching url...
2015-11-01 21:15:40.739 EventSystem: Fetching url...
2015-11-01 21:15:40.739 EventSystem: Script event triggered: /usr/local/domoticz/var/scripts/lua/script_device_gcal.lua
2015-11-01 21:15:40.677 (GCalCheck Domoticz) Lighting 2 (GCalCheck Domoticz)
2015-11-01 21:15:42.290 (GCalCheck Domoticz) Lighting 2 (GCalCheck Domoticz)
A also run domoticz on my synology see a followed your steps for this machine also. But there is no creating for 25 user variables.
So i'm stocked in here , can you please help me out ? Thanks.
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: BakSeeDaa´s Google Calendar for Domoticz V 1.0.1 Release

Post by BakSeeDaa »

@capman ...
If you have protected Domoticz with Username/Password, you must temporarily put it back to default (no password required) before doing the next step. You may activate password protection again later.
Is password protection active?

If not, then I will prepare a new script for you tomorrow that will show some more debug information.
User avatar
capman
Posts: 153
Joined: Friday 12 July 2013 20:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Belgium
Contact:

Re: BakSeeDaa´s Google Calendar for Domoticz V 1.0.1 Release

Post by capman »

Yes !! That was the problem. Thanks 4 helping my so fast ;).
It's working now.
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: BakSeeDaa´s Google Calendar for Domoticz V 1.0.1 Release

Post by BakSeeDaa »

capman wrote:Yes !! That was the problem. Thanks 4 helping my so fast ;).
It's working now.
You're welcome. I'm happy it works :D
User avatar
Ferpando
Posts: 30
Joined: Friday 23 October 2015 9:45
Target OS: NAS (Synology & others)
Domoticz version:
Location: Spain
Contact:

Re: BakSeeDaa´s Google Calendar for Domoticz V 1.0.1 Release

Post by Ferpando »

It seems that rebooting the synology clears the contents of the root folder. Or maybe the DSM upgrade...
Anyway, I think we have to find another way to make this work, because creating folders and remounting every time is not very practical.
Also gcal json files are deleted, which is not good.
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: BakSeeDaa´s Google Calendar for Domoticz V 1.0.1 Release

Post by BakSeeDaa »

Ferpando wrote:It seems that rebooting the synology clears the contents of the root folder. Or maybe the DSM upgrade...
Anyway, I think we have to find another way to make this work, because creating folders and remounting every time is not very practical.
Also gcal json files are deleted, which is not good.
OK, I'll have a look into that.
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: BakSeeDaa´s Google Calendar for Domoticz V 1.0.1 Release

Post by BakSeeDaa »

Ferpando wrote:It seems that rebooting the synology clears the contents of the root folder. Or maybe the DSM upgrade...
Anyway, I think we have to find another way to make this work, because creating folders and remounting every time is not very practical.
Also gcal json files are deleted, which is not good.
@Ferpando, I've made some compatibility changes in the code.

Since Synology seems to empty the /root directory when upgrading it's certainly not a good idea to store anything in there. With the attached 1.0.2 test version the GCal3 directory (where You put your credentials file) is now /usr/local/domoticz/var/Gcal3 . As before it will be automatically created but you will have to put the credentials file back. Also, now there is no need for symbolic links for BGCD to work on Synology.

Please unzip the attached file and put all the 3 lua scripts files where they belong (overwriting the older ones). Please let me know if it works. Thanks.
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: BakSeeDaa´s Google Calendar for Domoticz V 1.0.2 Release

Post by BakSeeDaa »

New version released. See upgrade instruction on initial post.

V 1.0.2 New location of the credentials folder for Synology systems.
Better detection of path for Domoticz install directory and script directory.
Setting the package.path before including files using "require" for
improved compatibility.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest