Skip to content

Instantly share code, notes, and snippets.

@vladyspavlov
Created November 25, 2023 15:13
Show Gist options
  • Save vladyspavlov/b64dff4a91a918be022b8965852bcb56 to your computer and use it in GitHub Desktop.
Save vladyspavlov/b64dff4a91a918be022b8965852bcb56 to your computer and use it in GitHub Desktop.
Home Assistant. Example of dividing time between entity last changes and converting to human readable
{% set td = trigger.to_state.last_changed - trigger.from_state.last_changed %}
{% set ts = td.total_seconds() | int %}
{% set hours, remainder = (ts // 3600, ts % 3600) %}
{% set minutes, seconds = (remainder // 60, remainder % 60) %}
Days: {{ td.days }}, hours: {{ hours }}, minutes: {{ minutes }}, seconds: {{ seconds }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment