Weekends and hollidays

How to get weekends and hollidays in arduino?
I want some device to be on only on working days on weekends and hollidays should be off.
How can I do that?

Arduino, power relay, real time clock. Arduino reads the real time clock. If "weekend" or "holiday" then "de-energize relay."

A Real Time Clock (RTC) or an Internet connection would be two ways

Which Arduino board are you using ?

how do you set that?

for now ESP32 but I can change. And it is connected to internet.

With an Internet connection you can get the date and time from an NTP server

See ESP32 NTP Client-Server: Get Date and Time (Arduino IDE) | Random Nerd Tutorials

getting the time with the ESP32 is quite easy.
See:
https://werner.rothschopf.net/microcontroller/202103_arduino_esp32_ntp_en.htm

you will find the weekday in the tm structure:

Serial.print(tm.tm_wday); // days since Sunday 0-6

thank you. weekdays are ok, what about holidays which are work free?

That would be different for each country. Are you just making this for one country?

Holidays which fall on the same month and day of month are also easy. For example Christmas Day is always 25th Dec, at least in my country. The RTC will give you the month number and the day of month number and your code can compare those against a list of such dates that you can add into your code.

Holidays which move around the calender are more difficult. For example Eid or Easter. Some of these always fall on a particular day of the week, but not the same week each year. Others have even more complex rules which may depend, for example, on the phase of the moon. You may be able to find, on line, an algorithm to calculate their dates, which you can turn into C code so that your Arduino can calculate when these holidays fall in any given year.

as others pointed out ... some are fixed by date, some need to be calculated.
When you are interested in other free days, most catholic days are based on eastern and you should find some algorithm to get Eastern.

first try:
https://www.google.com/search?q=calculate+easter+c%2B%2B

yes for my country Slovenia

google already have for each country hollidays, but how to pull in that data?
Like this
https://www.googleapis.com/calendar/v3/calendars/sl.slovenian%23holiday%40group.v.calendar.google.com/events?key=AIzaSyDouVkRTq1GFSMa7fVNxx9v_q28pppqTI0

here are all hollidays for each country question is just how to pull in those data

https://www.googleapis.com/calendar/v3/calendars/sl.slovenian%23holiday%40group.v.calendar.google.com/events?key=AIzaSyDouVkRTq1GFSMa7fVNxx9v_q28pppqTI0

  1. get the API description,
  2. probably get working API key
  3. fetch data and stream to an ArduinoJson object.
  4. let ArduinoJson library parse the JSON
2 Likes

I can't see the response from that API, I get only a "BLOCKED/DENIED" error message, perhaps because I am not in Slovenia. Can you post an example response?

yes, here it is

Can you just paste it into your post please, using code tags? No need to post links to sites people might not know or trust.

On second thoughts, it is very long. It seems to cover 10 years of holiday dates.

Is there a way to filter the request for this year only ?

1 Like

I can't it is too long. That link is my server it is safe.

Use ArduinoJson assistant to generate parts of the needed source code

If of any help, here I have an example for reading and parsing a JSON from OpenWeatherAPI

https://werner.rothschopf.net/microcontroller/202409_esp_weather_en.htm

1 Like