vd Brink Home Automations

Home automations: Home Assistant, ESPHome, Node-RED and more.

Follow me on GitHub

Home Assistant dashboard: Date & Time

Home Assistant logo

Here you find Home Assistant (lovelace) dashboard examples related to date and time which you can easily add to your own dashboards.



Table of Contents


Time and date

Hugh time notation and a full date notation.

time_date.png


# Sourcecode by vdbrink.github.io
# configuration.yaml
type: vertical-stack
cards:
  - type: custom:mushroom-title-card
    title: '{{now().strftime(''%H:%M'')}}'
    alignment: center
    card_mod:
      style: |
        ha-card {
          --title-font-size: 90px !important;
        }
  - type: custom:mushroom-title-card
    title: '{{states.sensor.date_only_formatted.state}}'
    alignment: center
    card_mod:
      style: |
        ha-card {
          --title-font-size: 30px !important;
        }


Inline time and date (Dutch format)

Current date and time


# Sourcecode by vdbrink.github.io
# configuration.yaml
- platform: template
  sensors:
    time_formatted:
      friendly_name: "Datum en tijd"
      value_template: >-
        {% set days = ["maandag", "dinsdag", "woensdag", "donderdag", "vrijdag", "zaterdag", "zondag"] %}
        {% set day = days[now().weekday()] %}
        {% set day_short = day[0:2] %}
        {% set months = ["januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december"] %}
        {% set month = months[now().month - 1] %}
        {{ now().strftime('%H:%M') + ', ' + day_short + ' ' + now().strftime('%d') + ' ' + month + ' ' + now().strftime('%Y') }}
      icon_template: mdi:calendar-clock


# Sourcecode by vdbrink.github.io
# Dashboard card code
- type: entity
  entity: sensor.time_formatted
  name: ' '


Current day of the week (Dutch format)

Day of the week

# Sourcecode by vdbrink.github.io
# configuration.yaml
- platform: template
  sensors:
    day_of_the_week_full:
      friendly_name: "Dag van de week"
      value_template: >-
        {% set days = ["maandag", "dinsdag", "woensdag", "donderdag", "vrijdag", "zaterdag", "zondag"] %}
        {% set day = days[now().weekday()] %}
        {{ day }}


# Sourcecode by vdbrink.github.io
# Dashboard card code
- type: entity
  entity: sensor.time_formatted
  name: ' '


Days count down

Days countdown

Twente Milieu: format YYYY-MM-DD

Countdown for the number of days until they pick up the paper waste. The Twente Milieu integration creates the sensor paper_waste_pickup in the format YYYY-MM-DD

With this template it gives the amount of days from now.


# Sourcecode by vdbrink.github.io
# configuration.yaml
- platform: template      
  sensors:
    paper_waste_pickup_countdown:
      friendly_name: "papier ophalen"
      value_template: >-
         {% set now_timestamp = as_timestamp(strptime(states("sensor.date"), "%Y-%m-%d")) %}
         {% set paper_timestamp = as_timestamp(strptime(states("sensor.paper_waste_pickup"), "%Y-%m-%d")) %}
         {% set days = ((paper_timestamp - now_timestamp) / (24 * 60 * 60)) | round(0, 'ceil')  %}
         {{ days }}
      icon_template: mdi:delete-empty
      unit_of_measurement: "dagen"  

HACS: Afvalbeheer: attribute and format YYYYMMDD

Countdown for the number of days until they pick up the paper waste. The HACS: Afvalbeheer integration creates the sensor wastecollector_papier the default value can be Morgen, 05-02-2024 or 06-02-2024. But the attributes field Sort_date has a default YYYYMMDD that’s why I use this value

With this template it gives the amount of days from now.


# Sourcecode by vdbrink.github.io
# configuration.yaml
- platform: template      
  sensors:
    paper_waste_pickup_countdown:
      friendly_name: "papier ophalen"
      value_template: >-
        {% set datex = state_attr('sensor.wastecollector_papier','Sort_date') | string %}
        {{ ((as_timestamp(strptime(datex, '%Y%m%d')) - as_timestamp(now())) / (60 * 60 * 24)) | round(0, 'ceil')  }}
      icon_template: mdi:delete-empty
      unit_of_measurement: "dagen"  

Show only on the last 4 days

To show only the message when it’s less than 4 days before the pick-up I used the HACS: auto-entities custom element. Install it via this button Open your Home Assistant instance and show the add-on store.


# Sourcecode by vdbrink.github.io
# Dashboard card code
- type: custom:auto-entities
  card:
    type: entities
  filter:
    include:
      - entity_id: sensor.paper_waste_pickup_countdown
        state 1: "< 4"
        state 2: "> -1"
  show_empty: false


How long an entity is active in human-readable text

How long the washing machine is running Running more than one hour

Show in human-readable text how long an entity, like a washing machine, is active.

I used a custom HACS module mushroom. Install it via this button Open your Home Assistant instance and show the add-on store.


# Sourcecode by vdbrink.github.io
# Dashboard card code
- type: custom:mushroom-title-card
  title: |-
  {{ 'De wasmachine is ' }}
  {%- set entity_id = 'binary_sensor.wasmachine' -%}
  {%- if is_state(entity_id, 'on') -%}
  
      {%- set runningsince = (now()) - ((states[entity_id].last_changed)) -%}
      {%- set runningsinceseconds = runningsince.total_seconds()|round -%}
      {%- set runningsincedays = (runningsinceseconds / 86400)|int|string -%}
      {%- set runningsincedaystext = 'dagen' -%}
      {%- if runningsincedays|int == 1 -%}
        {%- set runningsincedaystext = 'dag' -%}
      {%- endif -%}
  
      {%- set runningsincehours = (runningsinceseconds % 86400 / 3600)|int|string -%}
      {%- set runningsincehourstext = 'uren' -%}
      {%- if runningsincehours|int == 1 -%}
        {%- set runningsincehourstext = 'uur' -%}
      {%- endif -%} 
      
      {%- set runningsinceminutes = (runningsinceseconds % 3600 / 60)|int|string -%} 
      {%- set runningsinceminutestext = 'minuten' -%}
      {%- if runningsinceminutes|int == 1 -%} 
        {%- set runningsinceminutestext = 'minuut' -%}
      {%- endif -%} 
  
      {%- if runningsincedays|int > 0 -%} 
      # Running more then 1 day
        {{ runningsincedays + ' ' + runningsincedaystext + ', ' + runningsincehours + ' ' + runningsincehourstext + ' en ' + runningsinceminutes + ' ' + runningsinceminutestext }} 
      {%- elif runningsincehours|int > 0 -%}
      # Running more then 1 hour
        {{ runningsincehours + ' ' + runningsincehourstext + ' en ' + runningsinceminutes + ' ' + runningsinceminutestext }} 
      {%- else -%}
      # Running for minutes
        {{ runningsinceminutes + ' ' + runningsinceminutestext }}
      {%- endif -%}
      {%- if is_state(entity_id, 'on') -%} 
        {{ ' bezig'}} 
      {%- endif -%}
  {%- else -%}
  # State is off
    {{ ' uit' }}
  {%- endif -%}


Hours count up

Hours count upn

Count the hours since the last changed state. In this case when a drawer with medicines was opened for the last time.

The value 11.3 will round to 11 and also 11.6 will round to 11 hours.


# Sourcecode by vdbrink.github.io
# configuration.yaml
- platform: template
  sensors:
    drawer_opened_hours_ago:
      friendly_name: "la geopend"
      value_template: >-
        {% set now_timestamp = as_timestamp(now()) %}
        {% set drawer_timestamp = as_timestamp(states.binary_sensor.drawer_contact.last_changed) %}
        {% set hours = ((now_timestamp - drawer_timestamp) / (60 * 60)) | round(0, 'ceil')  %}
        {{ hours }}
      unit_of_measurement: "uren"


Last changed indication as secondary info

Last changed indication as secondary info

The value on the right is the actual sensor value.


# Sourcecode by vdbrink.github.io
# Dashboard card code
- type: entities
  entities:
    - entity: binary_sensor.contact1_contact
      secondary_info: last-changed


Last changed indication

A custom sensor that shows the time since the last change.
Also useful to show on a floor map.


# Sourcecode by vdbrink.github.io
# Dashboard card code
mailbox_timer:
  friendly_name: mailbox
  icon_template: mdi:clock-outline
  value_template: >
    {{ relative_time(states.binary_sensor.mailbox_contact.last_changed) }}


Triggered today

Test if the robot vacuum already runs today.


# Sourcecode by vdbrink.github.io
# configuration.yaml
binary_sensor:
  - platform: template
    sensors:
       vaccuum_run_today:
            friendly_name: "runned today"
            value_template: "{{ as_local(as_datetime(states("sensor.vacuum_last_clean_start"))).date() == now().date() }}"


^^ Top

<< See also my other Home Assistant tips and tricks


Top | Homepage | Best Buy Tips