autorzy: sztywniak, marecki_0luk1
Urządzenie wirtualne: Urodziny/Imieniny
1) Tworzymy nowe urządzenie i dodajemy do niego dwie etykiety puste o nazwach: birthdayL1, birthdayL2.
2) Do pętli głównej wpisujemy:
-- BIRTHDAY CALENDAR
-- LUA script by marecki_0luk1
-- version 1.0, 2014-07-11
-- Configuration --
-- 1) Put your deviceID into mDevices
-- 2) Fill your birthday calendar
-- 3) Change notification time
-- 4) Change device icon
local virtualId = fibaro:getSelfId();
local mDevices = {}; -- put device ids here
local today = "d"..tostring(os.date("%m%d"));
local tomorrow = "d"..tostring(os.date("%m%d", os.time()+24*60*60));
local next_day = os.time()+24*60*60;
local notification_hour = "20"; -- time to notify user
local note;
local next_birthday;
local birthday_calendar={
d0101="",
d0101="",
d0102="",
d0103="",
d0104="",
d0105="",
d0106="",
d0107="",
d0108="",
d0109="",
d0110="",
d0111="",
d0112="",
d0113="",
d0114="",
d0115="",
d0116="",
d0117="",
d0118="",
d0119="",
d0120="",
d0121="",
d0122="",
d0123="",
d0124="",
d0125="",
d0126="",
d0127="",
d0128="",
d0129="",
d0130="",
d0131="",
d0201="",
d0202="",
d0203="",
d0204="",
d0205="",
d0206="",
d0207="",
d0208="",
d0209="",
d0210="",
d0211="",
d0212="",
d0213="",
d0214="",
d0215="",
d0216="",
d0217="",
d0218="",
d0219="",
d0220="",
d0221="",
d0222="",
d0223="",
d0224="",
d0225="",
d0226="",
d0227="",
d0228="",
d0229="",
d0301="",
d0302="",
d0303="",
d0304="",
d0305="",
d0306="",
d0307="",
d0308="",
d0309="",
d0310="",
d0311="",
d0312="",
d0313="",
d0314="",
d0315="",
d0316="",
d0317="",
d0318="",
d0319="",
d0320="",
d0321="",
d0322="",
d0323="",
d0324="",
d0325="",
d0326="",
d0327="",
d0328="",
d0329="",
d0330="",
d0331="",
d0401="",
d0402="",
d0403="",
d0404="",
d0405="",
d0406="",
d0407="",
d0408="",
d0409="",
d0410="",
d0411="",
d0412="",
d0413="",
d0414="",
d0415="",
d0416="",
d0417="",
d0418="",
d0419="",
d0420="",
d0421="",
d0422="",
d0423="",
d0424="",
d0425="",
d0426="",
d0427="",
d0428="",
d0429="",
d0430="",
d0501="",
d0502="",
d0503="",
d0504="",
d0505="",
d0506="",
d0507="",
d0508="",
d0509="",
d0510="",
d0511="",
d0512="",
d0513="",
d0514="",
d0515="",
d0516="",
d0517="",
d0518="",
d0519="",
d0520="",
d0521="",
d0522="",
d0523="",
d0524="",
d0525="",
d0526="",
d0527="",
d0528="",
d0529="",
d0530="",
d0531="",
d0601="",
d0602="",
d0603="",
d0604="",
d0605="",
d0606="",
d0607="",
d0608="",
d0609="",
d0610="",
d0611="",
d0612="",
d0613="",
d0614="",
d0615="",
d0616="",
d0617="",
d0618="",
d0619="",
d0620="",
d0621="",
d0622="",
d0623="",
d0624="",
d0625="",
d0626="",
d0627="",
d0628="",
d0629="",
d0630="",
d0701="",
d0702="",
d0703="",
d0704="",
d0705="",
d0706="",
d0707="",
d0708="",
d0709="",
d0710="",
d0711="",
d0712="",
d0713="",
d0714="",
d0715="",
d0716="",
d0717="",
d0718="",
d0719="",
d0720="",
d0721="",
d0722="",
d0723="",
d0724="",
d0725="",
d0726="",
d0727="",
d0728="",
d0729="",
d0730="",
d0731="",
d0801="",
d0802="",
d0803="",
d0804="",
d0805="",
d0806="",
d0807="",
d0808="",
d0809="",
d0810="",
d0811="",
d0812="",
d0813="",
d0814="",
d0815="",
d0816="",
d0817="",
d0818="",
d0819="",
d0820="",
d0821="",
d0822="",
d0823="",
d0824="",
d0825="",
d0826="",
d0827="",
d0828="",
d0829="",
d0830="",
d0831="",
d0901="",
d0902="",
d0903="",
d0904="",
d0905="",
d0906="",
d0907="",
d0908="",
d0909="",
d0910="",
d0911="",
d0912="",
d0913="",
d0914="",
d0915="",
d0916="",
d0917="",
d0918="",
d0919="",
d0920="",
d0921="",
d0922="",
d0923="",
d0924="",
d0925="",
d0926="",
d0927="",
d0928="",
d0929="",
d0930="",
d1001="",
d1002="",
d1003="",
d1004="",
d1005="",
d1006="",
d1007="",
d1008="",
d1009="",
d1010="",
d1011="",
d1012="",
d1013="",
d1014="",
d1015="",
d1016="",
d1017="",
d1018="",
d1019="",
d1020="",
d1021="",
d1022="",
d1023="",
d1024="",
d1025="",
d1026="",
d1027="",
d1028="",
d1029="",
d1030="",
d1031="",
d1101="",
d1102="",
d1103="",
d1104="",
d1105="",
d1106="",
d1107="",
d1108="",
d1109="",
d1110="",
d1111="",
d1112="",
d1113="",
d1114="",
d1115="",
d1116="",
d1117="",
d1118="",
d1119="",
d1120="",
d1121="",
d1122="",
d1123="",
d1124="",
d1125="",
d1126="",
d1127="",
d1128="",
d1129="",
d1130="",
d1201="",
d1202="",
d1203="",
d1204="",
d1205="",
d1206="",
d1207="",
d1208="",
d1209="",
d1210="",
d1211="",
d1212="",
d1213="",
d1214="",
d1215="",
d1216="",
d1217="",
d1218="",
d1219="",
d1220="",
d1221="",
d1222="",
d1223="",
d1224="",
d1225="",
d1226="",
d1227="",
d1228="",
d1229="",
d1230="",
d1231=""}
-- Send birthday notification
function sendPush(note)
if tostring(os.date("%H")) == tostring(notification_hour) then
for i = 1, # mDevices do
fibaro:call(mDevices[i], "sendPush", note);
end;
end;
end;
-- main LOOP
-- Always show if there is a somebody's birthday today
if birthday_calendar[today] ~= "" then
note = "Dzisiaj urodziny obchodzi " .. birthday_calendar[today];
fibaro:call(virtualId, "setProperty", "ui.birthdayL1.value", note);
sendPush(note);
fibaro:log(note);
else
fibaro:call(virtualId, "setProperty", "ui.birthdayL1.value", "Dzisiaj nikt nie obchodzi urodzin");
end;
if birthday_calendar[tomorrow] ~= "" then
note = "Jutro urodziny obchodzi " .. birthday_calendar[tomorrow];
fibaro:call(virtualId, "setProperty", "ui.birthdayL2.value", note);
sendPush(note);
fibaro:log(note);
elseif birthday_calendar[tomorrow] == "" then
-- check for nearest birthday....
fibaro:log("looking forward ...");
repeat
next_day = next_day + 24*60*60;
--fibaro:debug(tostring(os.date("%m%d", next_day)));
next_birthday = "d"..tostring(os.date("%m%d", next_day));
--fibaro:debug(next_birthday);
if birthday_calendar[next_birthday] ~= "" then
note = "Najbliższe urodziny " .. tostring(os.date("[%Y-")) .. tostring(os.date("%m-%d]", next_day)) .." obchodzi " .. birthday_calendar[next_birthday];
fibaro:call(virtualId, "setProperty", "ui.birthdayL2.value", note);
fibaro:log(note);
--sendPush(note);
end;
if next_birthday == "d1231" then
--fibaro:debug("Year changed");
change_year = true;
next_day = (os.time({day=01,month=01,year=tostring(tonumber(os.date("%Y"))+1),hour=00,min=00,sec=00})+os.time()-os.time(os.date("!*t")));
--fibaro:debug(tostring(next_day));
end;
until birthday_calendar[next_birthday] ~= "";
end;
-- check every hour to send notification
fibaro:sleep(1000*60*60);
Urządzenie mogłoby również pobierać dane z serwera zewnętrznego zamiast tablicy, ale nie wszyscy posiadaja własny hosting.