Closed sfgabe closed 3 years ago
hey hey,
yes you are touching a concept I have in mind for some time now: column data types
it is quite a longer story and is also targeting this use case, for now I would suggest using modify
to get something like "3hours" I currently use something like this:
type: 'custom:flex-table-card'
max_rows: 10
sort_by: receivedTS-
clickable: true
title: Time Since Last Received Msg
columns:
- align: center
attr: node_id
icon: 'mdi:z-wave'
name: NodeID
- name: Name
prop: name
- align: right
attr: receivedTS
modify: Math.round((Date.now() - Date.parse(x)) / 36000.) / 100.
name: Recv. Age
suffix: ' h'
entities:
exclude:
- zwave.unknown_device_*
- zstick_gen5
- _tot
include: zwave.*
using this modify
you will get hours, Date.parse(x)
can be used for many similar approaches. Hope this solves your issue for now, once column data types are available this should be possible in a more generic fashion.
Sweet, I didn't realize modify could deal with something complicated.
Here's what I ended up with:
modify: >-
const hourDiff = (Date.now() - Date.parse(x));
const secDiff = hourDiff / 1000;
const minDiff = hourDiff / 60 / 1000;
const hDiff = hourDiff / 3600 / 1000;
const hours = Math.floor(hDiff);
const minutes = minDiff - 60 * hours;
const minr = Math.floor(minutes);
hours + " hours " + minr + " minutes"
suffix: ' ago'
Thanks for this card, one feature request: Can you add in some jinja timestamp magic to prettify the "last_changed" property (something like "April 26, 2020, 11:15" or "3 hours, 56 minutes ago")?