Error in jewish_calendar integration - Python Math ValueError thrown?

Please forward to maintainer.

Jewish Calendar Integration produces this and other errors as it seems to not be finding the maths Sin/Cos/Tan etc routines from Python. I’m running the latest version 2021.6.3 on a PI4 using HA OS. This is the first error but it occurs several times for each different time / location based calculation. I’m UK based with config:

jewish_calendar:
   language: english
   diaspora: true
   candle_lighting_minutes_before_sunset: 18
   havdalah_minutes_after_sunset: 50

lattitude: 53.4***** - 5 digits removed  
longitude: -2.2*****

=====Log Output ===========================

Logger: homeassistant.helpers.entity
Source: components/jewish_calendar/sensor.py:184
First occurred: 2:43:37 PM (13 occurrences)
Last logged: 2:49:37 PM

Update for sensor.jewish_calendar_upcoming_havdalah fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 350, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 558, in async_device_update
    raise exc
  File "/usr/src/homeassistant/homeassistant/components/jewish_calendar/sensor.py", line 100, in async_update
    self._state = self.get_state(daytime_date, after_shkia_date, after_tzais_date)
  File "/usr/src/homeassistant/homeassistant/components/jewish_calendar/sensor.py", line 184, in get_state
    return times.havdalah
  File "/usr/local/lib/python3.8/site-packages/hdate/zmanim.py", line 186, in havdalah
    return self._havdalah_datetime
  File "/usr/local/lib/python3.8/site-packages/hdate/zmanim.py", line 160, in _havdalah_datetime
    return self.zmanim["three_stars"]
  File "/usr/local/lib/python3.8/site-packages/hdate/zmanim.py", line 130, in zmanim
    for key, value in self.utc_zmanim.items()
  File "/usr/local/lib/python3.8/site-packages/hdate/zmanim.py", line 122, in utc_zmanim
    for key, value in self.get_utc_sun_time_full().items()
  File "/usr/local/lib/python3.8/site-packages/hdate/zmanim.py", line 313, in get_utc_sun_time_full
    first_light = self._get_utc_time_of_transit(106.1, True)
  File "/usr/local/lib/python3.8/site-packages/hdate/zmanim.py", line 295, in _get_utc_time_of_transit
    return self._datetime_to_minutes_offest(astral.sun.time_of_transit(
  File "/usr/local/lib/python3.8/site-packages/astral/sun.py", line 343, in time_of_transit
    hourangle = hour_angle(
  File "/usr/local/lib/python3.8/site-packages/astral/sun.py", line 243, in hour_angle
    HA = acos(h)
ValueError: math domain error

Spelling of “latitude” perhaps?

Ah, I think if I quote @tsvi. This goes to the author of the code? Please see my possible typo or bug giving Python ValueError in the sun elevation calculations: Error in jewish_calendar integration - Python Math ValueError thrown?

Thanks Troon, I checked the spelling of “latitude” in my real config is correct and loads correctly.

The integration takes the Home Assistant location by default. But on looking again, they are float in the general config but specified as integer for this integration. This looks like a bug or possibly a place where the integration author decided that too much accuracy was not essential? Away from the equator the difference in times for integer vs float values will grow as you get nearer the poles making fixed point or float values essential. Anyway, I just tested it with explicit closest integer values and it makes no difference to the error.

Yes, thanks for quoting me.
I’ll try to take a look at it. Float to integer doesn’t make sense here as no casting is done.

Which type of installation is this? Docker? Core? Full HA?
What version of Python?
If possible could you open a GitHub issue in the home assistant repo with the details and tag me?

Ok, I see this has to do with the value being passed to astral to calculate the values.
So yes, this seems an issue with the specific values for latitude/longitude. I’ll try to run a few tests.

Thank you very much.

Thanks. Input as a Issue with HA Core with your name at the top for assignment. I replaced my latitude and longitude with Jerusalem and it all works OK. My latitude is around 53 but there are more Northerly communities and probably southerly in South America.

The most Northerly Jewish Community in Europe is Trondheim in Norway: latitude 63.434570 and longitude 10.398440. North of Trondheim people use Trondheim times as it is close to but below the Arctic Circle, so Shabbat does manage to go out in the summer! It is possible that in Alaska USA there may be more northerly communities nowadays?

Hopefully a simple one to fix! To’da

Nick