4 * Author: danielbarak@live.com
8 // Automatically generated. Make future change here.
10 name: "Shabbat and Holiday Modes",
11 namespace: "ShabbatHolidayMode",
12 author: "danielbarak@live.com",
13 description: "Changes the mode at candle lighting and back after havdalah. Uses the HebCal.com API to look for days that are shabbat or chag and pull real time candle lighting and havdalah times to change modes automatically",
15 iconUrl: "http://upload.wikimedia.org/wikipedia/commons/thumb/4/49/Star_of_David.svg/200px-Star_of_David.svg.png",
16 iconX2Url: "http://upload.wikimedia.org/wikipedia/commons/thumb/4/49/Star_of_David.svg/200px-Star_of_David.svg.png",
17 iconX3Url: "http://upload.wikimedia.org/wikipedia/commons/thumb/4/49/Star_of_David.svg/200px-Star_of_David.svg.png")
21 section("At Candlelighting Change Mode To:")
23 input "startMode", "mode", title: "Mode?"
25 section("At Havdalah Change Mode To:")
27 input "endMode", "mode", title: "Mode?"
29 section("Havdalah Offset (Usually 50 or 72)") {
30 input "havdalahOffset", "number", title: "Minutes After Sundown", required:true
32 section("Your ZipCode") {
33 input "zipcode", "text", title: "ZipCode", required:true
35 section( "Notifications" ) {
36 input "sendPushMessage", "enum", title: "Send a push notification?", metadata:[values:["Yes","No"]], required:false
37 input "phone", "phone", title: "Send a Text Message?", required: false
43 log.debug "Installed with settings: ${settings}"
48 log.debug "Updated with settings: ${settings}"
55 schedule("0 0 8 1/1 * ? *", poll)
58 //Check hebcal for today's candle lighting or havdalah
70 /**********************************************
72 -----------------------------------------------*/
74 //This function is the web request and response parse
75 def Hebcal_WebRequest(){
77 def today = new Date().format("yyyy-MM-dd")
78 //def today = "2014-11-14"
79 def zip = settings.zip as String
80 def locale = getWeatherFeature("geolookup", zip)
81 def timezone = TimeZone.getTimeZone(locale.location.tz_long)
86 def candlelightingLocalTime
91 def urlRequest = "http://www.hebcal.com/hebcal/?v=1&cfg=json&nh=off&nx=off&year=now&month=now&mf=off&c=on&zip=${zipcode}&m=${havdalahOffset}&s=off&D=off&d=off&o=off&ss=off"
92 log.trace "${urlRequest}"
94 def hebcal = { response ->
95 hebcal_date = response.data.items.date
96 hebcal_category = response.data.items.category
97 hebcal_title = response.data.items.title
99 for (int i = 0; i < hebcal_date.size; i++)
101 if(hebcal_date[i].split("T")[0]==today)
103 if(hebcal_category[i]=="candles")
105 candlelightingLocalTime = HebCal_GetTime12(hebcal_title[i])
106 pushMessage = "Candle Lighting is at ${candlelightingLocalTime}"
107 candlelightingLocalTime = HebCal_GetTime24(hebcal_date[i])
108 candlelighting = timeToday(candlelightingLocalTime, timezone)
110 sendMessage(pushMessage)
111 schedule(candlelighting, setChag)
112 log.debug pushMessage
113 }//END if(hebcal_category=="candles")
115 else if(hebcal_category[i]=="havdalah")
117 havdalahLocalTime = HebCal_GetTime12(hebcal_title[i])
118 pushMessage = "Havdalah is at ${havdalahLocalTime}"
119 havdalahLocalTime = HebCal_GetTime24(hebcal_date[i])
120 havdalah = timeToday(havdalahLocalTime, timezone)
121 testmessage = "Scheduling for ${havdalah}"
122 schedule(havdalah, endChag)
123 log.debug pushMessage
124 log.debug testmessage
125 }//END if(hebcal_category=="havdalah"){
126 }//END if(hebcal_date[i].split("T")[0]==today)
128 }//END for (int i = 0; i < hebcal_date.size; i++)
129 }//END def hebcal = { response ->
130 httpGet(urlRequest, hebcal);
131 }//END def queryHebcal()
134 //This function gets candle lighting time
135 def HebCal_GetTime12(hebcal_title){
136 def returnTime = hebcal_title.split(":")[1] + ":" + hebcal_title.split(":")[2] + " "
138 }//END def HebCal_GetTime12()
140 //This function gets candle lighting time
141 def HebCal_GetTime24(hebcal_date){
142 def returnTime = hebcal_date.split("T")[1]
143 returnTime = returnTime.split("-")[0]
145 }//END def HebCal_GetTime12()
147 /*-----------------------------------------------
148 END OF HEBCAL FUNCTIONS
149 -----------------------------------------------*/
153 if (location.mode != startMode)
155 if (location.modes?.find{it.name == startMode})
157 setLocationMode(startMode)
158 //sendMessage("Changed the mode to '${startMode}'")
159 def dayofweek = new Date().format("EEE")
160 if(dayofweek=='Fri'){
161 sendMessage("Shabbat Shalom!")
164 sendMessage("Chag Sameach!")
167 }//END if (location.modes?.find{it.name == startMode})
170 sendMessage("Tried to change to undefined mode '${startMode}'")
172 }//END if (location.mode != newMode)
174 unschedule("setChag")
181 if (location.mode != endMode)
183 if (location.modes?.find{it.name == endMode})
185 setLocationMode(endMode)
186 sendMessage("Changed the mode to '${endMode}'")
187 }//END if (location.modes?.find{it.name == endMode})
190 sendMessage("Tried to change to undefined mode '${endMode}'")
192 }//END if (location.mode != endMode)
194 //sendMessage("Shavuah Tov!")
195 unschedule("endChag")
198 def sendMessage(msg){
199 if ( sendPushMessage != "No" ) {
200 log.debug( "sending push message" )
205 log.debug( "sending text message" )
206 sendSms( phone, msg )
208 }//END def sendMessage(msg)