Using the Google Calendar plugin to manage my daily reminders and notifications

I use a single Gcal device and a Variable Container device to manage notifications that are spoken or pushed (push notification) to me during the day.

Thought I’d share the code so that someone might find something useful in it.

My speech (the veraSay function) is handled outside of this. It’s a function that sends text to another server that uses PHP and MicroSoft’s speech API to make announcements. You could adapt to use Push Notifications, Vera Alerts, etc.

I set up reminder calendar entries - generally for early in the morning - with a token that my script uses. I have AM, PM, NOW, and SCHOOL HOLIDAY. The event title on the calendar will look like:
AM{Today is trash day.}
PM{Tomorrow is trash and recycling day.}
SCHOOL HOLIDAY{it’s a teacher work day.}

(side note - when you set up an event in Google Calendar, it tends to want to remove words like “today” and “tomorrow.”)

AM and PM save their data to a variable container. The logic to speak these reminders uses motion sensors, etc, to deliver messages when I wake up or when I’m moving around the house.

NOW just speaks the notification once and doesn’t save the text.

SCHOOL HOLIDAY also sets a Virtual Switch and saves the reason for the holiday (it’s a teacher work day, it’s Christmas break…) to the Variable Container. I use the School Holiday to prevent a “hey - you better leave for school or you’re gonna be late” type message from speaking on vacation days.

I’ve found this to be really handy. Especially to help remind us to put out trash bins (an recycle bins on alternating weeks).

If you spot some familiar code, it’s because I cobbled this together from bits found on the forum. Thanks to everyone that shares. It’s also a bit ugly. But it works.

-- gcal text handler

local gCalDeviceNo = 60 -- GCal Sensor device number
local GS_SID = "urn:utz-com:serviceId:GCal1" -- GCal Sensor Service ID
local eventVar = luup.variable_get (GS_SID, "gcalval", gCalDeviceNo )
local eventTitle = luup.variable_get (GS_SID, "gcalkeyword", gCalDeviceNo )
local varContainerDeviceNo = 64 -- Variable Container device number

luup.log(eventTitle .. " is " .. eventVar)

if eventTitle == "AM" then
	local current = luup.variable_get("urn:upnp-org:serviceId:VContainer1","Variable1",varContainerDeviceNo)
	-- local new = current .. " " .. eventVar
	local new = table.concat({current,eventVar}, " ")
	luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable1",new,varContainerDeviceNo)
elseif eventTitle == "PM" then
	local current = luup.variable_get("urn:upnp-org:serviceId:VContainer1","Variable3",varContainerDeviceNo)
	--local new = current .. " " .. eventVar
	local new = table.concat({current,eventVar}, " ")
	luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable3",new,varContainerDeviceNo)
elseif eventTitle == "NOW" then
	veraSay(eventVar,1)
elseif eventTitle == "SCHOOL HOLIDAY" then
	-- set holiday switch ON
	local holidaySwitch = 84
	luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue = "1"}, holidaySwitch)
	
	-- put holiday text in AM message
	local current = luup.variable_get("urn:upnp-org:serviceId:VContainer1","Variable1",varContainerDeviceNo)
	
	local new = table.concat({current,"No school today because " .. eventVar}, " ")
	luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable1",new,varContainerDeviceNo)
end

Hello,

This is very interesting. Thanks for sharing.
But I have a question:
How do you turn off the holiday switch?

@ih8gates

Kind of funny that this got pushed back to the top today. I was researching yesterday on how to do a server based TTS like you describe. I have an amazing TTS voice on my old PC that I used to use for voice announcements that I would like to use with VERA. Do you have a minute to give a rough draft of how you accomplished the PHP tie in to the microsoft speech api?

On the vacation reminders, I was already using the gcal sensor for days off similar to yours but I like how you have it set to tell WHY you will be off that day. Cool stuff.

[quote=“bubaleta, post:2, topic:178349”]Hello,

This is very interesting. Thanks for sharing.
But I have a question:
How do you turn off the holiday switch?[/quote]

I have a scene that runs at midnight and resets my virtual switches and clears out the variable container.

Here’s how you reset all of the Variable Container values (assuming your VC is device 64)

luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable1","",64) luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable2","",64) luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable3","",64) luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable3","",64)

I discussed it a bit here:
http://forum.micasaverde.com/index.php/topic,13619.msg133337.html#msg133337

Lemme know if you have questions!

@ih8gates I thought you used also the calendar…
Using your method is ok for one day holiday, but if you have 3 in a row, that would imply set-reset many times… not very efficient.
What I do, and this is only valid for one keyword, is to use the triggered-not triggerd sensor status, combined with a scene.
But as I said, only valid for one type of event, so I was looking for a new way of triggering events.

[quote=“bubaleta, post:6, topic:178349”]@ih8gates I thought you used also the calendar…
Using your method is ok for one day holiday, but if you have 3 in a row, that would imply set-reset many times… not very efficient.[/quote]

I’m OK with one reset a day. Not much overhead there.
Especially because I also set the reason for the holiday. So last month, I had:

because it’s Christmas break
because it’s Christmas eve
because it’s Christmas
and eventually
Because it’s New Years Eve

And I can use a repeating calendar event, then adjust some of the events in the series as needed.

I discussed it a bit here: http://forum.micasaverde.com/index.php/topic,13619.msg133337.html#msg133337

Lemme know if you have questions!

Awesome, thats probably enough to get what I need working. Thanks a bunch!

I was just wondering if anyone had created some GCAL TTS notifications that would work with the Sonos Plugin ?

@ih8gates

I noticed that you are using the original Google Calendar switch developed by utz.

That version was based on google api’s which will stop working sometime in November (the 14th from memory). You may want to convert to the newer GCal3 which supports the google calendar v3 API.

It also has a lot more functionality to play with :smiley:

Yes! I just fired up the forums this morning because I had a vague memory that November would be the end of the old API. Getting started on the conversion now.

It was pretty easy to adapt my code to work with Stuart’s new GCal plugin. If anyone’s interested, here’s what I’m using now.

I just noticed that I hard-coded a “64” for my text variable container, so adjust that to fit your ID.

-- gcal text handler

local gCalDeviceNo = 136 – GCal Sensor device number
local GS_SID = “urn:srs-com:serviceId:GCalIII” – GCal Sensor Service ID
local eventVar = luup.variable_get (GS_SID, “gc_Value”, gCalDeviceNo )
local eventTitle = luup.variable_get (GS_SID, “gc_TrippedEvent”, gCalDeviceNo )

luup.log(eventTitle … " is " … eventVar)

if eventTitle == “AM” then
local current = luup.variable_get(“urn:upnp-org:serviceId:VContainer1”,“Variable1”,64)
– local new = current … " " … eventVar
local new = table.concat({current,eventVar}, " ")
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”,“Variable1”,new,64)
elseif eventTitle == “PM” then
local current = luup.variable_get(“urn:upnp-org:serviceId:VContainer1”,“Variable3”,64)
–local new = current … " " … eventVar
local new = table.concat({current,eventVar}, " ")
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”,“Variable3”,new,64)
elseif eventTitle == “NOW” then
deedeeSay(eventVar,1)
elseif eventTitle == “SCHOOL HOLIDAY” then
– set holiday switch ON
local holidaySwitch = 84
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “1”}, holidaySwitch)

-- put holiday text in AM message
local current = luup.variable_get("urn:upnp-org:serviceId:VContainer1","Variable1",64)

local new = table.concat({current,"No school today because " .. eventVar}, " ")
luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable1",new,64)

end

@ ih8gates:

That is awesome. I just downloaded the google calendar 3, v1.1, and was about to embark on exactly what you have done. My vision, similar to yours, is NOT ramp up the kids lights, not tell them the temp, how to dress based on weather, and turn off their ivona (british Amy) voice alerts. After all, getting the kids up early every day on vacation is not the best way to enjoy the news in the morning :).

I am planning on a holiday vswitch also.

I currently have to use a vswitch - “Nonsense blocker”, because my kids have learned the xbox can be turned on again, when pressing the little white button on the outlet.
so, if the kids have been turned on, that scene also activates the nonsense blocker. if Nonsense off scene is triggered, or goodnight scene is executed, and they attempt to turn the device back on, it checks the status of Nonsense blocker.

If on, turns the device back off…My middle child found a loophole, and I invite thoughts for a fix…

if he presses the button enough times, vera seems to give up, and his device stays on…now, I can get extreme, and install an extra linear in line 20 amp device down stream of his outlet, and if the device turns on after the off scenes, and if nonsense blocker is still on, to trigger that relay and turn off the whole room, but I am hoping to not have to wire that device… anyone have thoughts on this ?

From your tinkering on this holiday calendar matter, is this still the best way to go, has it been reliable for you, etc?

Thanks all, for making this forum of sharing, a fantastic resource.

Hi
Wouldn’t a plug with power metering capabilities solve the problem? For example, if the plug reports that more than 5 Watts are used you could trigger a scene that checks if the device is allowed to be on or should be turned off. Maybe that scene will trigger when the Vera recovers from the loophole? Just an idea.
/Claes

Does this

http://forum.micasaverde.com/index.php/topic,26692.msg229451.html#msg229451

look interesting / usable for you guys ?

Added event start and end triggers including overlapping events in R1.3. May be useful.