Hello,
Apologies for opening yet another thread for what appears to be a so simple topic - but it’s driving me nuts .
I have two sensors like this. Placing the definition into configuration.yaml works as desired:
template:
- sensor:
- name: "Schicht heute"
unique_id: schicht_heute
icon: mdi:calendar-today
state: >
{% set start = strptime('2026-02-09', '%Y-%m-%d') %}
{% set today = now().replace(hour=0, minute=0, second=0, microsecond=0) %}
{% set delta_days = ((as_timestamp(today) - as_timestamp(start)) / 86400) | int %}
{% set idx = ((delta_days % 42) + 42) % 42 %}
{% set shifts = [
"Tag","Tag","Tag","Tag","Tag",
"Frei","Frei",
"Früh","Früh",
"Spät","Spät",
"Nacht","Nacht","Nacht",
"Frei","Frei","Frei","Frei",
"Früh","Früh","Früh",
"Spät","Spät",
"Nacht","Nacht",
"Frei","Frei","Frei","Frei","Frei",
"Früh","Früh",
"Spät","Spät","Spät",
"Nacht","Nacht",
"Frei","Frei","Frei","Frei","Frei"
] %}
{{ shifts[idx] }}
So I wanted to move this and other stuff into a separate file schicht.yaml. The reference in configuration.yaml is
template: !include_dir_merge_named templates/
The content of the file is like the template definition, except for “template”. But now the sensor gets status “unavailable”.
sensor:
- name: "Schicht heute"
entity_id: schicht_heute
icon: mdi:calendar-today
state: >
{% set start = strptime('2026-02-09', '%Y-%m-%d') %}
{% set today = now().replace(hour=0, minute=0, second=0, microsecond=0) %}
{% set delta_days = ((as_timestamp(today) - as_timestamp(start)) / 86400) | int %}
{% set idx = ((delta_days % 42) + 42) % 42 %}
{% set shifts = [
"Tag","Tag","Tag","Tag","Tag",
"Frei","Frei",
"Früh","Früh",
"Spät","Spät",
"Nacht","Nacht","Nacht",
"Frei","Frei","Frei","Frei",
"Früh","Früh","Früh",
"Spät","Spät",
"Nacht","Nacht",
"Frei","Frei","Frei","Frei","Frei",
"Früh","Früh",
"Spät","Spät","Spät",
"Nacht","Nacht",
"Frei","Frei","Frei","Frei","Frei"
] %}
{{ shifts[idx] }}
WTH am I doing wrong?