Skip to content

Template Sensors

Fischer, Fabian edited this page Apr 28, 2026 · 1 revision

Template Sensors

Custom template sensors that extend the integration's capabilities.

Daylight Duration

Calculate how many hours of daylight today:

template:
  - sensor:
      - name: "Daylight duration"
        unit_of_measurement: "h"
        icon: mdi:weather-sunny
        state: >
          {% set rise = states('sensor.kachelmannwetter_sunrise') %}
          {% set sett = states('sensor.kachelmannwetter_sunset') %}
          {% if rise and sett and rise != 'unknown' and sett != 'unknown' %}
            {{ ((as_timestamp(sett) - as_timestamp(rise)) / 3600) | round(1) }}
          {% else %}
            unknown
          {% endif %}

Moon Phase Name

Convert the numeric moon phase (0–100) to a human-readable name:

template:
  - sensor:
      - name: "Moon phase name"
        icon: mdi:moon-waning-gibbous
        state: >
          {% set phase = states('sensor.kachelmannwetter_moon_phase') | int(0) %}
          {% if phase <= 5 %}Neumond
          {% elif phase <= 15 %}Zunehmende Sichel
          {% elif phase <= 25 %}Erstes Viertel
          {% elif phase <= 35 %}Zunehmender Mond
          {% elif phase <= 55 %}Vollmond
          {% elif phase <= 65 %}Abnehmender Mond
          {% elif phase <= 75 %}Letztes Viertel
          {% elif phase <= 85 %}Abnehmende Sichel
          {% else %}Neumond{% endif %}

Weather Summary for TTS

A single sentence summarizing current weather — great for voice assistants:

template:
  - sensor:
      - name: "Weather summary"
        state: >
          {{ states('weather.kachelmannwetter') | replace('partlycloudy', 'partly cloudy') | replace('clear-night', 'clear') }},
          {{ state_attr('weather.kachelmannwetter', 'temperature') }}°C.
          {% if is_state('binary_sensor.kachelmannwetter_rain_expected_3h', 'on') %}Rain expected within 3 hours.{% endif %}
          {% if is_state('binary_sensor.kachelmannwetter_frost_expected_tonight', 'on') %}Frost warning tonight.{% endif %}
          {% if is_state('binary_sensor.kachelmannwetter_thunderstorm_expected', 'on') %}Thunderstorm expected!{% endif %}

UV Index Estimate from Global Radiation

Rough UV index estimate based on global radiation (not a medical-grade calculation):

template:
  - sensor:
      - name: "UV index estimate"
        unit_of_measurement: "UV"
        icon: mdi:sun-wireless
        state: >
          {% set rad = states('sensor.kachelmannwetter_global_radiation_current') | float(0) %}
          {{ (rad / 25) | round(0) }}
        attributes:
          level: >
            {% set uv = (states('sensor.kachelmannwetter_global_radiation_current') | float(0) / 25) | round(0) %}
            {% if uv <= 2 %}Low
            {% elif uv <= 5 %}Moderate
            {% elif uv <= 7 %}High
            {% elif uv <= 10 %}Very High
            {% else %}Extreme{% endif %}

Solar Yield Potential

Estimate daily solar yield potential for your PV system:

template:
  - sensor:
      - name: "PV yield estimate"
        unit_of_measurement: "kWh"
        icon: mdi:solar-power
        device_class: energy
        state: >
          {# Adjust these values to your system #}
          {% set panel_area_m2 = 30 %}
          {% set efficiency = 0.20 %}
          {% set system_losses = 0.85 %}
          {% set radiation = states('sensor.kachelmannwetter_global_radiation_today') | float(0) %}
          {{ ((radiation * panel_area_m2 * efficiency * system_losses) / 1000) | round(1) }}

Feels Like Temperature (Wind Chill / Heat Index)

template:
  - sensor:
      - name: "Feels like temperature"
        unit_of_measurement: "°C"
        device_class: temperature
        icon: mdi:thermometer-lines
        state: >
          {% set temp = state_attr('weather.kachelmannwetter', 'temperature') | float(0) %}
          {% set wind = state_attr('weather.kachelmannwetter', 'wind_speed') | float(0) %}
          {% set humidity = state_attr('weather.kachelmannwetter', 'humidity') | float(50) %}
          {% if temp <= 10 and wind > 5 %}
            {# Wind chill (simplified Siple formula) #}
            {{ (13.12 + 0.6215 * temp - 11.37 * (wind ** 0.16) + 0.3965 * temp * (wind ** 0.16)) | round(1) }}
          {% elif temp >= 27 and humidity > 40 %}
            {# Heat index (simplified) #}
            {{ (temp + 0.33 * (humidity / 100 * 6.105 * (17.27 * temp / (237.7 + temp)) | float) - 4.0) | round(1) }}
          {% else %}
            {{ temp }}
          {% endif %}

Tomorrow's Weather Preview

template:
  - sensor:
      - name: "Tomorrow weather preview"
        icon: mdi:calendar-tomorrow
        state: >
          {% set forecast = state_attr('weather.kachelmannwetter', 'forecast') %}
          {% if forecast and forecast | length > 1 %}
            {% set tomorrow = forecast[1] %}
            {{ tomorrow.condition | replace('partlycloudy', 'teilweise bewölkt') | replace('sunny', 'sonnig') | replace('cloudy', 'bewölkt') | replace('rainy', 'Regen') }},
            {{ tomorrow.native_temperature }}°C / {{ tomorrow.native_templow }}°C
          {% else %}
            unavailable
          {% endif %}

14-Day Trend Access

Access any day from the 14-day trend sensor:

template:
  - sensor:
      - name: "Weather in 3 days"
        icon: mdi:calendar-clock
        state: >
          {% set days = state_attr('sensor.kachelmannwetter_trend_14day', 'days') %}
          {% if days and days | length > 3 %}
            {% set day = days[3] %}
            {{ day.temp_max }}°C, Regen: {{ day.precipitation_probability_1mm }}%
          {% else %}
            unavailable
          {% endif %}
        attributes:
          temp_max: "{{ state_attr('sensor.kachelmannwetter_trend_14day', 'days')[3].temp_max | default('unknown') }}"
          temp_min: "{{ state_attr('sensor.kachelmannwetter_trend_14day', 'days')[3].temp_min | default('unknown') }}"
          rain_prob: "{{ state_attr('sensor.kachelmannwetter_trend_14day', 'days')[3].precipitation_probability_1mm | default('unknown') }}"
          condition: "{{ state_attr('sensor.kachelmannwetter_trend_14day', 'days')[3].condition | default('unknown') }}"

Clone this wiki locally