Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

Bank Holiday Calc Scene


DonQuichopp

Question

Bank Holiday Calc Scene (V 1.2.3a)

 

I started creating a scene where the bank Holidays can be calculated, at the moment Switzerland (alle Kantone), Germany (alle Bundesländer), Austria (alle Bundesländer), United Kingdome (all Countries), France (some Départements), Sweden (whole Country), Ireland (whole Country), Iceland (whole Country), Poland (whole Country), Italy (whole Country), Norway (whole Country), Croatia (whole Country), Netherlands (whole Country), Czech Republic (whole Country, thanks @petr23) are covered. Work in progress for more Countries to come.

 

With this scene you can calculate all the Bank Holidays of the current year.
There are some preset Countries with already defined Holidays, some also have Provinces as there may be different holidays in parts of the country.

The yearly bank Holidays will be stored in the global Variable "BankHol_ThisYear" (in System Seconds). You can either use this list as you wish or implement it into Sankotronic's Main Scene for Time Based Events Control (setup described below).

 

The Names/Titles of the Bank Holidays are provided in multiple Languages and it is set up that more language or your own language can be supported.

 

Setup

You need to create a global variable with the Name "BankHol_ThisYear" in the upper part of the variable Panel.

 

If you wish to check constantly if today or tomorrow is a Bank Holiday, then you need to implement a function in @Sankotronic's Main Scene for Time Based Events Control.

 

Please login or register to see this code.

 

User Variables

Country

choose your country by changing the Code between the brackets (capital Letters)

Please login or register to see this code.

Available Countries:
  CH = Switzerland
  DE = Germany

  AT = Austria

  GB = United Kingdom

  FR = France

  SE = Sweden

  IE = Ireland

  IS = Iceland

  PL = Poland

  IT = Italy

  NO = Norway

  HR = Croatia

  CZ = Czech Republic

  NL = Netherlands

 

Province

choose your province by changing the Code between the brackets (small Letters).

If you do not wish to use a province you can keep the quotes empty "". 

Please login or register to see this code.

Available Provinces
Switzerland: ag = Argau, ar = Appenzell Ausserrhoden, ai = Appenzell Innerrhoden, bl = Basel-Landschaft, bs = Basel-Stadt, be = Bern, fr = Freiburg, ge = Genf, gl = Glarus, gr = Graubünden, ju = Jura, lu = Luzern, ne = Neuenburg, nw = Nidwalden, ow = Obwalden, sh = Schaffhausen, sz = Schwyz, so = Solothurn, sg = St. Gallen, ti = Tessin, tg = Thurgau, ur = Uri, vd = Waadt, vs = Wallis, zg = Zug, zh = Zürich

Germany: bw = Baden-Württemberg, by = Bayern, be = Berlin, bb = Brandenburg, hb = Bremen, hh = Hamburg, he = Hessen, mv = Mecklenburg-Vorpommern, ni = Niedersachsen, nw = Nordrhein-Westfalen, rp = Rheinland-Pfalz, sl = Saarland, sn = Sachsen, st = Sachsen-Anhalt, sh = Schleswig-Holstein, th = Thüringen

Austria: b = Burgenland, k = Kärnten, n = Niederösterreich, o = Oberösterreich, s = Salzburg, st = Steiermark, t = Tirol, v = Vorarlberg, w = Wien

United Kingdom: eng = England, sct = Scotland, wls = Wales, nir = Nord Ireland

France: moselle = Moselle, basrhin = Bas-Rhin, hautrhin = Haut-Rhin

Sweden: No Provinces (all public holidays apply for whole Country)

Ireland: No Provinces (all public holidays apply for whole Country)

Iceland: No Provinces (all public holidays apply for whole Country)

Poland: No Provinces (all public holidays apply for whole Country)

Italy: No Provinces (all public holidays apply for whole Country)

Norway: No Provinces (all public holidays apply for whole Country)

Croatia: No Provinces (all public holidays apply for whole Country)

Czech Republic: No Provinces (all public holidays apply for whole Country)

Netherlands: No Provinces (all public holidays apply for whole Country)

 

Language

choose your language by changing the Code between the brackets (small Letters)

Please login or register to see this code.

en = English
de = German

fr = French

sv = Swedish

ga = Gaelic / Irish

is = Islandic

pl = Polish

no = Norwegian

it = Italian

hr = Croatian

cz = Czech

nl = Dutch
ol = own language

 

The Texts are always given in the available languages.
If there is no Title for your chosen language, default language English will be taken.


There is also a key for your Own Language (ol)

Add the text in your language in the lines with the ["ol"] keys, just change the whole text in "OL xxx" after the equal-sign.

 

If you want to change the Title in an existing language for example German "de", then change it at the specific line where the key ["de"] is set.
Example: in xmasDayTitle you want to rename the German translation then change the Text in the line xmasDayTitle["de"] = change it from "Weihnachten" to "1. Weihnachtsfeiertag"

 

In this section I also tried to explain the Holiday as good as possible. This might need some improvement in future Versions.

 

Please login or register to see this code.

Show Sundays

There are some holidays that always fall on a Sunday (like Easter Sunday or Pentecost) these are not shown by default. If you want to add them, then you will have to set the variable "addSundays" to true. If set to false, these days are not shown/detected.

This setting does not exclude a holiday if it is a fixed day and hits a Sunday (like Swiss National day at 1. August), these days will always show.

 

Please login or register to see this code.

 

Debuggig

There are some switches to enable Debugging:

Please login or register to see this code.

If debug is set to true, then it will print the Results in an ordered List (Name = Date) in the Scene.

If you wish to check for a specific year to see if the calculations are correct, then set debugSpecificYear to true and choose the year in debugYear. Above it would check for the holidays in 2015 if debugSpecificYear were set to true.

 

Result

A JSON in the below format will be stored in the global Variable BankHol_ThisYear:

Please login or register to see this code.

 

Corrections

Even though I have tested the dates thoroughly there might be mistakes in the calculations. Before using the Scene in a vital Environment (Alarms, etc.) please check the list first in Debug Mode.

Please also let me know if I made a mistake, then I can correct it for future users.

 

Improvements

I will be adding more countries over the time. For certain Countries I am sure I'd need help from locals as these days are sometimes not easy to define.

 

Version History

1.2.3a     Fixed some Netherlands Holiday Names

1.2.3       Added Czech Republic, Netherlands

1.2.2       Added Norway, Italy, Croatia

1.2.1       Added Iceland, Poland

1.2.0       Introduced new Variable to add Sundays to the days too.
               Updated the countries and corrected a mistake in Sweden.
               Added Ireland and Irish/Gaelic language

1.1.0       Changed the Language Selection (see details above), added Sweden

1.0.2       Added France and Départements and French Language/Titles

1.0.1       Added Austria and its Bundesländer,
               Added United Kingdom (England, Northern Ireland, Wales and Scotland)

1.0.0       Initial Version for Switzerland & Germany
               With all Provinces (Kantone / Bundesländer)

 

Hope you enjoy the scene and some of you can use it :)

 

Here is the complete .lua file: 

Please login or register to see this attachment.

 

Cheers

Don

 

Please login or register to see this attachment.

Please login or register to see this attachment.

Please login or register to see this attachment.

Please login or register to see this attachment.

Please login or register to see this attachment.

Please login or register to see this attachment.

Please login or register to see this attachment.

Please login or register to see this attachment.

Edited by DonQuichopp
new Version
Link to comment
Share on other sites

Recommended Posts

  • 0

OK...I must be doing something really silly here...

I am adding the following chunk of code to another routine:

 

function doBankHoliday()
  if fibaro:getGlobalValue("BankHol_ThisYear") ~= nil then --only perform if there is a global Variable BankHol_ThisYear
    local local_bankHolidays = json.decode(fibaro:getGlobalValue("BankHol_ThisYear")) --get the global Value from Variable
    fibaro:setGlobal("BankHoliday", 0) -- set Variable to 0 before checking
    today = os.time({year = os.date('*t',os.time()).year, month = currentmonth, day = currentday})
   
    for k,v in pairs(local_bankHolidays) do
      if(today == v) then
        fibaro:setGlobal("BankHoliday", 1) --set Variable to 1
        if exDebug then logbug("lightblue", "Today is a Bankholiday ("..k..")") end;
        break
      end
      
    end
    
    fibaro:setGlobal("BankHolidayTomorro", 0) -- set Variable to 0 before checking
    tomorrow = os.time({year = os.date('*t',os.time()).year, month = currentmonth, day = currentday}) + (24*3600)
   
    for k,v in pairs(local_bankHolidays) do
      if(tomorrow == v) then
        fibaro:setGlobal("BankHolidayTomorro", 1) --set Variable to 1
        if exDebug then logbug("lightblue", "Tomorrow is a Bankholiday ("..k..")") end;
        break
      end
      
    end
  
  end
  
end

 

But I am getting the following error when I call it:

 

 

[DEBUG] 07:29:39: line 2311: field 'day' missing in date table

 

My JSON creation looks fine.

 

 

[DEBUG] 07:29:39: January First - 1. Jan 2017 (Sunday)
[DEBUG] 07:29:39: New Year's Day Compensation (2. January) - 2. Jan 2017 (Monday)
[DEBUG] 07:29:39: Easter Monday - 17. Apr 2017 (Monday)
[DEBUG] 07:29:39: May Day - 1. May 2017 (Monday)
[DEBUG] 07:29:39: Spring Bank Holiday - 29. May 2017 (Monday)
[DEBUG] 07:29:39: Late Summer Bank Holday - 28. Aug 2017 (Monday)
[DEBUG] 07:29:39: Christmas Day - 25. Dec 2017 (Monday)
[DEBUG] 07:29:39: Boxing Day - 26. Dec 2017 (Tuesday)
[DEBUG] 07:29:39: {"Boxing Day":1514289600,"May Day":1493636400,"January First":1483272000,"New Year's Day Compensation (2. January)":1483358400,"Christmas Day":1514203200,"Late Summer Bank Holday":1503918000,"Spring Bank Holiday":1496055600,"Easter Monday":1492426800}

 

What idiotic thing I am doing wrong?

Link to comment
Share on other sites

  • 0

Hi @darren-mc

 

Is line 2311 ( where the error is being reported) within this script that you are running this function or a a number that seems to large ?

 

If it is - what's at that line 

 

If not, I suspect its your today or tomorrow calculations. Try avd print them out and see if all parts are correct 

 

After that i'd add some print statements ( for k and v)  as you read you json/table

 

I can add this to my system later and see if it 'll run but may be worth check these few things 

Link to comment
Share on other sites

  • 0

Sorry that really wasn't very helpful.

 

today = os.time({year = os.date('*t',os.time()).year, month = currentmonth, day = currentday})

 

Is the line that its pointing to

Link to comment
Share on other sites

  • 0
19 minutes ago, darren-mc said:

Sorry that really wasn't very helpful.

 

today = os.time({year = os.date('*t',os.time()).year, month = currentmonth, day = currentday})

 

Is the line that its pointing to

Helpful or understandable ? 

 

Yes, where you assign a string value to today and also tomorrow 

 

Edit 

I just spotted that this is somebody else's code. I thought you had written it yourself and were looking for help debugging ...

Edited by AutoFrank
Link to comment
Share on other sites

  • 0
42 minutes ago, AutoFrank said:

Helpful or understandable ? 

 

Yes, where you assign a string value to today and also tomorrow 

 

Edit 

I just spotted that this is somebody else's code. I thought you had written it yourself and were looking for help debugging ...

Oh gees no...not clever enough to write that stuff....its taken from the code here....in this thread...I was trying to implement this stuff.

Link to comment
Share on other sites

  • 0
51 minutes ago, darren-mc said:

Oh gees no...not clever enough to write that stuff....its taken from the code here....in this thread...I was trying to implement this stuff.

 

@darren-mc

 

Could you post the full scene code and ill take a look later ...

Link to comment
Share on other sites

  • 0

Hello, is there a way to display the holidays (with the names) in a virtual device?

And thank you for this scene it works fine   :D

Link to comment
Share on other sites

  • 0

And if somebody need a Icon for this scene - here is the one i used

Please login or register to see this attachment.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...