Holiday Sensor

since the workday sensor is a binary sensor that only supports a binary status like on or off.

i decided to get rid of the holiday part and using another binary sensor just for the holidays.

What do you need?

  • Some scripting outside of your Homeassistent
  • a mqttbroker with mosquitto_pub
  • a simple textfile for the holiday days

~/feiertage_2019.csv (The file with the holidays)
since i am from germany my dateformat looks like this:

25.12.2019

the script (that should run every day at 00:01 via crontab )

#!/bin/bash
#holiday
today=`date +'%d'.'%m'.'%Y'`
my_year=`date +'%Y'`
feiertage=~/feiertage_$my_year.csv
feiertag=$(grep $today "$feiertage")
if [ -z "$feiertag" ]
   then
   mosquitto_pub -h [ip of your mqtt server] -p 1883 -u [mqtt username]switch -P [mqtt password] -t holiday -m OFF -r
else
   mosquitto_pub -h [ip of your mqtt server] -p 1883 -u [mqtt username]switch -P [mqtt password] -t holiday -m ON -r
fi

run that script once before adding the sensor to your HA Server
Since i am using a binary_sensors.yaml my code looks like this

- platform: mqtt
  name: Holiday
  state_topic: "holiday"
  payload_on: "ON"
  payload_off: "OFF"

reload your sensors / HA Server and it should work.

1 Like

Nice idea, however it’s overkill. You can change the config for a workday sensor to show “on” only on holidays. And you can have multiple workday sensors.

Like this:

binary_sensor:
  #"normal" workday sensor
  - platform: workday
    country: DE
    name: Workday
  # holiday sensor, shows "on" only on the specified holidays
  - platform: workday
    country: DE
    name: Holiday
    workdays: [holiday]
    excludes: []
    add_holidays:
      - '2019-12-24'
      - '2019-12-31'
6 Likes

That sounds great and easy.
Since i already using that sourcefile to handle my alarm (outside of HA) and mqtt scripting like that for some non mqtt compatible things - its not that overkill (for me)

In Fact its less overkill because the overkill starts already by curl that csv from the internet and my calendar.
This way i didnt need to change the yaml every year (via script) or having two holidaysources.

Anyway thx for showing the easyway
cheers

@Burningstone
you were right it was overkill so i decided to replace the binary_sensor for another solution with even more overkill.
A script that wgets the school holidays (since these are always stored as start end description) some datediffmagic between start & end and change the light in the kids bedroom automation from always 07:20 A.M to only when the school holidays sensor is not in the state NEIN other than that it shows the holiday / type of the school holiday.

yapp useless i know but i like it (otherwise i wouldnt fiddle with HA in the 1st place)

1 Like

Yeah I see your point. Makes sense in your case to get a fully automated experience.

Just think for a complete newbie it’s way easier to just setup two workday sensors.

Your new method is even more overkill, but I really like it and think this is an awesome approach, where you don’t even need to adjust the holidays once a year. Would be nice if you could share it here, I don’t have any need for this (no HA automations for me haha) but others might find this very useful

dont know where to start

Yes doing things outside of HA seems not a good idea to share it here.
Yes it could share my old script that wgets reformats and change the yaml…
but a simple typo in the yaml would cause the whole HA to stop (ask me how i know) and the script is made for germany only and it not whole germany its just for my province because each provine has other “holidays”

If anyone in germany wants the script he/she/it can ask me it wouldnt make sense for an austrian chinese or us citicen.

F*** YAML haha, I’m really happy that I can do my automations in Python thanks to AppDaemon.

1 Like