Skip to content

Date Range Duration

Scott Gusler edited this page Feb 11, 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

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. Work Shift Duration

{
  "type": "date_range",
  "name": "Shift Hours",
  "start_datetime_entity": "input_datetime.shift_start",
  "end_datetime_entity": "input_datetime.shift_end"
}

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