-
Notifications
You must be signed in to change notification settings - Fork 15
input_datetime in lovelace
input_datetime
is an entity that allows to save a date and/or time information.
Very usefull in term of automation if you want to follow for example the date
of last maintenance of your car, chimney or boiler.
The drawback is the current implementation in lovelace.
Lovelace allows an easy way to update the date or time, but the readability is really bad.
I've made some investigations to find my options. I didn't find any solution with native features in Lovelace or Home Assistant core.
One way could be to use the template sensor to get the timestamp
attibute of
the input_datetime to have a readable date/time information. I was not very
found of this because you have to create a new entity in the back-end to
workaround a front end issue.
I've investigated what could be done on Lovelace side. My solution is based on the plug-in lovelace-template-entity-row by @thomasloven. It allows to display whatever you want in an entities card row using Jinja syntax.
I use the templating language to create a sort of fake entity showing me if I should do something compare to the age of the date.
entities:
- entity: input_datetime.last_maintenance_date_tank
name: Entretien fosse sceptique
secondary: >-
{{
relative_time(strptime(state_attr('input_datetime.last_maintenance_date_tank','timestamp')
| timestamp_custom('%Y-%m-%d %H:%M:%S %z'), '%Y-%m-%d %H:%M:%S %z')) }}
ago
state: >-
{% if as_timestamp(strptime(states('sensor.date'), '%Y-%m-%d')) -
state_attr('input_datetime.last_maintenance_date_tank','timestamp') >
86400 * 365 * 3 %}A prévoir{% else %}OK{% endif %}
type: 'custom:template-entity-row'
By adding the entity
parameter, I can modify the date just by clicking the fake
entity. It open the more-info window of the orginal input_datetime
entity.
In bonus I have a readable and human understanding age of my date in the secondary information. The template code is complicated but it's the only way to make it works.