Exists a way to know if the day is holiday or business day?
Moderators: leecollings, remb0
-
- Posts: 91
- Joined: Thursday 11 August 2016 12:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: IT
- Contact:
Exists a way to know if the day is holiday or business day?
Hi all,
I need to know if [today] is an holiday or business day because I want to change the behavior of my scripts in base of it.
I know that in DzVents doesn't exists a way (something like "domoticz.isHoliday", it's correct?), but exists an API (like google maps, WU, etc) or any other way?
Obviously, i'd like to have the holiday in my local calendar (italian).
Thanks.
I need to know if [today] is an holiday or business day because I want to change the behavior of my scripts in base of it.
I know that in DzVents doesn't exists a way (something like "domoticz.isHoliday", it's correct?), but exists an API (like google maps, WU, etc) or any other way?
Obviously, i'd like to have the holiday in my local calendar (italian).
Thanks.
- emme
- Posts: 909
- Joined: Monday 27 June 2016 11:02
- Target OS: Raspberry Pi / ODroid
- Domoticz version: latest
- Location: Milano, Italy
- Contact:
Re: Exists a way to know if the day is holiday or business day?
as a workaround... what about a table like:
(maybe into an external file so all scripts can use it)
then, in your code
of course you will need to update it every year
it would be nice to include this into domoticz
Code: Select all
isHoliday = {}
isHoliday['0101'] = 'New Year'
isHoliday['0104'] = 'Easter'
isHoliday['0105'] = 'Labour Day'
...
then, in your code
Code: Select all
if isHoliday[<today's date formatted as DDMM>] ~= nil then
domoticz.log('Hey... no rush...today is '..isHoliday[<today's date formatted as DDMM>]..'!!!!!')
else
domoticz.log('Come on Men... wake up!!')
end if
it would be nice to include this into domoticz
The most dangerous phrase in any language is:
"We always done this way"
"We always done this way"
-
- Posts: 91
- Joined: Thursday 11 August 2016 12:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: IT
- Contact:
Re: Exists a way to know if the day is holiday or business day?
yes, nice, but inconvenient to do this job every year..
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Exists a way to know if the day is holiday or business day?
I use a bash script (triggered daily by cron) to do this.
relevant parts of the script:
you can change the json to domoticz to do other stuff eg change state of a virtual switch or change to a different timerplan as well
relevant parts of the script:
Code: Select all
today=$(date --date="0 days ago " +"%-d-%-m-%Y")
json_return=$(curl -s http://www.kayaposoft.com/enrico/json/v1.0/?action=isPublicHoliday\&date=$today\&country=ita )
if $(echo $json_return | jq '.[]') ;then
curl -i -s -H "Accept: application/json" "http://domoticz-IP:domoticz-port/json.htm?type=command¶m=updateuservariable&vname=MyVarName&vtype=0&vvalue=1"
fi
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 91
- Joined: Thursday 11 August 2016 12:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: IT
- Contact:
Re: Exists a way to know if the day is holiday or business day?
I like this, I will try it! Thanks.
- Siewert308SW
- Posts: 288
- Joined: Monday 29 December 2014 15:47
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Stable
- Location: The Netherlands
- Contact:
Re: Exists a way to know if the day is holiday or business day?
There are so many ways to get this job done.
I know some countries have variable days which are called as (bank) holiday.
Haven't took a look at that for my own country but some days are a easy calculation as they for example occur on a fixed day after some other day like Easter.
For fixed days i use a function which can be called like below:
edit: @waaren didn't know that url, thx
I know some countries have variable days which are called as (bank) holiday.
Haven't took a look at that for my own country but some days are a easy calculation as they for example occur on a fixed day after some other day like Easter.
For fixed days i use a function which can be called like below:
edit: @waaren didn't know that url, thx
Code: Select all
function IsHoliday()
local monthNow = tonumber(os.date("%m"));
local dayNow = tonumber(os.date("%d"));
local holiday
if (dayNow == 27 and monthNow == 04) -- Koningsdag
or (dayNow == 04 and monthNow == 05) -- Bevrijdingdag
or (dayNow == 05 and monthNow == 05) -- Doden Herdenking
or (dayNow == 11 and monthNow == 11) -- Sint Maarten
or (dayNow == 05 and monthNow == 12) -- Sinterklaas
or (dayNow == 25 and monthNow == 12) -- 1e Kerstdag
or (dayNow == 26 and monthNow == 12) -- 2e kerstdag
or (dayNow == 31 and monthNow == 12) -- Oud jaarsdag
or (dayNow == 01 and monthNow == 01) -- Nieuw jaarsdag
then
holiday = 1
else
holiday = 0
end
return holiday
end
-- Call function holiday
holiday = IsHoliday()
commandArray = {}
if devicedchanged['someonehome'] == 'On'
and otherdevices['light'] == 'Off'
and otherdevices['holidaylight'] == 'Off'
and holiday == 0
then
commandArray['light']='On'
end
if devicedchanged['someonehome'] == 'On'
and otherdevices['light'] == 'Off'
and otherdevices['holidaylight'] == 'Off'
and holiday == 1
then
commandArray['light']='On'
commandArray['holidaylight']='On'
end
return commandArray
Setup:
- RPi4 - Domo Stable / Aeotec Z-stick7 / PiHole Unbound Gemini
- RPi4 - PiHole / PiVPN Unbound Gemini
- Synology DS923+ / DS218j
- P1 Gas/Power, SmartGateway watermeter
- Fibaro switches, contacts, plugs, smoke/Co2 ect
- rootfs @ USB HDD
- RPi4 - Domo Stable / Aeotec Z-stick7 / PiHole Unbound Gemini
- RPi4 - PiHole / PiVPN Unbound Gemini
- Synology DS923+ / DS218j
- P1 Gas/Power, SmartGateway watermeter
- Fibaro switches, contacts, plugs, smoke/Co2 ect
- rootfs @ USB HDD
- emme
- Posts: 909
- Joined: Monday 27 June 2016 11:02
- Target OS: Raspberry Pi / ODroid
- Domoticz version: latest
- Location: Milano, Italy
- Contact:
Re: Exists a way to know if the day is holiday or business day?
The most dangerous phrase in any language is:
"We always done this way"
"We always done this way"
-
- Posts: 247
- Joined: Sunday 29 November 2015 20:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.9639
- Location: Spain
- Contact:
Re: Exists a way to know if the day is holiday or business day?
Hi,
I have been looking into that a bit. Haven't found a LUA way yet but came up with this in Python
Based on https://pypi.python.org/pypi/holidays
This looks up if the current date is a Public Holiday and prints the result to screen.
Following Python libraries need to be installed : datetime, calendar and holidays
After the weekend I will finish the rest:
The print command have to be replaced with a curl command to update a switch
And in the else-part I will include a nested IF to check if the current day of week is not a Saturday or Sunday because that might of course influence if we want to activate a virtual switch.
I have been looking into that a bit. Haven't found a LUA way yet but came up with this in Python
Based on https://pypi.python.org/pypi/holidays
This looks up if the current date is a Public Holiday and prints the result to screen.
Following Python libraries need to be installed : datetime, calendar and holidays
Code: Select all
from datetime import date
#library datetime has to be installed
import holidays
#set your country
festivos = holidays.ES()
#get today's date (YYYY-MM-DD)
hoy = str(date.today())
dia = datetime.weekday(hoy)
#look up today
fiesta = str((festivos.get(hoy)))
msg = "Hoy es " + dia + hoy
print(msg)
if fiesta == "None":
print("No es festivo")
else:
print(fiesta)
The print command have to be replaced with a curl command to update a switch
And in the else-part I will include a nested IF to check if the current day of week is not a Saturday or Sunday because that might of course influence if we want to activate a virtual switch.
-
- Posts: 247
- Joined: Sunday 29 November 2015 20:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.9639
- Location: Spain
- Contact:
Re: Exists a way to know if the day is holiday or business day?
Update.
This is what I came up with.
You will also need the urllib2 so required are
* from Python: datetime, holidays, calendar and urllib2
* a virtual switch that will reflect if current day is a holiday or not
* optional, a virtual text device that will show what Holiday it is (if current day is a holiday)
* have crontab run the script once a day
I had a look at holiday.py to see if I could convert it to LUA (dzvents) but 2227 lines does not make me very eager
This is what I came up with.
You will also need the urllib2 so required are
* from Python: datetime, holidays, calendar and urllib2
* a virtual switch that will reflect if current day is a holiday or not
* optional, a virtual text device that will show what Holiday it is (if current day is a holiday)
* have crontab run the script once a day
I had a look at holiday.py to see if I could convert it to LUA (dzvents) but 2227 lines does not make me very eager
Code: Select all
from datetime import date
import holidays
import calendar
import urllib2
#set your country here. In this example ES for Spain
festivos = holidays.ES()
Hswitch=1127
Hname=1128
domoticzserver="192.168.1.6:8080"
#get today's date (YYYY-MM-DD)
hoy = date.today() #Comment this line when testing with following line Uncommented
#hoy = date(2018, 3, 30) #uncomment this line and put date that is a holiday (format = YYYY, M, D) to check if switch is updated
dia = calendar.day_name[hoy.weekday()]
#look up today in holidays
fiesta = str((festivos.get(hoy)))
fiesta = fiesta.replace(" ", "%20") #if holday name contains a space replace it with %20
if fiesta == "None":
fiesta = ""
print("No es festivo") #only visible in command line, for testing
urllib2.urlopen("http://" + str(domoticzserver) + "/json.htm?type=command¶m=switchlight&idx=" + str(Hswitch) + "&switchcmd=Off")
urllib2.urlopen("http://" + str(domoticzserver) + "/json.htm?type=command¶m=udevice&idx=" + str(Hname) + "&nvalue=0&svalue=" + str(fiesta))
else:
urllib2.urlopen("http://" + str(domoticzserver) + "/json.htm?type=command¶m=switchlight&idx=" + str(Hswitch) + "&switchcmd=On")
urllib2.urlopen("http://" + str(domoticzserver) + "/json.htm?type=command¶m=udevice&idx=" + str(Hname) + "&nvalue=0&svalue=" + str(fiesta))
print(fiesta) #only visible in command line, for testing
-
- Posts: 91
- Joined: Thursday 11 August 2016 12:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: IT
- Contact:
Re: Exists a way to know if the day is holiday or business day?
This is fantastic! I have to try it as soon as possible! Thanks.
Re: Exists a way to know if the day is holiday or business day?
Very nice plugin! I adapted for python 3.5 and for update a variable (string) instead a switch. Only holidays module is necessary, the other are already built with python35:
pip3.5 install holidays
pip3.5 install holidays
Code: Select all
#!/usr/local/bin/python3.5
from datetime import date
import holidays
import calendar
import urllib.request, urllib.error, urllib.parse
#set your country here. In this example ES for Spain
festivos = holidays.IT()
#get today's date (YYYY-MM-DD)
hoy = date.today() #Comment this line when testing with following line Uncommented
#hoy = date(2018, 3, 30) #uncomment this line and put date that is a holiday (format = YYYY, M, D) to check if switch is updated
dia = calendar.day_name[hoy.weekday()]
#look up today in holidays
fiesta = str((festivos.get(hoy)))
fiesta = fiesta.replace(" ", "%20") #if holday name contains a space replace it with %20
if fiesta == "None":
fiesta = ""
print("No es festivo") #only visible in command line, for testing
urllib.request.urlopen("http://192.168.99.51:8080/json.htm?type=command¶m=updateuservariable&vname=Giorno&vtype=2&vvalue=Feriale")
else:
urllib.request.urlopen("http://192.168.99.51:8080/json.htm?type=command¶m=updateuservariable&vname=Giorno&vtype=2&vvalue=Festivo")
print(fiesta) #only visible in command line, for testing
-
- Posts: 113
- Joined: Friday 08 January 2016 12:32
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Exists a way to know if the day is holiday or business day?
I’m sure I read aboit (some time ago) a way to do this with ifttt - linked to google calendar.
Basically, if the day contains holiday, then switch a switch in domoticz. So it would also work if you had your own holidays / annual leave etc..
not looked into it further yet but it’s on my list
Basically, if the day contains holiday, then switch a switch in domoticz. So it would also work if you had your own holidays / annual leave etc..
not looked into it further yet but it’s on my list
running domoticz 3.4834 on rpi2, with
Hue bridge / bulbs.
lightwave rf sockets, mood controlers, sensors & contacts.
Home bridge / Siri.
Ha bridge / echo Alexa.
Hard wired alarm system - setting home / away status.
Next: harmony hub.
Hue bridge / bulbs.
lightwave rf sockets, mood controlers, sensors & contacts.
Home bridge / Siri.
Ha bridge / echo Alexa.
Hard wired alarm system - setting home / away status.
Next: harmony hub.
Re: Exists a way to know if the day is holiday or business day?
Changed to default english and added a check. Now also if it's a normal sunday it appear as holiday.
Code: Select all
#!/usr/local/bin/python3.5
from datetime import date
import holidays
import calendar
import urllib.request, urllib.error, urllib.parse
#set your country here. In this example ES for Spain
holiday = holidays.IT()
#get today's date (YYYY-MM-DD)
today = date.today()
day = calendar.day_name[today.weekday()]
#look up today in holidays
bankholiday = str((holiday.get(today)))
bankholiday = bankholiday.replace(" ", "%20") #if holday name contains a space replace it with %20
if bankholiday == "None":
bankholiday = ""
if day == "Sunday":
urllib.request.urlopen("http://192.168.99.51:8080/json.htm?type=command¶m=updateuservariable&vname=Giorno_Festivo&vtype=2&vvalue=Si")
else:
urllib.request.urlopen("http://192.168.99.51:8080/json.htm?type=command¶m=updateuservariable&vname=Giorno_Festivo&vtype=2&vvalue=No")
else:
urllib.request.urlopen("http://192.168.99.51:8080/json.htm?type=command¶m=updateuservariable&vname=Giorno_Festivo&vtype=2&vvalue=Si")
- EdwinK
- Posts: 1820
- Joined: Sunday 22 January 2017 21:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: BETA
- Location: Rhoon
- Contact:
Re: Exists a way to know if the day is holiday or business day?
Can it update a text-box with the name of the holiday? Something like 'Today is Easter'.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Exists a way to know if the day is holiday or business day?
Please find an answer on your question In this topic
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- EdwinK
- Posts: 1820
- Joined: Sunday 22 January 2017 21:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: BETA
- Location: Rhoon
- Contact:
Re: Exists a way to know if the day is holiday or business day?
Found it, did it, and works
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
-
- Posts: 1
- Joined: Sunday 24 February 2019 17:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Exists a way to know if the day is holiday or business day?
Calendarific allows you to get bank and public holidays information for over 230 countries via a simple json api. I think for what you want to do, you should be able to use it.
https://calendarific.com
https://calendarific.com/api-documentation
https://calendarific.com
https://calendarific.com/api-documentation
Who is online
Users browsing this forum: Bing [Bot] and 1 guest