Days of the month

Easy to use, 100% Lua-based event scripting framework.
Post Reply
User avatar
Derik
Posts: 2187
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Days of the month

Post by Derik » Sunday 23 September 2018 19:18

Is there some that a have a Dzvent working with the days of the month?
Like to have a option to switch a dummy for all the day of the month..

I do have a months script.
When i have a day script i can set some birthdays with some blockley options sned mail set music on etc.

So i hope there is anyone that make a script..

Perhaps a simple start vor day 1 and 2 etc,,,
So i can make the script finised by my self

Only how is this working with the different days in short and long month?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups

User avatar
Derik
Posts: 2187
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Days of the month

Post by Derik » Sunday 21 October 2018 9:50

Kick..
Perhaps some one have a script or some help?

I found smething like this:

Code: Select all

-- GROUPSCRIPT gets passed a 'recordset' object.
-- the 'Month', 'Year' and 'Day' are fields in the data
-- Each cell is filled with 'Title' and 'Time'

imonth = tonumber(recordset:getrecord(1):field('Month'):content());
iyear = tonumber(recordset:getrecord(1):field('Year'):content());

function get_day_of_week(dd, mm, yy)
  dw=os.date('*t',os.time{year=yy,month=mm,day=dd})['wday']
  return dw,({"Sun","Mon","Tue","Wed","Thu","Fri","Sat" })[dw]
end

function get_days_in_month(month, year)
  local days_in_month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }   
  local d = days_in_month[month]
   
  -- check for leap year
  if (month == 2) then
  
    if year % 4 == 0 then
     if year % 100 == 0 then                
      if year % 400 == 0 then                    
          d = 29
      end
     else                
      d = 29
     end
    end
  end
  return d  
end

function populate_cell(row, col, day_of_week)
   for record=1, recordset:size() do
   		myrecord = recordset:getrecord(record);
  		
   		data_day = tonumber(myrecord:getfield('Day'):content());
   		if data_day == day_of_week then
			this_entry = "<p>" .. myrecord:getfield('Title'):content() .. "</p>" .. "<p>" .. myrecord:getfield('Time'):content() .. "</p><br/>"
			table:cell(row,col):setcontent(table:cell(row,col):getcontent() .. this_entry);
   		end
   end
end

table = TABLE.new();
table:cell(1,1):setcontent("Sunday");
table:cell(1,2):setcontent("Monday");
table:cell(1,3):setcontent("Tuesday");
table:cell(1,4):setcontent("Wednesday");
table:cell(1,5):setcontent("Thursday");
table:cell(1,6):setcontent("Friday");
table:cell(1,7):setcontent("Saturday");

days_in_month = get_days_in_month(imonth, iyear);
first_day_in_month = get_day_of_week(1,imonth,iyear);

for day=1,days_in_month do
	offset = (day-1) + first_day_in_month;

	row = math.floor((offset-1) / 7)
	column = math.floor(offset-1) % 7;

	table:cell((row*2)+2,column+1):setcontent(day);

	populate_cell((row*2)+3,column+1, day);
end;

table:present();
Only how to switch a dummy with this?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups

Post Reply

Who is online

Users browsing this forum: bce626 and 3 guests