Swedish hollidays

I found an API that lists all days you search for and includes if it’s a work free day.
That gave me an idea to list what is the most important in life: when is the next weekday that is work free?
I built a quick API that I could use to make Home Asssistant show me upcoming days of interest (which you can customize).

Here is what the stock output is:
image
Upcoming dates, weekday and why.

To get this you need to add the following in configuration.yaml

sensor:
  - platform: rest
    name: Lediga_dagar
    resource: "http://www.hoppvader.nu/app/dagar.php" 
    value_template: '1'  # dummy value, not used; avoids the "State max length is 255 characters" error
    json_attributes:
      - dagar # this is what we actually want
    scan_interval: 28800 # three times per day

This will give you a sensor with a dummy state and an attribute like this:

dagar: # Specialdagar
**2020-06-19 Fredag - Midsommarafton**
**2020-12-24 Torsdag - Julafton**
**2020-12-25 Fredag - Juldagen**
**2020-12-31 Torsdag - Nyårsafton**
friendly_name: Lediga_dagar

This is json with one value (all the text). The ** and # is styling (read below).
This json can now be added to a markdown card like this:

content: '{{ states.sensor.lediga_dagar.attributes.dagar }}'
type: markdown

and it retuns a card as shown in the image above.

Styling and configuration
The API relies on GET parameters to be customized to your preferences.
That means you a question mark at the end of the URL and then add the configuration.
Each configuration needs to end with a & if there is a trailing command after.
Example cofiguration.yaml: resource: "http://www.hoppvader.nu/app/dagar.php?bold=n&title=FooBar&exclude=Måndag,Tisdag".
That will remove the bold font, set the title to FooBar and exclude Måndag and Tisdag.

Bold
The API makes the text bold by default.
To disable bold text add bold=n
Example in configuration that would be resource: "http://www.hoppvader.nu/app/dagar.php?bold=n"

Custom title
If you wish to replace or remove the custom title then use the GET command title=xxxx.
If you don’t want a title at all then just write title as in example resource: "http://www.hoppvader.nu/app/dagar.php?bold=n&title&exclude=Måndag,Tisdag"
The default is # Specialdagar, the # means the text is larger font.

Exclude days
The default is to not display work free days that occurs on Saturdays and Sundays since most people are not working those days anyways.
But if you work part time or have your “weekend” in the week then you can customize what days to exclude.
As an example, if you work part time and is always free on Fridays then “Midsommarafton” is not of interest for you because you are already free that day.
exclude=Fredag,Lördag,Söndag (Note the case sensitive)
Above will set Friday to Sunday as your days off, and you will not see “Midsommarafton” as an example.
I do not recommend disabling exclude all together as you can do with the other since it will list all Saturdays and Sundays.

Add days
You can add dates to the list also with a custom topic.
The custom added days will always be visible in the list even if they occur on a exclude day.
All other configuration you do to the URL will be read as topic=dates,comma,separated (no spaces).
Example, you have days when you are only working half the day.
Add a topic “Halvdagar” and add all dates after it.
resource: "http://www.hoppvader.nu/app/dagar.php?Halvdag=2020-03-01,2020-06-19 12:00&Fridag=2020-11-30" will add two days that is “Halvdagar” and one work free day.
image

Note the timestamp at Midsommarafton to make sure it occurs before “Midsommarafton”, all calendar dates are set to 23:59.
If you want the output on Midsommarafton to be (simplified example) “Halvdag -> Midsommarafton -> Go to bed” then you need to make the URL:
resource: "http://www.hoppvader.nu/app/dagar.php?Halvdag=2020-06-19 12:00&Go to bed=2020-06-19 23:59:01" because that makes go to bed occur one second after Midsommarafton.
image

Limitations

  • A URL can only hold about 2000 characters. If anyone actually needs more then I can try and figure out a way to do it but for now I believe it will be enough.

  • It’s case sensitive. Make sure to get it right…

  • The updates does not happen in real time. The scan_interval is when it should be updated.

  • I added the break point between “this year” and “next year” in August. So depending on your scan_interval sometimes during August next years days will be added.

But that is a binary output.
Not really comparable.

I have honestly not tried it but I assume it will give you true/false if today is a workday not about future events.
Or am I wrong?