Skip to content

Home Assistant Lovelace Custom Card to calculate time elapsed/left

License

Notifications You must be signed in to change notification settings

Kirbo/ha-lovelace-elapsed-time-card

Repository files navigation

Time Elapsed Card by @kirbo

Time Elapsed card

GitHub Release License hacs_badge

Project Maintenance GitHub Activity

Discord Community Forum

Support

Hey dude! Help me out for a couple of 🍻 or a ☕!

coffee

Options

Name Type Requirement Description Default
type string Required custom:elapsed-time-card
time_today string Required Home Assistant entity ID. none
max_today string Optional Home Assistant entity ID. none
format string Required Format for the card Time Left
time_format string Required Card name 1h 5m
name string Optional Name to show on card none
icon string Optional Icon to show on card none

Format Options

Time Elapsed

Show time in <time elapsed> / <time maximum> format, e.g.: 01:54 / 02:00 or 1h 54m / 2h, depending on time_format setting.

Time Left

Show time in <time remaining> format, e.g.: 00:06 or 6m, depending on time_format setting.

Examples

Card examples

Cartoons Watched

type: 'custom:elapsed-time-card'
format: Time Elapsed
time_format: 1h 5m
time_today: sensor.ps4_playing_game
max_today: input_datetime.ps4_game_time
name: Cartoons watched
icon: netflix

Game time left

type: 'custom:elapsed-time-card'
format: Time Left
time_format: 1h 5m
time_today: sensor.ps4_playing_game
max_today: input_datetime.ps4_game_time
name: Game time left
icon: sony-playstation

Editor examples

Game time left - Editor 1 Game time left - Editor 2

Panel example

Time Cards and history example

type: horizontal-stack
cards:
  - type: vertical-stack
    title: Today elapsed
    cards:
      - format: Time Elapsed
        time_format: 1h 5m
        type: 'custom:elapsed-time-card'
        name: Played total
        icon: gamepad-variant
        time_today: sensor.ps4_playing_game
      - format: Time Elapsed
        time_format: 1h 5m
        type: 'custom:elapsed-time-card'
        name: Watched total
        icon: youtube
        time_today: sensor.ps4_playing_app
      - format: Time Elapsed
        time_format: 1h 5m
        type: 'custom:elapsed-time-card'
        name: Screentime total
        icon: monitor-eye
        time_today: sensor.ps4_playing
  - type: vertical-stack
    title: Today left
    cards:
      - format: Time Left
        time_format: 1h 5m
        type: 'custom:elapsed-time-card'
        name: Game time left
        icon: gamepad-variant
        time_today: sensor.ps4_playing_game
        max_today: input_datetime.ps4_game_time
      - format: Time Left
        time_format: 1h 5m
        type: 'custom:elapsed-time-card'
        name: Videos left
        icon: youtube
        time_today: sensor.ps4_playing_app
        max_today: input_datetime.ps4_vod_time
      - format: Time Left
        time_format: 1h 5m
        type: 'custom:elapsed-time-card'
        name: Screentime left
        icon: monitor-eye
        time_today: sensor.ps4_playing
        max_today: sensor.ps4_playing
  - type: vertical-stack
    title: Today total
    cards:
      - format: Time Elapsed
        time_format: '01:05'
        type: 'custom:elapsed-time-card'
        name: Played total
        icon: gamepad-variant
        max_today: input_datetime.ps4_game_time
        time_today: sensor.ps4_playing_game
      - format: Time Elapsed
        time_format: '01:05'
        type: 'custom:elapsed-time-card'
        name: Watched total
        icon: youtube
        time_today: sensor.ps4_playing_app
        max_today: input_datetime.ps4_vod_time
      - format: Time Elapsed
        time_format: '01:05'
        type: 'custom:elapsed-time-card'
        name: Screentime total
        icon: monitor-eye
        time_today: sensor.ps4_playing
  - type: vertical-stack
    title: This week elapsed
    cards:
      - format: Time Elapsed
        time_format: 1h 5m
        type: 'custom:elapsed-time-card'
        name: Played total
        icon: gamepad-variant
        time_today: sensor.ps4_weekly_game
      - format: Time Elapsed
        time_format: 1h 5m
        type: 'custom:elapsed-time-card'
        name: Watched total
        icon: youtube
        time_today: sensor.ps4_weekly_app
      - format: Time Elapsed
        time_format: 1h 5m
        type: 'custom:elapsed-time-card'
        name: Screentime total
        icon: monitor-eye
        time_today: sensor.ps4_weekly_playing
  - type: vertical-stack
    title: This week elapsed
    cards:
      - format: Time Elapsed
        time_format: '01:05'
        type: 'custom:elapsed-time-card'
        name: Played total
        icon: gamepad-variant
        time_today: sensor.ps4_weekly_game
      - format: Time Elapsed
        time_format: '01:05'
        type: 'custom:elapsed-time-card'
        name: Watched total
        icon: youtube
        time_today: sensor.ps4_weekly_app
      - format: Time Elapsed
        time_format: '01:05'
        type: 'custom:elapsed-time-card'
        name: Screentime total
        icon: monitor-eye
        time_today: sensor.ps4_weekly_playing

Example sensors

PS4 restrictions and stuff

sensors

- platform: template
  sensors:
    ps4_media_content_type:
      friendly_name: "PS4 - Media content type"
      value_template: "{{ state_attr('media_player.ps4', 'media_content_type') }}"
      
- platform: history_stats
  name: PS4 Playing (game)
  entity_id: sensor.ps4_media_content_type
  state: "game"
  type: time
  start: "{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}"
  end: "{{ now() }}"

- platform: history_stats
  name: PS4 Playing (app)
  entity_id: sensor.ps4_media_content_type
  state: "app"
  type: time
  start: "{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}"
  end: "{{ now() }}"

input_datetime

ps4_game_time:
  name: PS4 - Game time
  icon: mdi:sony-playstation
  has_date: false
  has_time: true

ps4_app_time:
  name: PS4 - APP time
  icon: mdi:netflix
  has_date: false
  has_time: true

With the entities above, you can use this configuration:

format: Time Elapsed
time_format: '01:05'
type: 'custom:elapsed-time-card'
name: Played total
icon: gamepad-variant
max_today: input_datetime.ps4_game_time
time_today: sensor.ps4_playing_game

And it will look like: Cartoons Watched

Notice

The card will show only entities that:

  • have unit_of_measurement one of the following (i.e. input_number, etc.):
    • s = seconds
    • m = minutes
    • h = hours
    • d = days
  • have one of the following attributes (i.e. input_datetime):
    • has_time
    • has_date

My stats

Kirbo's GitHub stats

Top Langs

About

Home Assistant Lovelace Custom Card to calculate time elapsed/left

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published