Exists a way to know if the day is holiday or business day?

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.
Post Reply
bigpea
Posts: 121
Joined: Thursday 11 August 2016 12:30
Target OS: Raspberry Pi
Domoticz version:
Location: IT
Contact:

Exists a way to know if the day is holiday or business day?

Post by bigpea » Thursday 11 January 2018 11:05

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.

User avatar
emme
Posts: 956
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Exists a way to know if the day is holiday or business day?

Post by emme » Thursday 11 January 2018 11:20

as a workaround... what about a table like:

Code: Select all

isHoliday = {}

isHoliday['0101'] = 'New Year'
isHoliday['0104'] = 'Easter'
isHoliday['0105'] = 'Labour Day'
...
(maybe into an external file so all scripts can use it)

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
of course you will need to update it every year :P

it would be nice to include this into domoticz :P
The most dangerous phrase in any language is:
"We always done this way"

bigpea
Posts: 121
Joined: Thursday 11 August 2016 12:30
Target OS: Raspberry Pi
Domoticz version:
Location: IT
Contact:

Re: Exists a way to know if the day is holiday or business day?

Post by bigpea » Thursday 11 January 2018 11:37

yes, nice, but inconvenient to do this job every year..

User avatar
waaren
Posts: 1348
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Exists a way to know if the day is holiday or business day?

Post by waaren » Thursday 11 January 2018 11:45

I use a bash script (triggered daily by cron) to do this.

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&param=updateuservariable&vname=MyVarName&vtype=0&vvalue=1"
fi

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
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

bigpea
Posts: 121
Joined: Thursday 11 August 2016 12:30
Target OS: Raspberry Pi
Domoticz version:
Location: IT
Contact:

Re: Exists a way to know if the day is holiday or business day?

Post by bigpea » Thursday 11 January 2018 12:00

I like this, I will try it! Thanks.

User avatar
Siewert308SW
Posts: 621
Joined: Monday 29 December 2014 16:47
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands - Zoutkamp (gn)
Contact:

Re: Exists a way to know if the day is holiday or business day?

Post by Siewert308SW » Thursday 11 January 2018 12:05

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

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:
- RPi3 - PIco HV3.0A / Domo Beta 3.9XXX / RFXtrx433E / Aeotec Gen5
- RPi3 - PIco HV3.0A / PiHole / PiVPN / NAS / Print Server
- Youless Elec&Gas
- FI9803P Cams
- KD101 detectors
- Zwave & KaKu

MyDomoticz scripts: @GitHub
PIco UPS Toolkit: @GitHub

User avatar
emme
Posts: 956
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Exists a way to know if the day is holiday or business day?

Post by emme » Thursday 11 January 2018 12:14

also found this:
https://holidayapi.com/
which require a registration :P
The most dangerous phrase in any language is:
"We always done this way"

elmortero
Posts: 241
Joined: Sunday 29 November 2015 21:46
Target OS: Raspberry Pi
Domoticz version: 3.9639
Location: Spain
Contact:

Re: Exists a way to know if the day is holiday or business day?

Post by elmortero » Friday 12 January 2018 16:58

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

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)
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.

elmortero
Posts: 241
Joined: Sunday 29 November 2015 21:46
Target OS: Raspberry Pi
Domoticz version: 3.9639
Location: Spain
Contact:

Re: Exists a way to know if the day is holiday or business day?

Post by elmortero » Saturday 13 January 2018 21:44

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 :D

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&param=switchlight&idx=" + str(Hswitch) + "&switchcmd=Off")
	urllib2.urlopen("http://" + str(domoticzserver) + "/json.htm?type=command&param=udevice&idx=" + str(Hname) + "&nvalue=0&svalue=" + str(fiesta))
else:
	urllib2.urlopen("http://" + str(domoticzserver) + "/json.htm?type=command&param=switchlight&idx=" + str(Hswitch) + "&switchcmd=On")
	urllib2.urlopen("http://" + str(domoticzserver) + "/json.htm?type=command&param=udevice&idx=" + str(Hname) + "&nvalue=0&svalue=" + str(fiesta))
	print(fiesta) #only visible in command line, for testing



bigpea
Posts: 121
Joined: Thursday 11 August 2016 12:30
Target OS: Raspberry Pi
Domoticz version:
Location: IT
Contact:

Re: Exists a way to know if the day is holiday or business day?

Post by bigpea » Saturday 13 January 2018 23:37

This is fantastic! I have to try it as soon as possible! Thanks.

TheCondor
Posts: 67
Joined: Thursday 18 June 2015 10:32
Target OS: Linux
Domoticz version:
Contact:

Re: Exists a way to know if the day is holiday or business day?

Post by TheCondor » Wednesday 25 April 2018 23:06

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

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&param=updateuservariable&vname=Giorno&vtype=2&vvalue=Feriale")
else:
 urllib.request.urlopen("http://192.168.99.51:8080/json.htm?type=command&param=updateuservariable&vname=Giorno&vtype=2&vvalue=Festivo")
 print(fiesta) #only visible in command line, for testing


sion
Posts: 122
Joined: Friday 08 January 2016 13:32
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Exists a way to know if the day is holiday or business day?

Post by sion » Thursday 26 April 2018 1:16

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 ;)
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.

TheCondor
Posts: 67
Joined: Thursday 18 June 2015 10:32
Target OS: Linux
Domoticz version:
Contact:

Re: Exists a way to know if the day is holiday or business day?

Post by TheCondor » Sunday 29 April 2018 10:05

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&param=updateuservariable&vname=Giorno_Festivo&vtype=2&vvalue=Si")
 else:
  urllib.request.urlopen("http://192.168.99.51:8080/json.htm?type=command&param=updateuservariable&vname=Giorno_Festivo&vtype=2&vvalue=No")
else:
 urllib.request.urlopen("http://192.168.99.51:8080/json.htm?type=command&param=updateuservariable&vname=Giorno_Festivo&vtype=2&vvalue=Si")
 

User avatar
EdwinK
Posts: 1402
Joined: Sunday 22 January 2017 22:46
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Exists a way to know if the day is holiday or business day?

Post by EdwinK » Thursday 19 July 2018 17:02

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) | RFxcom | Dashticz V2

User avatar
waaren
Posts: 1348
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Exists a way to know if the day is holiday or business day?

Post by waaren » Friday 20 July 2018 0:36

EdwinK wrote:
Thursday 19 July 2018 17:02
Can it update a text-box with the name of the holiday? Something like 'Today is Easter'.
Please find an answer on your question In this topic
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

User avatar
EdwinK
Posts: 1402
Joined: Sunday 22 January 2017 22:46
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Exists a way to know if the day is holiday or business day?

Post by EdwinK » Friday 20 July 2018 16:34

Found it, did it, and works ;)
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | RFxcom | Dashticz V2

zak45
Posts: 574
Joined: Sunday 22 January 2017 12:37
Target OS: Windows
Domoticz version: V4.10171
Contact:

Re: Exists a way to know if the day is holiday or business day?

Post by zak45 » Thursday 02 August 2018 15:15


Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests