Skip to content

Date Range Duration

Scott Gusler edited this page Feb 13, 2026 · 2 revisions

Date Range Duration

Measures the duration between two datetime entities.

Overview

A date range duration sensor calculates the difference between two datetimes and displays it in hours.

Configuration

  1. Select "Date Range Duration"
  2. Configure:
    • Calculation Name: A friendly name
    • Start Datetime Entity: Start of the range
    • End Datetime Entity: End of the range
    • Icon: Optional custom icon

Add Date Range Duration

Examples

1. Event Duration

{
  "type": "date_range",
  "name": "Meeting Duration Hours",
  "start_datetime_entity": "input_datetime.meeting_start",
  "end_datetime_entity": "input_datetime.meeting_end"
}

Result: Hours between meeting start and end

2. Time to Next Solar Peak

Calculate hours until the next estimated solar production peak:

{
  "type": "date_range",
  "name": "Hours to Solar Peak",
  "start_datetime_entity": "sensor.current_time",
  "end_datetime_entity": "sensor.estimated_solar_peak_time"
}

This shows how many hours until your solar panels will produce maximum power, helping you time energy-intensive activities.

Add Date Range Duration Time To Next Peak Example

Automation Example

automation:
  - alias: "Alert if event too long"
    trigger:
      platform: numeric_state
      entity_id: sensor.meeting_duration_hours
      above: 3
    action:
      service: notify.mobile_app
      data:
        message: "Meeting is running long!"

Templates

Format the duration nicely:

{% set hours = states('sensor.shift_hours') | int(0) %}
{% set minutes = ((states('sensor.shift_hours') | float(0) - hours) * 60) | int %}
Shift: {{ hours }}h {{ minutes }}m

Clone this wiki locally