Skip to content

Instantly share code, notes, and snippets.

@SLaks
Last active May 19, 2026 14:58
Show Gist options
  • Select an option

  • Save SLaks/9c55b0fa434532cbb5999f7461240a26 to your computer and use it in GitHub Desktop.

Select an option

Save SLaks/9c55b0fa434532cbb5999f7461240a26 to your computer and use it in GitHub Desktop.
Home Assistant Shabbos Sensors
template:
- sensor:
# Changes at צאת הכוכבים, when it's actually time to count the next day.
# Use this everywhere instead of the standard sensor.
- name: "Effective Day of Omer"
icon: mdi:barley
state: |
{%- set day = states('sensor.jewish_calendar_day_of_the_omer') | int -%}
{{
day - 1 if day > 0
and states('sensor.jewish_calendar_shkia') | as_datetime
<= now() <= states('sensor.jewish_calendar_t_set_hakochavim') | as_datetime
else day
}}
- name: Omer Text
unique_id: omer_text
icon: mdi:barley
state: |
{%- if not is_state('sensor.effective_day_of_omer', ['0', 'unknown']) -%}
{%- set texts = [
"הַיּוֹם יוֹם אֶחָד לָעֽוֹמֶר",
"הַיּוֹם שְׁנֵי יָמִים לָעֽוֹמֶר",
"הַיּוֹם שְׁלוֹשָׁה יָמִים לָעֽוֹמֶר",
"הַיּוֹם אַרְבָּעָה יָמִים לָעֽוֹמֶר",
"הַיּוֹם חֲמִשָּׁה יָמִים לָעֽוֹמֶר",
"הַיּוֹם שִׁשָּׁה יָמִים לָעֽוֹמֶר",
"הַיּוֹם שִׁבְעָה יָמִים, שֶׁהֵם שָׁבֽוּעַ אֶחָד לָעֽוֹמֶר",
"הַיּוֹם שְׁמוֹנָה יָמִים, שֶׁהֵם שָׁבֽוּעַ אֶחָד וְיוֹם אֶחָד לָעֽוֹמֶר",
"הַיּוֹם תִּשְׁעָה יָמִים, שֶׁהֵם שָׁבֽוּעַ אֶחָד וּשְׁנֵי יָמִים לָעֽוֹמֶר",
"הַיּוֹם עֲשָׂרָה יָמִים, שֶׁהֵם שָׁבֽוּעַ אֶחָד וּשְׁלוֹשָׁה יָמִים לָעֽוֹמֶר",
"הַיּוֹם אַחַד עָשָׂר יוֹם, שֶׁהֵם שָׁבֽוּעַ אֶחָד וְאַרְבָּעָה יָמִים לָעֽוֹמֶר",
"הַיּוֹם שְׁנֵים עָשָׂר יוֹם, שֶׁהֵם שָׁבֽוּעַ אֶחָד וַחֲמִשָּׁה יָמִים לָעֽוֹמֶר",
"הַיּוֹם שְׁלוֹשָׁה עָשָׂר יוֹם, שֶׁהֵם שָׁבֽוּעַ אֶחָד וְשִׁשָּׁה יָמִים לָעֽוֹמֶר",
"הַיּוֹם אַרְבָּעָה עָשָׂר יוֹם, שֶׁהֵם שְׁנֵי שָׁבוּעוֹת לָעֽוֹמֶר",
"הַיּוֹם חֲמִשָּׁה עָשָׂר יוֹם, שֶׁהֵם שְׁנֵי שָׁבוּעוֹת וְיוֹם אֶחָד לָעֽוֹמֶר",
"הַיּוֹם שִׁשָּׁה עָשָׂר יוֹם, שֶׁהֵם שְׁנֵי שָׁבוּעוֹת וּשְׁנֵי יָמִים לָעֽוֹמֶר",
"הַיּוֹם שִׁבְעָה עָשָׂר יוֹם, שֶׁהֵם שְׁנֵי שָׁבוּעוֹת וּשְׁלוֹשָׁה יָמִים לָעֽוֹמֶר",
"הַיּוֹם שְׁמוֹנָה עָשָׂר יוֹם, שֶׁהֵם שְׁנֵי שָׁבוּעוֹת וְאַרְבָּעָה יָמִים לָעֽוֹמֶר",
"הַיּוֹם תִּשְׁעָה עָשָׂר יוֹם, שֶׁהֵם שְׁנֵי שָׁבוּעוֹת וַחֲמִשָּׁה יָמִים לָעֽוֹמֶר",
"הַיּוֹם עֶשְׂרִים יוֹם, שֶׁהֵם שְׁנֵי שָׁבוּעוֹת וְשִׁשָּׁה יָמִים לָעֽוֹמֶר",
"הַיּוֹם אֶחָד וְעֶשְׂרִים יוֹם, שֶׁהֵם שְׁלוֹשָׁה שָׁבוּעוֹת לָעֽוֹמֶר",
"הַיּוֹם שְׁנַיִם וְעֶשְׂרִים יוֹם, שֶׁהֵם שְׁלוֹשָׁה שָׁבוּעוֹת וְיוֹם אֶחָד לָעֽוֹמֶר",
"הַיּוֹם שְׁלוֹשָׁה וְעֶשְׂרִים יוֹם, שֶׁהֵם שְׁלוֹשָׁה שָׁבוּעוֹת וּשְׁנֵי יָמִים לָעֽוֹמֶר",
"הַיּוֹם אַרְבָּעָה וְעֶשְׂרִים יוֹם, שֶׁהֵם שְׁלוֹשָׁה שָׁבוּעוֹת וּשְׁלוֹשָׁה יָמִים לָעֽוֹמֶר",
"הַיּוֹם חֲמִשָּׁה וְעֶשְׂרִים יוֹם, שֶׁהֵם שְׁלוֹשָׁה שָׁבוּעוֹת וְאַרְבָּעָה יָמִים לָעֽוֹמֶר",
"הַיּוֹם שִׁשָּׁה וְעֶשְׂרִים יוֹם, שֶׁהֵם שְׁלוֹשָׁה שָׁבוּעוֹת וַחֲמִשָּׁה יָמִים לָעֽוֹמֶר",
"הַיּוֹם שִׁבְעָה וְעֶשְׂרִים יוֹם, שֶׁהֵם שְׁלוֹשָׁה שָׁבוּעוֹת וְשִׁשָּׁה יָמִים לָעֽוֹמֶר",
"הַיּוֹם שְׁמוֹנָה וְעֶשְׂרִים יוֹם, שֶׁהֵם אַרְבָּעָה שָׁבוּעוֹת לָעֽוֹמֶר",
"הַיּוֹם תִּשְׁעָה וְעֶשְׂרִים יוֹם, שֶׁהֵם אַרְבָּעָה שָׁבוּעוֹת וְיוֹם אֶחָד לָעֽוֹמֶר",
"הַיּוֹם שְׁלוֹשִׁים יוֹם, שֶׁהֵם אַרְבָּעָה שָׁבוּעוֹת וּשְׁנֵי יָמִים לָעֽוֹמֶר",
"הַיּוֹם אֶחָד וּשְׁלוֹשִׁים יוֹם, שֶׁהֵם אַרְבָּעָה שָׁבוּעוֹת וּשְׁלוֹשָׁה יָמִים לָעֽוֹמֶר",
"הַיּוֹם שְׁנַיִם וּשְׁלוֹשִׁים יוֹם, שֶׁהֵם אַרְבָּעָה שָׁבוּעוֹת וְאַרְבָּעָה יָמִים לָעֽוֹמֶר",
"הַיּוֹם שְׁלוֹשָׁה וּשְׁלוֹשִׁים יוֹם, שֶׁהֵם אַרְבָּעָה שָׁבוּעוֹת וַחֲמִשָּׁה יָמִים לָעֽוֹמֶר",
"הַיּוֹם אַרְבָּעָה וּשְׁלוֹשִׁים יוֹם, שֶׁהֵם אַרְבָּעָה שָׁבוּעוֹת וְשִׁשָּׁה יָמִים לָעֽוֹמֶר",
"הַיּוֹם חֲמִשָּׁה וּשְׁלוֹשִׁים יוֹם, שֶׁהֵם חֲמִשָּׁה שָׁבוּעוֹת לָעֽוֹמֶר",
"הַיּוֹם שִׁשָּׁה וּשְׁלוֹשִׁים יוֹם, שֶׁהֵם חֲמִשָּׁה שָׁבוּעוֹת וְיוֹם אֶחָד לָעֽוֹמֶר",
"הַיּוֹם שִׁבְעָה וּשְׁלוֹשִׁים יוֹם, שֶׁהֵם חֲמִשָּׁה שָׁבוּעוֹת וּשְׁנֵי יָמִים לָעֽוֹמֶר",
"הַיּוֹם שְׁמוֹנָה וּשְׁלוֹשִׁים יוֹם, שֶׁהֵם חֲמִשָּׁה שָׁבוּעוֹת וּשְׁלוֹשָׁה יָמִים לָעֽוֹמֶר",
"הַיּוֹם תִּשְׁעָה וּשְׁלוֹשִׁים יוֹם, שֶׁהֵם חֲמִשָּׁה שָׁבוּעוֹת וְאַרְבָּעָה יָמִים לָעֽוֹמֶר",
"הַיּוֹם אַרְבָּעִים יוֹם, שֶׁהֵם חֲמִשָּׁה שָׁבוּעוֹת וַחֲמִשָּׁה יָמִים לָעֽוֹמֶר",
"הַיּוֹם אֶחָד וְאַרְבָּעִים יוֹם, שֶׁהֵם חֲמִשָּׁה שָׁבוּעוֹת וְשִׁשָּׁה יָמִים לָעֽוֹמֶר",
"הַיּוֹם שְׁנַיִם וְאַרְבָּעִים יוֹם, שֶׁהֵם שִׁשָּׁה שָׁבוּעוֹת לָעֽוֹמֶר",
"הַיּוֹם שְׁלוֹשָׁה וְאַרְבָּעִים יוֹם, שֶׁהֵם שִׁשָּׁה שָׁבוּעוֹת וְיוֹם אֶחָד לָעֽוֹמֶר",
"הַיּוֹם אַרְבָּעָה וְאַרְבָּעִים יוֹם, שֶׁהֵם שִׁשָּׁה שָׁבוּעוֹת וּשְׁנֵי יָמִים לָעֽוֹמֶר",
"הַיּוֹם חֲמִשָּׁה וְאַרְבָּעִים יוֹם, שֶׁהֵם שִׁשָּׁה שָׁבוּעוֹת וּשְׁלוֹשָׁה יָמִים לָעֽוֹמֶר",
"הַיּוֹם שִׁשָּׁה וְאַרְבָּעִים יוֹם, שֶׁהֵם שִׁשָּׁה שָׁבוּעוֹת וְאַרְבָּעָה יָמִים לָעֽוֹמֶר",
"הַיּוֹם שִׁבְעָה וְאַרְבָּעִים יוֹם, שֶׁהֵם שִׁשָּׁה שָׁבוּעוֹת וַחֲמִשָּׁה יָמִים לָעֽוֹמֶר",
"הַיּוֹם שְׁמוֹנָה וְאַרְבָּעִים יוֹם, שֶׁהֵם שִׁשָּׁה שָׁבוּעוֹת וְשִׁשָּׁה יָמִים לָעֽוֹמֶר",
"הַיּוֹם תִּשְׁעָה וְאַרְבָּעִים יוֹם, שֶׁהֵם שִׁבְעָה שָׁבוּעוֹת לָעֽוֹמֶר",
]
-%}
{{- texts[states('sensor.effective_day_of_omer') | int(0) - 1] -}}
{%- endif -%}
- name: Omer Sefira
unique_id: omer_sefira
icon: mdi:numeric-7-box-multiple-outline
state: |
{%- set day = states('sensor.effective_day_of_omer') | int(0) -%}
{%- if day != '0' -%}
{%- set sefiros = [
"חסד", "גבורה", "תפארת", "נצח", "הוד", "יסוד", "מלכות",
] -%}
{{- sefiros[(day - 1) % 7] }} שב{{- sefiros[((day - 1) / 7) | int] -}}
{%- endif -%}
# True during the daytime, when you cannot make a ברכה.
# If this is true, add a Last Night prefix on displays.
binary_sensor:
- name: "Omer: Is Last Night"
state: |
{{
states('sensor.jewish_calendar_alot_hashachar') | as_datetime
<= now()
<= states('sensor.jewish_calendar_t_set_hakochavim') | as_datetime
}}
template:
- trigger:
# This sensor changes at midnight only.
# It renders candle lighting for each day of a
# multi-day יום טוב.
- trigger: time
at: 00:05:00
sensor:
# When to actually light candles. Ignores early שבת, but correctly
# shows צאת for the second day of יום טוב (except on Friday). Use
# this on dashboards. On the last day of יום טוב, uses yesterday's
# value, for reference (this includes a regular שבת day).
- name: "Today's Candle Lighting"
unique_id: today_s_candle_lighting
device_class: timestamp
icon: mdi:candle
state: |
{%- set initial_candle_lighting = states('sensor.jewish_calendar_upcoming_candle_lighting') | as_datetime | as_local -%}
{%- set havdalah = states('sensor.jewish_calendar_upcoming_havdalah') | as_datetime | as_local -%}
{%- if initial_candle_lighting > today_at() -%}
{# On Erev (even after candle lighting), show today's candle lighting. #}
{{ initial_candle_lighting }}
{%- elif havdalah.date() > today_at('0:00').date() -%}
{# If tomorrow is also יום טוב, use today's צאת הכוכבים. #}
{# On Fridays (even if today is יום טוב), use regular candle lighting. #}
{# The sensor for צאת is too early, so compute it by hand. #}
{{ states('sensor.jewish_calendar_shkia') | as_datetime | as_local
+ timedelta(minutes =
-18 if now().strftime('%A') == 'Friday'
else 50
) }}
{%- else -%}
{# On the last day, don't change (show yesterday's value). #}
{{ states('sensor.today_s_candle_lighting') }}
{%- endif -%}
- sensor:
# When we expect שבת to actually start, including early שבת.
# This replaces upcoming_candle_lighting for most purposes.
- name: "Actual Shabbos Start"
unique_id: "actual_shabbos_start"
device_class: timestamp
state: |
{%- set zman_time = as_datetime(states("sensor.jewish_calendar_shkia"))
- timedelta( minutes = 18 ) -%}
{%- if state_attr('sensor.jewish_calendar_holiday', 'id') == 'erev_shavuot' -%}
{%- set time = zman_time -%}
{%- elif is_state("input_boolean.shabbos_plag_shabbos", "on") -%}
{%- set time =
states("sensor.jewish_calendar_plag_hamincha") | as_datetime
- timedelta( minutes = 0 )
-%}
{%- else -%}
{# We always make early shabbos at 7:00 when applicable. #}
{%- set time = [today_at("19:00"), zman_time] | min -%}
{%- endif -%}
{{ time | as_local }}
# When we want Shabbos Mode to start automatically. This is 25 minutes
# before the actual start time, as a heads up.
- name: "Shabbos Mode Start"
unique_id: "shabbos_mode_start"
device_class: timestamp
state: |
{{ states("sensor.actual_shabbos_start") | as_datetime('9999-12-31' | as_datetime) | as_local
- timedelta( minutes = 25 ) }}
# This powers a reminder notification and a dashboard display.
- name: Shabbos Chicken Alert
unique_id: shabbos_chicken_alert
device_class: timestamp
icon: mdi:food-drumstick-outline
state: |
{{ states("sensor.actual_shabbos_start") | as_datetime('9999-12-31' | as_datetime) | as_local
- timedelta( minutes = 90 ) }}
# Today's date, but changes at candle lighting, not at midnight.
# Use this for Jewish-date-based logic, mostly in this file.
# Warning: Returns Sunday before הבדלה.
- name: Candles-based Date
device_class: date
state: |
{{
now().date()
+ timedelta(
days = now() > (
states('sensor.jewish_calendar_shkia') | as_datetime
- timedelta(minutes = 18)
)
) }}
- binary_sensor:
- name: Is Rosh Chodesh
icon: mdi:moon-waxing-crescent
state: |
{{ state_attr('sensor.jewish_calendar_date', 'hebrew_day') in ['1', '30'] }}
# True on שבת, when we should actually eat the ערוב תבשילין.
# Use for dashboard reminders.
- name: Eat Eruv Tavshilin
icon: mdi:bread-slice
state: |
{# Guaranteed to be in the past on שבת. #}
{# On מוצאי שבת, this will be in the future; return false. #}
{%- set yom_tov_start = states('sensor.jewish_calendar_upcoming_candle_lighting') | as_datetime | as_local -%}
{{
now().strftime('%A') == 'Saturday'
and yom_tov_start.strftime('%A') != 'Friday'
and yom_tov_start <= now()
}}
# True if שבת might not have started yet.
# False after sunset, or if the user explicitly turned on שבת mode when lighting candles.
# Use to hide interactive dashboard cards.
- name: Not yet fully Shabbos
unique_id: not_yet_fully_shabbos
icon: mdi:power-plug-outline
state: |
{{
(states('sensor.jewish_calendar_upcoming_candle_lighting')
| as_datetime | as_local).date()
== today_at('0:00').date()
and is_state('sun.sun', 'above_horizon')
and is_state('input_boolean.extend_shabbos_mode', 'off')
}}
# True if it's late enough to start שבת, but שבת has not definitely started yet.
# Use to show a dashboard button to start שבת.
- name: Shabbos can start
unique_id: Shabbos can start
icon: mdi:candelabra
state: |
{{
is_state('binary_sensor.not_yet_fully_shabbos', 'on')
and now() >= states('sensor.jewish_calendar_plag_hamincha') | as_datetime
}}
# True between the prior מוצאי שבת and מוצאי יום טוב.
# Use as a condition for things that are only apply for יום טוב.
# This can be used both before and during יום טוב. Beware: This
# will also be true on שבת as part of a 3-day יום טוב, even when
# it isn't actually יום טוב. This is generally a feature.
- name: Is Yom Tov Coming
unique_id: Is Yom Tov Coming
icon: mdi:calendar-star
state: |
{#
- Check for שבת יום כיפור
- Check whether יום טוב starts before שבת
- Check whether יום טוב ends after שבת
#}
{{
is_state('sensor.jewish_calendar_parshat_hashavua', '')
or states('sensor.jewish_calendar_upcoming_candle_lighting')
!= states('sensor.jewish_calendar_upcoming_shabbat_candle_lighting')
or states('sensor.jewish_calendar_upcoming_havdalah')
!= states('sensor.jewish_calendar_upcoming_shabbat_havdalah')
}}
# True on יום טוב, or on שבת immediately adjacent to יום טוב.
# This is like the above sensor, but turns on when שבת starts.
- name: "Is Yom Tov Adjacent"
unique_id: "Is_yom_tov_adjacent"
icon: "mdi:candelabra-fire"
state: >
{{
is_state('binary_sensor.shabbos_mode', 'on')
and is_state('binary_sensor.is_yom_tov_coming', 'on')
}}
# True on the second day of a multi-day יום טוב or שבת.
# Becomes true at the candle lighting for the 2nd night.
- name: Is Second Day of Issur Melacha
unique_id: is_second_day_of_issur_melacha
icon: mdi:numeric-2-box-multiple-outline
state: >
{#
Returns Saturday after candle lighting.
Warning: Returns Sunday before הבדלה.
#}
{%- set candles_based_date = as_datetime(states('sensor.candles_based_date')).date() -%}
{%- set initial_candle_lighting = states('sensor.jewish_calendar_upcoming_candle_lighting') | as_datetime | as_local -%}
{%- set havdalah = states('sensor.jewish_calendar_upcoming_havdalah') | as_datetime | as_local -%}
{#
- If it's still יום טוב
- And candle lighting is >1 day ago by date
- And it's actually multi-day.
#}
{{
is_state('binary_sensor.jewish_calendar_issur_melacha_in_effect', 'on')
and initial_candle_lighting.date() < candles_based_date - timedelta(days = 1)
and (havdalah.date() > initial_candle_lighting.date() + timedelta(days = 1))
}}
# The fully resolved value for whether we expect it to be שבת
# or יום טוב. Use this instead of Issur Melacha in Effect for
# most purposes. This includes early שבת and late הבדלה. This
# turns on based on the Actual Shabbos Start time sensor above
# and the explicit `Extend Shabbos Mode` input boolean. Please
# turn that off via automation on מוצאי שבת, in case the user
# forgets.
- name: "Shabbos Mode"
unique_id: "shabbos_mode"
icon: >
{% if is_state("binary_sensor.shabbos_mode", "on") %}
mdi:candelabra-fire
{% else %}
mdi:candelabra
{% endif %}
state: >
{#
Check candle lighting, so we don't flash off when
jewish_calendar_erev_shabbat_hag turns off before
jewish_calendar_issur_melacha_in_effect turns on.
Also check that it's after midnight, so we do not
turn on if jewish_calendar_erev_shabbat_hag turns
on before shabbos_mode_start updates to today.
#}
{{
is_state("binary_sensor.jewish_calendar_issur_melacha_in_effect", "on")
or now() >= as_datetime(states('sensor.jewish_calendar_upcoming_candle_lighting'))
or is_state("input_boolean.extend_shabbos_mode", "on")
or (is_state("binary_sensor.jewish_calendar_erev_shabbat_hag", "on")
and today_at("0:00") <= as_datetime(states("sensor.shabbos_mode_start")) <= now())
}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment