Get Shabbat Times From Hebcal API Custom Sensor


I’ve made a custom platform sensor which creates multiple sensors for multiple cities around the world, available in my git hub repository.

Based on the data retrieved from the sensors created by the custom platform shabbat_times,
I was able to create two template sensors that shows the value of the start and end attributes in the new sensors based on a designated input_select.

The result:

The configuration:
First of all, add the custom component into your configuration following the instructions on my git hub repository.

Updated your configuration files:

# configuration.yaml

  - platform: shabbat_times
    geonames: "IL-Haifa,IL-Rishon LeZion"
    candle_lighting_minutes_before_sunset: 0
    havdalah_minutes_after_sundown: 40
  - platform: template
        value_template: >
          {% if states.input_select.select_shabbat_city.state == "Haifa" %}{{ states.sensor.shabbat_times_il_haifa.attributes.shabbat_start }}
          {% elif states.input_select.select_shabbat_city.state == "Rishon LeZion" %}{{ states.sensor.shabbat_times_il_rishon_lezion.attributes.shabbat_start }}
        value_template: >
          {% if states.input_select.select_shabbat_city.state == "Haifa" %}{{ states.sensor.shabbat_times_il_haifa.attributes.shabbat_end }}
          {% elif states.input_select.select_shabbat_city.state == "Rishon LeZion" %}{{ states.sensor.shabbat_times_il_rishon_lezion.attributes.shabbat_end }}

    name: select_shabbat_city
      - Haifa
      - Rishon LeZion
# groups.yaml

  name: shabbat_times
    - input_select.select_shabbat_city
    - sensor.select_city_shabbat_start_time
    - sensor.select_city_shabbat_end_time

  view: yes
    - group.shabbat_times
# customize.yaml

  hidden: true
  hidden: true
  friendly_name: "Shabbat Starts At"
  icon: mdi:clock-start
  friendly_name: "Shabbat Ends At"
  icon: mdi:clock-end
  friendly_name: "Shabbat Times"

Very elegant, way to go :sunny: !

1 Like

Could it be suggested as another component for the next release @TomerFi @fabaff @balloob ?


I came up with a modified version of this that uses latitude and longitude and adds in the Parasha for the week.

1 Like

That’s cool!

I also thought it would be fun adding a service that allows you to update the long & lat per request,
that way you can update the same sensor according to a device from your device tracker and get the shabbat data based on the location of your device.

It also occurs to me that, since this is calculated against sunset, something that Home Assistant already has a library for, it might be doable without calling on Hebcal.

Actually you are right, I didn’t thought of that.
Great idea!

Well, you have the Google Geocode custom component. You should be able to look at how it pulls the device tracker info and incorporate that in. But both a fixed and a device one make sense if you consider varying use cases, if you consider submitting it to HA as a more permanent component. One covers the traditional use case…automating your home, which is a fixed location. The other covers the dashboard function.

I don’t have much experience programming in Python…but I had a look at the sunset code, and they include a python library called Astral. It looks straightforward enough to calculate based on location. Alternatively, the current sun component only seems to allow the sun to be calculated for the default location. If it was extended to allow for multiple locations, then there would be a broader use case.

If you wanted to add Yom Tov, you could in theory, download a list of holidays from Hebcal on initialize and search for the next date.

You can get the latitude and longitude from the device state attributes.
But I think the sun component is based on the latitude and longitude from the Home Assistant configuration, I have no idea if you can configure it for a different latitude and longitude.
I haven’t used this component.

You can’t. Using the Home Assistant configuration longitude and latitude is hard-coded and would have to be extended. But the library it uses is already bundled into the package, so it would work if used for another component.

1 Like

hello! I was wondering if anyone used this sensor to trigger an automation. I’m having trouble setting one up based on the shabbat start and end times. Thanks!

I haven’t tried it, but if you’ll post your automation here, maybe I can help…

Hi! Thanks for getting this started. I have forked your repository and have been working on many, many improvements locally and have only now gotten back to posting them on github.

Some features I’ve added:

  • Support for Yom Tov
  • Reading the English & Hebrew parasha from Hebcal
  • Support for restoring the state of the sensor upon HA restart (so you don’t constantly have to requery HebCal)
  • Very detailed handling of many edge cases - it turns out 2018 had a lot of weird exceptional cases, e.g. Shabbat starting in one month and ending in another, two-day Yom Tov starting in September and ending in October, etc.
  • Simple unit tests (not using tox, just pure python for now) using cached Hebcal data – ensuring the correctness of this if you are relying on it for Shabbat automation is highly important!
  • Probably some other things I forgot to mention

I also added to the README an example of my template sensor for “Shabbat Mode” as well as a sample automation that runs when Shabbat Mode begins.

Please feel free to check out my github repo to download this. I haven’t tested this on an environment outside my own, so please do let me know if you run into any issues!

@TomerFi - I’d love to start integrating this as a full-fledged component into HA. I saw there was recently a Jewish Calendar sensor added using HDate but that one does not appear to be as robust and full-featured as this version is. WDYT, is it ok with you to go ahead and start integrating it?

1 Like

I would like Shabbat mode sensor in my HA installation as well… Python isn’t my thing, but am willing to help.

Toda Raba Achi!
Thanks this is just what I was looking for - I made an automation for 18 minutes before sunset etc but the Chagim option is brilliant. Thank you!

Not exactly on topic, but have you worked out a way to incorporate the Red Alert/pikud haoref alarm as a sensor? I’d love to flash the lights in the house when the alarm goes off, in case someone is in the shower or is not sure if they heard the alarm.

I hacked together a node red flow from but it seemed to be delayed which didnt work well for us.

Bevakasha :slight_smile: One thing to note - part of the configuration of the Shabbat Times sensor includes a setting for minutes-before-candlelighting - so if you set that to 18, your shabbat_start time should actually include the 18 minutes; in that case if you wanted an actual start-of-Shabbat automation you’d need to add 18 minutes to that time.

Your idea for flashing the lights for the Red Alert sounds like a brilliant application, though since I am in the US it hasn’t been applicable. But, looking at Pikud Haoref’s site, it looks like there’s probably a way to do it – if you look at it seems you can at least list out the alerts for a day - there’s got to be a way to access this via URL and parse it. Might require some experimentation, but it’s possible there’s some way of getting that data out…

Oh wow sorry about that, I figured with your example cities that you lived here:)

With some poking around I found the live stream is at

Now I gotta figure out how to read the live data from that stream and parse out my areas - I might have to hire a programmer to give me a hand with it.

Thanks for this great Shabbat sensor!

hi all!
so sorry for the delayed response… i had tons going on:
I’m attaching my automations file hereautomations.yaml (1.6 KB)
Basically, I create a boolean that trigers when it’s shabbat and yom tov and that should trigger the automation… it configered correctly and hassio doesn’t show any errors but for some reason, it’s not working but at least it’s somewhere to start?

1 Like