-- Fill table with your birthday calendar information. Two friends are added as an example.
-- Enter the mailto.
-- Create an alert device.
-- Schedule this script once per day.
-- The script looks at who's birthday is tomorrow.
-- It updates the alert device with date, name and age and sends email notification when found.
When no one is found: When one or more are found:
Code: Select all
-- 21-03-2024- Jan Peppink, https://ict.peppink.nl
-- Fill table with your birthday calendar information.
-- Enter the mailto.
-- Create an alert device.
-- Schedule this script once per day.
-- The script looks at who's birthday is tomorrow.
-- It updates the alert device with date, name and age and sends email notification when found.
--
return {
on = {
timer = {
'at 12:05', -- Run once per day
-- Before - birthday(s) of today are shown.
-- After - birthday(s) of tomorrow are shown.
}
},
-- logging = {
-- level = domoticz.LOG_INFO,
-- marker = 'BirthdayReminder-',
-- },
execute = function(domoticz, timer)
-- Set Local environment=================
-- loging level 0 = NO logging, 1 = INFO, 2 = DEBUG, 3 = ERROR or 4 = FORCE
local debug_level = 2
local _u = domoticz.utils
-- local _h = domoticz.helpers
local dmTomorrow = domoticz.time.dateToDate(domoticz.time.rawDate, 'yyyy-mm-dd', 'dd-mm', 86400 ) -- Day and month tomorrow
local mailContent = ''
local alertIdx = n -- Set to the idx of the Virtual Alert sensor you have to create for this script
local alertLevel = domoticz.ALERTLEVEL_GREY -- Holds the alertLevel (color) to set
local alertText = ''
local mailto = '[email protected]' -- Set E-mail adres to sent to.
-- Local Functions go here =============
function split(str, character)
result = {}
index = 1
for s in string.gmatch(str, "[^"..character.."]+") do
result[index] = s
index = index + 1
end
return result
end
-- Translate local day and month names
--local lDday = {"zondag", "maandag", "dinsdag", "woensdag", "donderdag", "vrijdag", "zaterdag"}
local lmonthnames = {'januari', 'februari', 'maart', 'april', 'mei', 'juni', 'juli', 'augustus', 'september', 'october', 'november', 'december'}
local nextDay = domoticz.time.makeTime(domoticz.time.dateToDate(domoticz.time.rawDate, 'yyyy-mm-dd', 'yyyy-mm-dd hh:mm:ss', 86400))
--local TestDate = lmonthnames[nextDay.wday] .. ' '..string.format("%02d", nextDay.day) .. ' ' .. lmonthnames[nextDay.month] .. ' ' .. tostring(nextDay.year)
--Create table birthdayarray
birthdayarray = {}
--january
--february
--march
table.insert(birthdayarray, "1993-03-22;Your Friend1")
table.insert(birthdayarray, "2001-03-22;Your Friend2")
--april
--may
--june
--july
--august
--september
--october
--november
--december
-- Now start to do something ============
local loopcounter = 0
for key,value in ipairs(birthdayarray) do
local currentdayarray = split(value, ";")
local dateFound = currentdayarray[1]
local nameFound = currentdayarray[2]
local dmBirthdayFound = domoticz.time.dateToDate(dateFound,'yyyy-mm-dd', 'dd-mm', 0 ) -- Day and month
if dmTomorrow == dmBirthdayFound then
--Found someone for tomorrow. Calculate age
local age = nextDay.year - domoticz.time.dateToDate(dateFound,'yyyy-mm-dd', 'yyyy', 0 )
-- strip the .0 from the end of the age.
age = _u.round(age,0)
if loopcounter > 0 then
-- Add a newline first when more than one birtday is found.
alertText = alertText .. string.char(10)
mailContent = mailContent .. '<br>'
end
-- Add current content to the string
alertText = alertText .. string.format("%02d", nextDay.day) .. ' ' .. lmonthnames[nextDay.month] .. ': ' .. nameFound .. ' <span style="color: red;">' .. age .. '</span>' .. ' jaar!'
mailContent = mailContent .. string.format("%02d", nextDay.day) .. ' ' .. lmonthnames[nextDay.month] .. ': ' .. nameFound .. ' ' .. age .. ' jaar!'
loopcounter = loopcounter + 1
end
end
if mailContent ~= '' then
domoticz.email( 'Morgen jarig!', mailContent, mailto )
--
alertLevel = domoticz.ALERTLEVEL_GREEN
domoticz.devices(alertIdx).updateAlertSensor(alertLevel, alertText)
else
alertLevel = domoticz.ALERTLEVEL_GREY
alertText = string.format("%02d", nextDay.day) .. ' ' .. lmonthnames[nextDay.month] .. ': Geen jarigen.'
domoticz.devices(alertIdx).updateAlertSensor(alertLevel, alertText)
end
end
}