Creating an api driven time based event

Hi there, I'm new here! I have an API that returns a time of day and would like to use it as a value to trigger an event at that time on a specific day of the week. How would I go about doing this?

You would need a custom driver or app to query the api
Does the api return data in a JSON format?

Can you give us an example of the returned data?

Sure. In this case

{
   "title":"São Paulo, Brazil",
   "date":"2019-07-30T07:23:09-00:00",
   "link":"https://www.hebcal.com/shabbat/?geonameid=3448439;m=50;maj=on;min=on;mod=on;mf=on;ss=on;nx=on;c=on;geo=geoname",
   "location":{
      "tzid":"America/Sao_Paulo",
      "geonameid":3448439,
      "latitude":-23.5475,
      "country":"Brazil",
      "admin1":"São Paulo",
      "longitude":-46.63611,
      "geo":"geoname",
      "city":"São Paulo",
      "asciiname":"Sao Paulo",
      "title":"São Paulo, Brazil"
   },
   "items":[
      {
         "hebrew":"ראש חודש אב",
         "date":"2019-08-02",
         "title":"Rosh Chodesh Av",
         "memo":"Beginning of new Hebrew month of Av",
         "category":"roshchodesh",
         "link":"https://www.hebcal.com/holidays/rosh-chodesh-av"
      },
      {
         "title":"Candle lighting: 5:26pm",
         "date":"2019-08-02T17:26:00-03:00",
         "hebrew":"הדלקת נרות",
         "category":"candles"
      },
    ]
}

is the total payload. I would want to grab (please forgive my hacky entity extraction...) payload.items and use the value of "date" where {"category":"candles"}.

In case you're wondering, the use case is to turn the house down a few minutes before the Jewish Sabbath starts.

Not the answer to your actual question, but I would use Node-Red for that and have it trigger a virtual switch via MakerAPI. Would be very simple to setup, as Node-Red can easily fetch and parse json with little/no code at all.

I would create a virtual switch driver to query the api site with a sort of 'if today is Shabbat then turn on'

Andy

Have a look at the code in one of my weather drivers.. or better still my Holiday switch driver

1 Like

I don't know if it will help you, but there is an old SmartThings SmartApp that uses the Hebcal API to put your home into 'Shabbat mode'. Maybe the code in there can give you some ideas.

Shabbat and Holiday Modes

1 Like

Thanks! Ported to hubitat! https://github.com/Dannyzen/hubitat_shabbat/blob/master/shabbat-and-holiday-modes.groovy

1 Like