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